-
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.
generate dependents from PACT contracts
- Loading branch information
Showing
9 changed files
with
219 additions
and
35 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
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,19 @@ | ||
package application.api | ||
|
||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/search") | ||
class SearchController { | ||
|
||
@PostMapping | ||
fun post(@RequestBody request: SearchRequest): List<SearchResult> { | ||
return emptyList() | ||
} | ||
|
||
data class SearchRequest(val userName: String?) | ||
data class SearchResult(val id: String) | ||
} |
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
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,67 @@ | ||
package application | ||
|
||
import application.documentation.ArchitectureDocumentation.createOrReplaceDependent | ||
import application.documentation.ComponentType | ||
import application.documentation.DependentDescription | ||
import application.documentation.Distance | ||
import au.com.dius.pact.provider.IConsumerInfo | ||
import au.com.dius.pact.provider.junit5.HttpTestTarget | ||
import au.com.dius.pact.provider.junit5.PactVerificationContext | ||
import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider | ||
import au.com.dius.pact.provider.junitsupport.Provider | ||
import au.com.dius.pact.provider.junitsupport.State | ||
import au.com.dius.pact.provider.junitsupport.VerificationReports | ||
import au.com.dius.pact.provider.junitsupport.loader.PactFolder | ||
import org.apache.hc.core5.http.HttpRequest | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS | ||
import org.junit.jupiter.api.TestTemplate | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.boot.test.web.server.LocalServerPort | ||
|
||
@TestInstance(PER_CLASS) | ||
@Provider("backend-service-1") | ||
@PactFolder("src/test/pacts") | ||
@VerificationReports("console") | ||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
@ExtendWith(PactVerificationInvocationContextProvider::class) | ||
internal class ContractTests { | ||
|
||
@BeforeEach | ||
fun setTarget(context: PactVerificationContext, @LocalServerPort port: Int) { | ||
context.target = HttpTestTarget("localhost", port) | ||
} | ||
|
||
@TestTemplate | ||
fun `consumer contract tests`(context: PactVerificationContext, request: HttpRequest) { | ||
createOrReplaceDependent(dependentDescription(context.consumer)) | ||
context.verifyInteraction() | ||
} | ||
|
||
@State("search returns empty result") | ||
fun noOpStates() { | ||
// nothing to do | ||
} | ||
|
||
private fun dependentDescription(consumer: IConsumerInfo): DependentDescription = | ||
when (consumer.name) { | ||
"frontend" -> DependentDescription( | ||
id = "frontend", | ||
groupId = "application", | ||
systemId = "platform", | ||
type = ComponentType.FRONTEND, | ||
distanceFromUs = Distance.OWNED | ||
) | ||
|
||
"external-service-x" -> DependentDescription( | ||
id = "external-service-x", | ||
type = ComponentType.BACKEND, | ||
distanceFromUs = Distance.EXTERNAL | ||
) | ||
|
||
else -> error("Unmapped dependent [${consumer.name}]! Please add a mapping here.") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"consumer": { | ||
"name": "external-service-x" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "execute simple search #1", | ||
"providerStates": [ | ||
{ | ||
"name": "search returns empty result" | ||
} | ||
], | ||
"request": { | ||
"headers": { | ||
"Accept": "application/json" | ||
}, | ||
"method": "POST", | ||
"path": "/search", | ||
"body": { | ||
"userName": "[email protected]" | ||
} | ||
}, | ||
"response": { | ||
"body": [], | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pact-jvm": { | ||
"version": "4.6.7" | ||
}, | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "backend-service-1" | ||
} | ||
} |
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,68 @@ | ||
{ | ||
"consumer": { | ||
"name": "frontend" | ||
}, | ||
"interactions": [ | ||
{ | ||
"description": "execute simple search #1", | ||
"providerStates": [ | ||
{ | ||
"name": "search returns empty result" | ||
} | ||
], | ||
"request": { | ||
"headers": { | ||
"Accept": "application/json" | ||
}, | ||
"method": "POST", | ||
"path": "/search", | ||
"body": { | ||
"userName": "[email protected]" | ||
} | ||
}, | ||
"response": { | ||
"body": [], | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200 | ||
} | ||
}, | ||
{ | ||
"description": "execute simple search #2", | ||
"providerStates": [ | ||
{ | ||
"name": "search returns empty result" | ||
} | ||
], | ||
"request": { | ||
"headers": { | ||
"Accept": "application/json" | ||
}, | ||
"method": "POST", | ||
"path": "/search", | ||
"body": { | ||
"userName": "[email protected]" | ||
} | ||
}, | ||
"response": { | ||
"body": [], | ||
"headers": { | ||
"Content-Type": "application/json" | ||
}, | ||
"status": 200 | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"pact-jvm": { | ||
"version": "4.6.7" | ||
}, | ||
"pactSpecification": { | ||
"version": "3.0.0" | ||
} | ||
}, | ||
"provider": { | ||
"name": "backend-service-1" | ||
} | ||
} |