diff --git a/road/src/test/groovy/com/example/road/pharmacy/cache/PharmacyRedisTemplateServiceTest.groovy b/road/src/test/groovy/com/example/road/pharmacy/cache/PharmacyRedisTemplateServiceTest.groovy new file mode 100644 index 00000000..7b06787d --- /dev/null +++ b/road/src/test/groovy/com/example/road/pharmacy/cache/PharmacyRedisTemplateServiceTest.groovy @@ -0,0 +1,74 @@ +package com.example.road.pharmacy.cache + +import com.example.road.AbstractIntegrationContainerBaseTest +import com.example.road.pharmacy.dto.PharmacyDto +import org.springframework.beans.factory.annotation.Autowired + +class PharmacyRedisTemplateServiceTest extends AbstractIntegrationContainerBaseTest { + + @Autowired + private PharmacyRedisTemplateService pharmacyRedisTemplateService + + def setup() { + pharmacyRedisTemplateService.findAll() + .forEach(dto -> { + pharmacyRedisTemplateService.delete(dto.getId()) + }) + } + + def "save success"() { + given: + String pharmacyName = "name" + String pharmacyAddress = "address" + PharmacyDto dto = + PharmacyDto.builder() + .id(1L) + .pharmacyName(pharmacyName) + .pharmacyAddress(pharmacyAddress) + .build() + + when: + pharmacyRedisTemplateService.save(dto) + List result = pharmacyRedisTemplateService.findAll() + + then: + result.size() == 1 + result.get(0).id == 1L + result.get(0).pharmacyName == pharmacyName + result.get(0).pharmacyAddress == pharmacyAddress + } + + def "success fail"() { + given: + PharmacyDto dto = + PharmacyDto.builder() + .build() + + when: + pharmacyRedisTemplateService.save(dto) + List result = pharmacyRedisTemplateService.findAll() + + then: + result.size() == 0 + } + + def "delete"() { + given: + String pharmacyName = "name" + String pharmacyAddress = "address" + PharmacyDto dto = + PharmacyDto.builder() + .id(1L) + .pharmacyName(pharmacyName) + .pharmacyAddress(pharmacyAddress) + .build() + + when: + pharmacyRedisTemplateService.save(dto) + pharmacyRedisTemplateService.delete(dto.getId()) + def result = pharmacyRedisTemplateService.findAll() + + then: + result.size() == 0 + } +} diff --git a/road/src/test/groovy/com/example/road/pharmacy/service/PharmacySearchServiceTest.groovy b/road/src/test/groovy/com/example/road/pharmacy/service/PharmacySearchServiceTest.groovy new file mode 100644 index 00000000..b2338a0f --- /dev/null +++ b/road/src/test/groovy/com/example/road/pharmacy/service/PharmacySearchServiceTest.groovy @@ -0,0 +1,45 @@ +package com.example.road.pharmacy.service + +import com.example.road.pharmacy.cache.PharmacyRedisTemplateService +import com.example.road.pharmacy.entity.Pharmacy +import org.assertj.core.util.Lists +import spock.lang.Specification + +class PharmacySearchServiceTest extends Specification { + + private PharmacySearchService pharmacySearchService + + private PharmacyRepositoryService pharmacyRepositoryService = Mock() + private PharmacyRedisTemplateService pharmacyRedisTemplateService = Mock() + + private List pharmacyList + + def setup() { + pharmacySearchService = new PharmacySearchService(pharmacyRepositoryService, pharmacyRedisTemplateService) + + pharmacyList = Lists.newArrayList( + Pharmacy.builder() + .id(1L) + .pharmacyName("호수온누리약국") + .latitude(37.60894036) + .longitude(127.029052) + .build(), + Pharmacy.builder() + .id(2L) + .pharmacyName("돌곶이온누리약국") + .latitude(37.61040424) + .longitude(127.0569046) + .build()) + } + + def "레디스 장애시 DB를 이용하여 약국 데이터 조회"() { + when: + pharmacyRedisTemplateService.findAll() >> [] + pharmacyRepositoryService.findAll() >> pharmacyList + + def result = pharmacySearchService.searchPharmacyDtoList() + + then: + result.size() == 2 + } +}