-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Contract tests using spring-cloud-contract
- Loading branch information
Showing
16 changed files
with
161 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Fri Feb 23 18:20:49 EST 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include 'groovy' | ||
|
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
src/test/java/org/aitesting/microservices/tests/helpers/TestConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.aitesting.microservices.tests.helpers; | ||
|
||
import java.util.UUID; | ||
|
||
public class TestConstants { | ||
public static final UUID TRIP_ID1 = UUID.fromString("f849769e-2534-84a6-d475-5c2d701343ab"); | ||
public static final UUID TRIP_ID2 = UUID.fromString("5b842415-9447-4b9b-85c6-2e1075214cc4"); | ||
public static final UUID TRIP_ID3 = UUID.fromString("7a7d1e99-4823-4aa5-9d3b-2307e88cee0d"); | ||
public static final UUID USER_ID = UUID.fromString("123e4567-e89b-12d3-a456-426655440000"); | ||
public static final String FROM = "from some place over there"; | ||
public static final String TO = "to this other place"; | ||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/org/aitesting/microservices/tests/provider/TripContractBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.aitesting.microservices.tests.provider; | ||
|
||
import io.restassured.module.mockmvc.RestAssuredMockMvc; | ||
import org.aitesting.microservices.tripmanagement.common.TripStatus; | ||
import org.aitesting.microservices.tripmanagement.query.TripManagementQueryApplication; | ||
import org.aitesting.microservices.tripmanagement.query.domain.models.Trip; | ||
import org.aitesting.microservices.tripmanagement.query.service.repositories.TripRepository; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import static org.aitesting.microservices.tests.helpers.TestConstants.*; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(classes = TripManagementQueryApplication.class) | ||
public abstract class TripContractBase { | ||
|
||
@Autowired | ||
private WebApplicationContext webApplicationContext; | ||
|
||
@Autowired | ||
TripRepository tripRepository; | ||
|
||
@Before | ||
public void setup() { | ||
RestAssuredMockMvc.webAppContextSetup(webApplicationContext); | ||
tripRepository.findAll(); | ||
tripRepository.save(new Trip(TRIP_ID1, USER_ID, FROM, TO, TripStatus.STARTED)); | ||
tripRepository.save(new Trip(TRIP_ID2, USER_ID, FROM, TO, TripStatus.CREATED)); | ||
tripRepository.save(new Trip(TRIP_ID3, USER_ID, FROM, TO, TripStatus.COMPLETED)); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
tripRepository.deleteAll(); | ||
} | ||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...query/unit/TripEventHandlerUnitTests.java → ...tests/unit/TripEventHandlerUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
src/test/resources/contracts/TripQuery/ShouldGetTrip.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package TripQuery | ||
|
||
import org.springframework.cloud.contract.spec.* | ||
|
||
Contract.make { | ||
description("When a Get request with a TripID is made, the corresponding trip is returned") | ||
request { | ||
method 'GET' | ||
url '/api/trip/f849769e-2534-84a6-d475-5c2d701343ab' | ||
} | ||
response { | ||
status 200 | ||
body( | ||
"id": "f849769e-2534-84a6-d475-5c2d701343ab", | ||
"userID": "123e4567-e89b-12d3-a456-426655440000", | ||
"originAddress": "from some place over there", | ||
"destinationAddress": "to this other place", | ||
"status": "STARTED" | ||
) | ||
headers { | ||
contentType(applicationJson()) | ||
} | ||
} | ||
} | ||
|
44 changes: 44 additions & 0 deletions
44
src/test/resources/contracts/TripQuery/shouldGetAllTrips.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package TripQuery | ||
|
||
import org.springframework.cloud.contract.spec.* | ||
|
||
Contract.make { | ||
description("When a Get request for all the trips should get all the trips") | ||
request { | ||
method 'GET' | ||
url '/api/trips' | ||
} | ||
response { | ||
status 200 | ||
body(""" | ||
[ | ||
\t{ | ||
\t\t"id": "f849769e-2534-84a6-d475-5c2d701343ab", | ||
\t\t"userID": "123e4567-e89b-12d3-a456-426655440000", | ||
\t\t"originAddress": "from some place over there", | ||
\t\t"destinationAddress": "to this other place", | ||
\t\t"status": "STARTED" | ||
\t}, | ||
\t{ | ||
\t\t"id": "5b842415-9447-4b9b-85c6-2e1075214cc4", | ||
\t\t"userID": "123e4567-e89b-12d3-a456-426655440000", | ||
\t\t"originAddress": "from some place over there", | ||
\t\t"destinationAddress": "to this other place", | ||
\t\t"status": "CREATED" | ||
\t}, | ||
\t{ | ||
\t\t"id": "7a7d1e99-4823-4aa5-9d3b-2307e88cee0d", | ||
\t\t"userID": "123e4567-e89b-12d3-a456-426655440000", | ||
\t\t"originAddress": "from some place over there", | ||
\t\t"destinationAddress": "to this other place", | ||
\t\t"status": "COMPLETED" | ||
\t} | ||
] | ||
""" | ||
) | ||
headers { | ||
contentType(applicationJson()) | ||
} | ||
} | ||
} | ||
|
Binary file not shown.