11package com .lohika .jclub .client ;
22
3+ import com .lohika .jclub .storage .client .Apartment ;
34import com .lohika .jclub .storage .client .StorageServiceClient ;
45
56import org .junit .ClassRule ;
67import org .junit .Rule ;
78import org .junit .Test ;
8- import org .junit .rules .RuleChain ;
9- import org .junit .rules .TestRule ;
109import org .junit .runner .RunWith ;
1110import org .springframework .beans .factory .annotation .Autowired ;
1211import 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}
0 commit comments