11package com .lohika .jclub .integration ;
22
3+ import com .lohika .jclub .storage .client .Apartment ;
4+
35import org .junit .BeforeClass ;
46import org .junit .Test ;
57import org .springframework .beans .factory .annotation .Autowired ;
810import org .springframework .http .ResponseEntity ;
911import org .springframework .web .client .RestTemplate ;
1012
13+ import java .util .Collection ;
1114import java .util .HashMap ;
1215import java .util .Map ;
1316
1417import static org .hamcrest .CoreMatchers .is ;
1518import static org .hamcrest .CoreMatchers .notNullValue ;
1619import static org .hamcrest .MatcherAssert .assertThat ;
20+ import static org .hamcrest .Matchers .hasSize ;
1721
1822public 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}
0 commit comments