Skip to content

Commit cf49023

Browse files
author
Roman Tsypuk
committed
added containers chaining
1 parent 77781c1 commit cf49023

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

client-service/src/main/java/com/lohika/jclub/client/ClientController.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import org.springframework.web.bind.annotation.GetMapping;
99
import org.springframework.web.bind.annotation.RestController;
1010

11-
import java.util.Collection;
12-
1311
import lombok.extern.slf4j.Slf4j;
1412

1513
@Slf4j
@@ -22,9 +20,7 @@ public class ClientController {
2220
@GetMapping("/apartments")
2321
public PagedResources<Apartment> getApartments() {
2422
PagedResources<Apartment> list = storageServiceClient.list();
25-
Collection<Apartment> content = list.getContent();
26-
return new PagedResources<>(content, list.getMetadata());
27-
//TODO wrap appratments with resources. generate links to client service.
23+
return new PagedResources<>(list.getContent(), list.getMetadata());
2824
}
2925

3026
}
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.lohika.jclub.client;
22

3+
import com.lohika.jclub.storage.client.Apartment;
34
import com.lohika.jclub.storage.client.StorageServiceClient;
45

56
import org.junit.ClassRule;
67
import org.junit.Rule;
78
import org.junit.Test;
8-
import org.junit.rules.RuleChain;
9-
import org.junit.rules.TestRule;
109
import org.junit.runner.RunWith;
1110
import org.springframework.beans.factory.annotation.Autowired;
1211
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -33,23 +32,15 @@ public class ClientServiceTest {
3332

3433
@ClassRule
3534
public static GenericContainer discoveryService = new GenericContainer("discovery-service:latest")
36-
// .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Registered instance STORAGE-SERVICE.*\\s"))
3735
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s"))
3836
.withExposedPorts(8761);
3937

4038
@Rule
4139
public GenericContainer storageService = new GenericContainer("storage-service:latest")
42-
// .withStartupTimeout(Duration.ofSeconds(20))
4340
.withExposedPorts(8091)
4441
.withEnv("eureka.client.serviceUrl.defaultZone", "http://" + discoveryService.getContainerIpAddress() + ":" + discoveryService.getMappedPort(8761) + "/eureka")
4542
.withEnv("eureka.instance.preferIpAddress", "true")
46-
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started EurekaServerApplication in.*\\s"));
47-
// .waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s"));
48-
49-
// @ClassRule
50-
// public static TestRule chain = RuleChain
51-
// .outerRule(discoveryService)
52-
// .around(storageService);
43+
.waitingFor(new LogMessageWaitStrategy().withRegEx(".*DiscoveryClient_STORAGE-SERVICE.*registration status: 204.*\\s"));
5344

5445
@Autowired
5546
private StorageServiceClient storageServiceClient;
@@ -60,30 +51,32 @@ public class ClientServiceTest {
6051
public static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
6152
@Override
6253
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
63-
64-
// EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
65-
// "storage-service.ribbon.servers=http://" + storageService.getContainerIpAddress() + ":"
66-
// + storageService.getMappedPort(8091) + "/"
67-
// );
6854
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
6955
"eureka.client.serviceUrl.defaultZone=http://" + discoveryService.getContainerIpAddress() +
70-
":" + discoveryService.getMappedPort(8761) + "/eureka");
71-
72-
73-
EnvironmentTestUtils.addEnvironment("testcontainers", configurableApplicationContext.getEnvironment(),
74-
"eureka.instance.preferIpAddress=true");
75-
56+
":" + discoveryService.getMappedPort(8761) + "/eureka",
57+
"storage-service.ribbon.servers=http://");
7658
}
7759
}
7860

7961
@Test
8062
public void testGetApartments() throws Exception {
8163
// Given
64+
Apartment lviv = storageServiceClient.create(
65+
Apartment.builder()
66+
.location("LVIV")
67+
.mail("asfafs@asf.com")
68+
.phone("02510505001")
69+
.price(5225)
70+
.realtorName("Bariga")
71+
.sqft(55)
72+
.build());
8273

8374
// When
8475
mockMvc.perform(MockMvcRequestBuilders.get("/apartments"))
8576
.andDo(print());
8677

8778
// Then
79+
//TODO storageServiceClient does not creating the records.
80+
// fallback is working with 0 paging
8881
}
8982
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feign.hystrix.enabled=true

0 commit comments

Comments
 (0)