theodo-fintech / spring-search

Provides advanced search capabilities to a JPA entity
MIT License
193 stars 44 forks source link

New data type strategy #38

Closed hr-ireh closed 3 years ago

hr-ireh commented 3 years ago

java.time.Duration java.time.LocalDate java.time.LocalTime java.time.LocalDateTime

luc-boussant commented 3 years ago

Hey @hr-ireh, thanks for this MR :) I am going to have to provision more time to read all your MRs !! Thank you so much for contributing to the project !

I have time this Friday to read it. I will keep you updated when i have read it.

hr-ireh commented 3 years ago

Hey @hr-ireh, thanks for this MR :) I am going to have to provision more time to read all your MRs !! Thank you so much for contributing to the project !

I have time this Friday to read it. I will keep you updated when i have read it.

Hi @luc-boussant , I tried to follow all the principles and write complete tests :) Thank you for the review.

luc-boussant commented 3 years ago

The MR was really good on my end !!! Thank you so much for adding all these strategies. I saw that we had a lot of boilerplate for each strategy and for each tests. I think we should try next time we add strategies to work on refactoring those two things. What do you think ?

hr-ireh commented 3 years ago

The MR was really good on my end !!! Thank you so much for adding all these strategies. I saw that we had a lot of boilerplate for each strategy and for each tests. I think we should try next time we add strategies to work on refactoring those two things. What do you think ?

Hi @luc-boussant Agree, I suggest using @CsvFileSource for testing. For example:

    @ParameterizedTest
    @CsvFileSource(resources = ["/search.csv"], numLinesToSkip = 1)
    fun test(users: String, search: String, assertA: Int, assertB: String) {
        val mapper = ObjectMapper().registerModule(JavaTimeModule())
        val typeRef = object : TypeReference<List<Users>>() {}
        val userList = mapper.readValue(users, typeRef)

        userList.forEach() {
            userRepository.save(it)
        }

        val specification = SpecificationsBuilder<Users>(SearchSpec::class.constructors.first().call("", false)).withSearch(search).build()
        val usersFind = userRepository.findAll(specification)
        Assertions.assertEquals(assertA, usersFind.size)
        Assertions.assertEquals(assertB, usersFind[0].userFirstName)
    }

search.csv

users,search,assertA,assertB
"[{""userFirstName"":""HamidReza"",""validityDuration"":""PT10H""},{""userFirstName"":""robot"",""validityDuration"":""PT15H""}]",validityDuration!'PT10H',1,robot
"[{""userFirstName"":""HamidReza"",""validityDuration"":""PT10H""},{""userFirstName"":""robot"",""validityDuration"":""PT15H""}]",validityDuration:'PT10H',1,HamidReza

I have to think about strategy.