|
| 1 | +package com.lohika.jclub.storage; |
| 2 | + |
| 3 | +import org.junit.ClassRule; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.boot.test.context.SpringBootTest; |
| 8 | +import org.springframework.hateoas.PagedResources; |
| 9 | +import org.springframework.test.context.junit4.SpringRunner; |
| 10 | +import org.testcontainers.containers.GenericContainer; |
| 11 | +import org.testcontainers.containers.wait.LogMessageWaitStrategy; |
| 12 | + |
| 13 | +import static org.hamcrest.Matchers.hasSize; |
| 14 | +import static org.hamcrest.Matchers.notNullValue; |
| 15 | +import static org.hamcrest.Matchers.nullValue; |
| 16 | +import static org.junit.Assert.assertThat; |
| 17 | + |
| 18 | +@RunWith(SpringRunner.class) |
| 19 | +@SpringBootTest(classes = StorageServiceClientTestApplication.class) |
| 20 | +public class StorageServiceClientFallbackTest { |
| 21 | + |
| 22 | + @ClassRule |
| 23 | + public static GenericContainer storageService = new GenericContainer("storage-service:latest") |
| 24 | + .withExposedPorts(8091) |
| 25 | + .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started StorageServiceApplication in.*\\s")); |
| 26 | + |
| 27 | + @Autowired |
| 28 | + private StorageServiceClient storageServiceClient; |
| 29 | + |
| 30 | + @Autowired |
| 31 | + private StorageServiceClientFallback storageServiceClientFallback; |
| 32 | + |
| 33 | + private Apartment apartment = Apartment.builder() |
| 34 | + .location("location") |
| 35 | + .mail("mail") |
| 36 | + .phone("phone") |
| 37 | + .price(1.5d) |
| 38 | + .realtorName("realtorName") |
| 39 | + .sqft(1.3d) |
| 40 | + .build(); |
| 41 | + |
| 42 | + @Test |
| 43 | + public void list() { |
| 44 | + PagedResources<Apartment> actual = storageServiceClient.list(); |
| 45 | + |
| 46 | + assertThat(actual, notNullValue()); |
| 47 | + assertThat(actual.getContent(), notNullValue()); |
| 48 | + |
| 49 | + assertThat(actual.getContent(), hasSize(0)); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void create() { |
| 54 | + Apartment actual = storageServiceClient.create(apartment); |
| 55 | + |
| 56 | + assertThat(actual, nullValue()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void get() { |
| 61 | + Apartment actual = storageServiceClient.get("not-existing-id"); |
| 62 | + |
| 63 | + assertThat(actual, nullValue()); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void update() { |
| 68 | + Apartment actual = storageServiceClient.update("not-existing-id", apartment); |
| 69 | + |
| 70 | + assertThat(actual, nullValue()); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void delete() { |
| 75 | + storageServiceClient.delete("not-existing-id"); |
| 76 | + } |
| 77 | +} |
0 commit comments