#26 pharmacy: redis test
This commit is contained in:
74
road/src/test/groovy/com/example/road/pharmacy/cache/PharmacyRedisTemplateServiceTest.groovy
vendored
Normal file
74
road/src/test/groovy/com/example/road/pharmacy/cache/PharmacyRedisTemplateServiceTest.groovy
vendored
Normal file
@@ -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<PharmacyDto> 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<PharmacyDto> 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Pharmacy> 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user