Skip to content

Commit b9f92fb

Browse files
committed
end to end test fixed
1 parent 685279e commit b9f92fb

File tree

11 files changed

+105
-14
lines changed

11 files changed

+105
-14
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,20 @@
1111

1212
import lombok.extern.slf4j.Slf4j;
1313

14+
import javax.annotation.PostConstruct;
15+
1416
@Slf4j
1517
@RestController
1618
public class ClientController {
1719

1820
@Autowired
1921
private StorageServiceClient storageServiceClient;
2022

23+
@PostConstruct
24+
public void warmUp() {
25+
storageServiceClient.list();
26+
}
27+
2128
@GetMapping(value = "/apartments", produces = MediaType.APPLICATION_JSON_VALUE)
2229
public PagedResources<Apartment> getApartments() {
2330
PagedResources<Apartment> list = storageServiceClient.list();

client-service/src/test/java/com/lohika/jclub/client/ClientServiceTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import org.testcontainers.containers.GenericContainer;
2121
import org.testcontainers.containers.wait.LogMessageWaitStrategy;
2222

23-
import java.time.Duration;
24-
23+
import static org.hamcrest.CoreMatchers.notNullValue;
24+
import static org.hamcrest.MatcherAssert.assertThat;
2525
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
2626

2727
@RunWith(SpringRunner.class)
@@ -54,6 +54,9 @@ public void testGetApartments() throws Exception {
5454
.sqft(55)
5555
.build());
5656

57+
assertThat(lviv, notNullValue());
58+
assertThat(lviv.getId(), notNullValue());
59+
5760
// When
5861
mockMvc.perform(MockMvcRequestBuilders.get("/apartments"))
5962
.andDo(print());

dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.nio.file.Files;
1818
import java.nio.file.Paths;
1919

20+
import javax.annotation.PostConstruct;
21+
2022
@Service
2123
public class DslService {
2224
private static final String DSL_EXTENSION = ".mydsl";
@@ -30,6 +32,11 @@ public class DslService {
3032
@Autowired
3133
private RatingServiceClient ratingServiceClient;
3234

35+
@PostConstruct
36+
public void warmUp() {
37+
storageServiceClient.list();
38+
}
39+
3340
public MyDsl runScript(String scriptName) throws IOException {
3441
String script = getScriptByName(scriptName);
3542
return run(script);
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.lohika.jclub.hackster.client;
22

3-
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
43
import org.springframework.cloud.netflix.feign.EnableFeignClients;
54
import org.springframework.context.annotation.Import;
6-
import org.springframework.hateoas.config.EnableHypermediaSupport;
75

86
import java.lang.annotation.Documented;
97
import java.lang.annotation.ElementType;
@@ -15,9 +13,7 @@
1513
@Retention(RetentionPolicy.RUNTIME)
1614
@Documented
1715

18-
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
1916
@EnableFeignClients(clients = {HacksterServiceClient.class})
2017
@Import({FeignMappingDefaultConfiguration.class, HacksterServiceClientConfiguration.class})
21-
@EnableDiscoveryClient
2218
public @interface EnableHacksterServiceClient {
2319
}

integration-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<version>0.0.1-SNAPSHOT</version>
4242
<scope>test</scope>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.lohika.jclub.storage.client</groupId>
46+
<artifactId>storage-service-client</artifactId>
47+
<version>0.0.1-SNAPSHOT</version>
48+
<scope>test</scope>
49+
</dependency>
4450

4551
<dependency>
4652
<groupId>org.springframework.boot</groupId>

integration-test/src/test/java/com/lohika/jclub/integration/BaseIntegrationTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
import lombok.extern.log4j.Log4j;
44

5+
import com.lohika.jclub.storage.client.StorageServiceClient;
6+
57
import org.apache.http.HttpResponse;
68
import org.apache.http.client.HttpClient;
79
import org.apache.http.client.methods.HttpGet;
810
import org.apache.http.impl.client.HttpClientBuilder;
11+
import org.junit.After;
12+
import org.junit.Before;
913
import org.junit.BeforeClass;
1014
import org.junit.runner.RunWith;
15+
import org.springframework.beans.factory.annotation.Autowired;
1116
import org.springframework.boot.test.context.SpringBootTest;
1217
import org.springframework.boot.test.util.EnvironmentTestUtils;
1318
import org.springframework.context.ApplicationContextInitializer;
@@ -17,6 +22,8 @@
1722

1823
import java.io.IOException;
1924

25+
import javax.annotation.PostConstruct;
26+
2027
import static org.hamcrest.CoreMatchers.notNullValue;
2128
import static org.hamcrest.MatcherAssert.assertThat;
2229

@@ -33,11 +40,25 @@ public abstract class BaseIntegrationTest {
3340
private static final int DISCOVERY_SERVER_PORT = 8761;
3441
private static final int SLEEP = 5000;
3542

43+
@Autowired
44+
protected StorageServiceClient storageServiceClient;
45+
3646
@BeforeClass
3747
public static void init() {
3848
assertThat(EntToEndIntegrationTestSuite.environment, notNullValue());
3949
}
4050

51+
@Before
52+
public void warmUp() {
53+
storageServiceClient.list();
54+
}
55+
56+
@Before
57+
public void cleanUp() {
58+
storageServiceClient.list().getContent()
59+
.forEach(apartment -> storageServiceClient.delete(apartment.getId()));
60+
}
61+
4162
public static void waitFor(String service) throws InterruptedException {
4263
HttpClient client = HttpClientBuilder.create().build();
4364
String gateway = "http://" + DISCOVERY_SERVER + ":" + DISCOVERY_SERVER_PORT + "/eureka/apps/" + service;

integration-test/src/test/java/com/lohika/jclub/integration/DslIntegrationTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package com.lohika.jclub.integration;
22

3+
import com.lohika.jclub.storage.client.Apartment;
4+
35
import org.junit.BeforeClass;
46
import org.junit.Test;
57
import org.springframework.beans.factory.annotation.Autowired;
68
import org.springframework.http.HttpMethod;
79
import org.springframework.http.ResponseEntity;
810
import org.springframework.web.client.RestTemplate;
911

12+
import java.util.Collection;
1013
import java.util.Map;
1114

1215
import static org.hamcrest.CoreMatchers.is;
1316
import static org.hamcrest.CoreMatchers.notNullValue;
1417
import static org.hamcrest.MatcherAssert.assertThat;
18+
import static org.hamcrest.Matchers.hasSize;
1519

1620
public class DslIntegrationTest extends BaseIntegrationTest {
1721
private static final String SIMPLE_DSL_EXECUTE = "http://" + DSL_EXECUTOR_SERVICE + "/dsl/end-to-end";
@@ -28,21 +32,36 @@ public static void setUpTests() throws InterruptedException {
2832

2933
@Test
3034
public void apartmentShouldBeAvailableAfterDslExecution() {
35+
/* GIVEN */
36+
37+
/* WHEN */
3138
ResponseEntity<Map> dslResult = restTemplate.exchange(
3239
SIMPLE_DSL_EXECUTE,
3340
HttpMethod.GET,
3441
null,
3542
Map.class
3643
);
3744

45+
/* THEN */
46+
assertThat(dslResult, notNullValue());
47+
assertThat(dslResult.getStatusCode().value(), is(200));
48+
49+
/* WHEN */
50+
Collection<Apartment> apartments = storageServiceClient.list().getContent();
51+
52+
/* THEN */
53+
assertThat(apartments, notNullValue());
54+
assertThat(apartments, hasSize(1));
55+
56+
/* WHEN */
3857
ResponseEntity<Map> get = restTemplate.exchange(
3958
GET_APARTMENTS,
4059
HttpMethod.GET,
4160
null,
4261
Map.class
4362
);
4463

64+
/* THEN */
4565
assertThat(get.getStatusCode().value(), is(200));
46-
assertThat(get.getBody().get("id"), notNullValue());
4766
}
4867
}

integration-test/src/test/java/com/lohika/jclub/integration/GetWayIntegrationTest.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.lohika.jclub.integration;
22

3+
import com.lohika.jclub.storage.client.Apartment;
4+
35
import org.junit.BeforeClass;
46
import org.junit.Test;
57
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,16 +10,16 @@
810
import org.springframework.http.ResponseEntity;
911
import org.springframework.web.client.RestTemplate;
1012

13+
import java.util.Collection;
1114
import java.util.HashMap;
1215
import java.util.Map;
1316

1417
import static org.hamcrest.CoreMatchers.is;
1518
import static org.hamcrest.CoreMatchers.notNullValue;
1619
import static org.hamcrest.MatcherAssert.assertThat;
20+
import static org.hamcrest.Matchers.hasSize;
1721

1822
public class GetWayIntegrationTest extends BaseIntegrationTest {
19-
20-
2123
private static final String STORE_APARTMENTS = "http://" + API_GATEWAY_SERVICE +
2224
"/api/realtor-service/storeApartments";
2325
private static final String GET_APARTMENTS = "http://" + API_GATEWAY_SERVICE + "/api/client-service/apartments";
@@ -32,33 +34,50 @@ public static void setUpTests() throws InterruptedException {
3234

3335
@Test
3436
public void apartmentShouldBeAvailableAfterAdding() {
35-
Map<String, Object> params = new HashMap() {
37+
/* GIVEN */
38+
final String email = "mail@domen.com";
39+
Map params = new HashMap() {
3640
{
3741
put("location", "location");
3842
put("price", 1500.5);
3943
put("sqft", 1.5);
4044
put("phone", "123");
41-
put("realtorName", "vas");
42-
put("mail", "mail@exem.comn");
45+
put("realtorName", "realtorName");
46+
put("mail", email);
4347

4448
}
4549
};
4650

51+
/* WHEN */
4752
ResponseEntity<Map> create = restTemplate.exchange(
4853
STORE_APARTMENTS,
4954
HttpMethod.POST,
5055
new HttpEntity<>(params),
5156
Map.class
5257
);
5358

59+
/* THEN */
60+
assertThat(create, notNullValue());
61+
assertThat(create.getStatusCode().value(), is(200));
62+
String createdId = (String) create.getBody().get("id");
63+
assertThat(createdId, notNullValue());
64+
65+
/* WHEN */
66+
Collection<Apartment> apartments = storageServiceClient.list().getContent();
67+
68+
/* THEN */
69+
assertThat(apartments, notNullValue());
70+
assertThat(apartments, hasSize(1));
71+
72+
/* WHEN */
5473
ResponseEntity<Map> get = restTemplate.exchange(
5574
GET_APARTMENTS,
5675
HttpMethod.GET,
5776
null,
5877
Map.class
5978
);
6079

80+
/* THEN */
6181
assertThat(get.getStatusCode().value(), is(200));
62-
assertThat(get.getBody().get("id"), notNullValue());
6382
}
6483
}

integration-test/src/test/java/com/lohika/jclub/integration/IntegrationTestApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package com.lohika.jclub.integration;
22

3+
import com.lohika.jclub.storage.client.EnableStorageServiceClient;
4+
import com.lohika.jclub.storage.client.StorageServiceClient;
5+
36
import org.springframework.boot.SpringApplication;
47
import org.springframework.boot.autoconfigure.SpringBootApplication;
58
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
69
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
10+
import org.springframework.cloud.netflix.feign.EnableFeignClients;
711
import org.springframework.context.annotation.Bean;
812
import org.springframework.web.client.RestTemplate;
913

1014
@EnableDiscoveryClient
15+
@EnableStorageServiceClient
16+
@EnableFeignClients(clients = {StorageServiceClient.class})
1117
@SpringBootApplication
1218
public class IntegrationTestApplication {
1319

integration-test/src/test/resources/dsl/end-to-end.mydsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ apartment {
44
sqft 3.4
55
phone 'phone'
66
realtorName 'realtorName'
7-
mail 'mail'
7+
mail 'ent-to-end-mail@domen.com'
88
}

0 commit comments

Comments
 (0)