本文整理汇总了Java中au.com.dius.pact.model.RequestResponsePact类的典型用法代码示例。如果您正苦于以下问题:Java RequestResponsePact类的具体用法?Java RequestResponsePact怎么用?Java RequestResponsePact使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestResponsePact类属于au.com.dius.pact.model包,在下文中一共展示了RequestResponsePact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writePact
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
public void writePact(String url, long requestId, RequestResponsePact pact) {
String filename = outputPath + "/" + url.replaceAll("[^\\p{Alnum}]", "_") + requestId;
try {
String pactDefinition;
try (StringWriter strOut = new StringWriter()) {
PactWriter.writePact(pact, new PrintWriter(strOut));
pactDefinition = strOut.toString();
}
try (PrintWriter out = new PrintWriter(filename)) {
out.println( pactDefinition );
}
LOGGER.debug("Pact file: {}", pactDefinition);
} catch (IOException e) {
rethrowRuntimeException(e);
}
}
示例2: createFragment
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Pact(provider = "test_provider", consumer = "test_consumer")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
return builder
.given("test state")
.uponReceiving("ConsumerTest test interaction")
.path("/")
.method("GET")
.willRespondWith()
.status(200)
.headers(header)
.bodyWithSingleQuotes(("{'responsetest': true, 'name': 'harry'}"))
.toPact();
}
示例3: createFragment
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
public RequestResponsePact createFragment(PactDslWithProvider builder) {
Map<String, String> header = new HashMap<>();
header.put("Content-Type", "application/json");
return builder
.given("test state", "name", "Alexandra")
.uponReceiving("ConsumerTest test interaction")
.path("/")
.method("GET")
.willRespondWith()
.status(200)
.headers(header)
.bodyWithSingleQuotes("{'responsetest': true, 'name': 'harry'}")
.toPact();
}
示例4: resolvePactAnnotation
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
private Optional<Pact> resolvePactAnnotation(Optional<Class<?>> clazz, Method method) {
Pact pactMethodAnnotation = method.getAnnotation(Pact.class);
if (pactMethodAnnotation == null) {
// It can be at class level.
if (clazz.isPresent()) {
return Optional.ofNullable(clazz.get().getAnnotation(Pact.class));
} else {
// method will be ignored.
logger.log(Level.INFO, String.format(
"Method %s returns a %s type but it is not annotated at method nor at class level with %s",
method.getName(),
RequestResponsePact.class.getName(),
Pact.class.getName()));
return null;
}
} else {
return Optional.of(pactMethodAnnotation);
}
}
示例5: run
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Override
public Object run() {
long requestId = COUNTER.incrementAndGet();
try {
RequestContext context = RequestContext.getCurrentContext();
HttpServletRequest request = context.getRequest();
String url = request.getRequestURL().toString();
LOGGER.info("Request context: {}", context);
LOGGER.info("Request {}: {} request to {}", requestId, request.getMethod(), url);
PactDslRequestWithPath pactRequest = ConsumerPactBuilder
.consumer(clientName)
.hasPactWith(providerName)
.uponReceiving("Request id " + requestId)
.path(url)
.method(request.getMethod());
buildRequestBody(pactRequest);
PactDslResponse pactResponse = pactRequest
.willRespondWith()
.status(context.getResponseStatusCode());
buildResponseBody(pactResponse);
RequestResponsePact pact = pactResponse.toFragment().toPact();
pactResultWriter.writePact(url, requestId, pact);
} catch (IOException e) {
rethrowRuntimeException(e);
}
return null;
}
示例6: test
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Test
public void test() {
String resp = rest.getForObject(REQUEST_PATH, String.class);
assertThat(resp).isEqualTo(RESPONSE_BODY);
ArgumentCaptor<RequestResponsePact> argument = ArgumentCaptor.forClass(RequestResponsePact.class);
verify(pactResultWriter).writePact(endsWith("/some-service"), anyLong(), argument.capture());
}
示例7: create_ec2_instance_when_rds_create_db_instance
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
protected RequestResponsePact create_ec2_instance_when_rds_create_db_instance() {
return ConsumerPactBuilder.consumer("RDS").hasPactWith("EC2")
.uponReceiving("a request to create an ec2 instance")
.headers("Content-Type", "application/json")
.body(requestData)
.method(HttpMethod.POST)
.path("/instances")
.willRespondWith()
.body(responseData)
.toPact();
}
示例8: run
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
public static void run(RequestResponsePact pact, PactTestRun pactTestRun) {
MockProviderConfig config = MockProviderConfig.createDefault("localhost", PactSpecVersion.V2);
config.setPort(9002);
PactVerificationResult result = runConsumerTest(pact, config, pactTestRun);
if (result instanceof PactVerificationResult.Error) {
throw new RuntimeException(((PactVerificationResult.Error)result).getError());
}
assertEquals(PactVerificationResult.Ok.INSTANCE, result);
}
示例9: validatePactSignature
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
private void validatePactSignature(Method method) {
boolean hasValidPactSignature =
RequestResponsePact.class.isAssignableFrom(method.getReturnType())
&& method.getParameterTypes().length == 1
&& method.getParameterTypes()[0].isAssignableFrom(PactDslWithProvider.class);
if (!hasValidPactSignature) {
throw new UnsupportedOperationException("Method " + method.getName() +
" does not conform required method signature 'public PactFragment xxx(PactDslWithProvider builder)'");
}
}
示例10: findPactFragmentMethods
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
private List<Method> findPactFragmentMethods(TestClass testClass) {
final Method[] methods = testClass.getJavaClass().getMethods();
return Arrays.stream(methods)
.filter(method -> method.getReturnType().isAssignableFrom(RequestResponsePact.class))
.collect(Collectors.toList());
}
示例11: tonyStarkCreditScore
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Pact(provider = CREDIT_SCORE_SERVICE, consumer = SPECIAL_MEMBERSHIP_SERVICE)
public RequestResponsePact tonyStarkCreditScore(PactDslWithProvider pact) {
return pact.given("There is a [email protected]")
.uponReceiving("A credit score request for [email protected]")
.path("/credit-scores/[email protected]").method("GET")
.willRespondWith()
.status(200)
.body(new PactDslJsonBody().integerType("creditScore", 850))
.headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
.toPact();
}
示例12: hawleyGriffinCreditScore
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Pact(provider = CREDIT_SCORE_SERVICE, consumer = SPECIAL_MEMBERSHIP_SERVICE)
public RequestResponsePact hawleyGriffinCreditScore(PactDslWithProvider pact) {
return pact.given("There is not a [email protected]")
.uponReceiving("A credit score request for [email protected]")
.path("/credit-scores/[email protected]").method("GET")
.willRespondWith()
.status(404)
.toPact();
}
示例13: createPact
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Override
protected RequestResponsePact createPact(PactDslWithProvider builder) {
return builder
.uponReceiving("a root request").method("GET").path("/")
.willRespondWith().status(200).body("Hello, world!")
.toPact();
}
示例14: createFragment
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Pact(consumer = "My JAX-RS Consumer")
public RequestResponsePact createFragment(PactDslWithProvider builder) {
return builder
.uponReceiving("a root request").method("GET").path("/")
.willRespondWith().status(200).body("Hello, world!")
.toPact();
}
示例15: shouldGetValidatedEidasAuthnResponseFromSamlEngine
import au.com.dius.pact.model.RequestResponsePact; //导入依赖的package包/类
@Pact(consumer = POLICY_SERVICE, provider = SAML_ENGINE_SERVICE)
public RequestResponsePact shouldGetValidatedEidasAuthnResponseFromSamlEngine(PactDslWithProvider pact) {
return pact
.uponReceiving("A request to validate the Authn Response")
.path(Urls.SamlEngineUrls.TRANSLATE_COUNTRY_AUTHN_RESPONSE_RESOURCE).method("POST")
.headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
.body(
new PactDslJsonBody()
.stringValue("samlResponse", samlAuthnResponseContainerDto.getSamlResponse())
.stringValue("principalIPAddressAsSeenByHub", samlAuthnResponseContainerDto.getPrincipalIPAddressAsSeenByHub())
.stringValue("matchingServiceEntityId", TEST_RP_MS)
.object("sessionId")
.stringValue("sessionId", sessionId.getSessionId())
.closeObject()
)
.willRespondWith()
.status(Response.Status.OK.getStatusCode())
.headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
.body(
new PactDslJsonBody()
.stringValue("issuer", COUNTRY_ENTITY_ID)
.stringValue("persistentId", "UK/GB/12345")
.stringValue("status", "Success")
.nullValue("statusMessage")
.stringMatcher("encryptedIdentityAssertionBlob", ".+", encryptedIdentityAssertionString)
.stringValue("levelOfAssurance", "LEVEL_2")
)
.uponReceiving("A request to generate an attribute query request")
.path(Urls.SamlEngineUrls.GENERATE_COUNTRY_ATTRIBUTE_QUERY_RESOURCE).method("POST")
.headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
.body(
new PactDslJsonBody()
.stringMatcher("requestId", ".+", ID)
.stringValue("assertionConsumerServiceUri", "/default-service-index")
.stringValue("encryptedIdentityAssertion", encryptedIdentityAssertionString)
.stringValue("authnRequestIssuerEntityId", TEST_RP)
.stringValue("levelOfAssurance", "LEVEL_2")
.stringValue("matchingServiceAdapterUri", MATCHING_SERVICE_URI)
.stringValue("matchingServiceEntityId", TEST_RP_MS)
.timestamp("matchingServiceRequestTimeOut", "yyyy-MM-dd'T'HH:mm:ss.S'Z'")
.booleanValue("onboarding", true)
.nullValue("cycle3Dataset")
.nullValue("userAccountCreationAttributes")
.timestamp("assertionExpiry", "yyyy-MM-dd'T'HH:mm:ss.S'Z'")
.object("persistentId")
.stringValue("nameId", "UK/GB/12345")
.closeObject()
)
.willRespondWith()
.status(Response.Status.OK.getStatusCode())
.headers(singletonMap(CONTENT_TYPE, APPLICATION_JSON))
.body(
new PactDslJsonBody()
.stringMatcher("samlRequest", "[\\s\\S]+", SAML_ATTRIBUTE_QUERY)
.stringValue("matchingServiceUri", MATCHING_SERVICE_URI)
.stringValue("id", ID)
.stringValue("issuer", EIDAS_HUB_ENTITY_ID)
.timestamp("attributeQueryClientTimeOut", "yyyy-MM-dd'T'HH:mm:ss.S'Z'")
.booleanValue("onboarding", true)
)
.toPact();
}