Search in sources :

Example 61 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class WireMockServer method stubMatching.

public void stubMatching(RequestMethod method, String pattern, ContentPattern<?> content, Consumer<ResponseDefinitionBuilder> consumer) {
    UrlPathPattern matcher = WireMock.urlPathMatching(pattern);
    MappingBuilder request = WireMock.request(method.getName(), matcher).withRequestBody(content);
    ResponseDefinitionBuilder response = WireMock.aResponse();
    consumer.accept(response);
    stubFor(request.willReturn(response));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern)

Example 62 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class WireMockServer method stubMatching.

public void stubMatching(RequestMethod method, String pattern, Consumer<MappingBuilder> mappingConsumer, Consumer<ResponseDefinitionBuilder> consumer) {
    UrlPathPattern matcher = WireMock.urlPathMatching(pattern);
    MappingBuilder request = WireMock.request(method.getName(), matcher);
    mappingConsumer.accept(request);
    ResponseDefinitionBuilder response = WireMock.aResponse();
    consumer.accept(response);
    stubFor(request.willReturn(response));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern)

Example 63 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class WireMockServer method stubPathEquals.

public void stubPathEquals(RequestMethod method, String pattern, Consumer<ResponseDefinitionBuilder> consumer) {
    UrlPathPattern matcher = WireMock.urlPathEqualTo(pattern);
    MappingBuilder request = WireMock.request(method.getName(), matcher);
    ResponseDefinitionBuilder response = WireMock.aResponse();
    consumer.accept(response);
    stubFor(request.willReturn(response));
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern)

Example 64 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class AuthUrlTest method namespaceIsProvisioned.

@Test
void namespaceIsProvisioned() {
    UrlPathPattern cosUrl = urlPathMatching("/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces");
    UrlPathPattern ssoUrl = urlPathMatching("/api/kafkas_mgmt/v1/sso_providers");
    given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
    untilAsserted(() -> {
        server.verify(exactly(1), getRequestedFor(cosUrl));
        server.verify(exactly(1), getRequestedFor(ssoUrl));
    });
    untilAsserted(() -> {
        given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
        server.verify(moreThanOrExactly(2), getRequestedFor(cosUrl));
        server.verify(moreThanOrExactly(2), getRequestedFor(ssoUrl));
    });
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 65 with UrlPathPattern

use of com.github.tomakehurst.wiremock.matching.UrlPathPattern in project mod-source-record-manager by folio-org.

the class RecordProcessedEventHandlingServiceImplTest method setUp.

@Before
public void setUp() throws IOException {
    String[] hostAndPort = kafkaCluster.getBrokerList().split(":");
    kafkaConfig = KafkaConfig.builder().kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).envId(KAFKA_ENV_ID).build();
    String rules = TestUtil.readFileFromPath(RULES_PATH);
    MockitoAnnotations.openMocks(this);
    mappingRuleCache = new MappingRuleCache(mappingRuleDao, vertx);
    marcRecordAnalyzer = new MarcRecordAnalyzer();
    mappingRuleService = new MappingRuleServiceImpl(mappingRuleDao, mappingRuleCache);
    mappingRuleDao = when(mock(MappingRuleDaoImpl.class).get(any(), anyString())).thenReturn(Future.succeededFuture(Optional.of(new JsonObject(rules)))).getMock();
    mappingParametersProvider = when(mock(MappingParametersProvider.class).get(anyString(), any(OkapiConnectionParams.class))).thenReturn(Future.succeededFuture(new MappingParameters())).getMock();
    mappingMetadataService = new MappingMetadataServiceImpl(mappingParametersProvider, mappingRuleService, mappingRulesSnapshotDao, mappingParamsSnapshotDao);
    changeEngineService = new ChangeEngineServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, marcRecordAnalyzer, hrIdFieldService, recordsPublishingService, mappingMetadataService, kafkaConfig);
    ReflectionTestUtils.setField(changeEngineService, "maxDistributionNum", 10);
    ReflectionTestUtils.setField(changeEngineService, "batchSize", 100);
    chunkProcessingService = new EventDrivenChunkProcessingServiceImpl(jobExecutionSourceChunkDao, jobExecutionService, changeEngineService, jobExecutionProgressService);
    recordProcessedEventHandlingService = new RecordProcessedEventHandlingServiceImpl(jobExecutionProgressService, jobExecutionService, journalService, jobMonitoringService);
    HashMap<String, String> headers = new HashMap<>();
    headers.put(OKAPI_URL_HEADER, "http://localhost:" + snapshotMockServer.port());
    headers.put(OKAPI_TENANT_HEADER, TENANT_ID);
    headers.put(OKAPI_TOKEN_HEADER, "token");
    params = new OkapiConnectionParams(headers, vertx);
    WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern("/data-import-profiles/jobProfiles/" + ".*"), true)).willReturn(ok().withBody(JsonObject.mapFrom(jobProfile).encode())));
}
Also used : HashMap(java.util.HashMap) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) MappingRuleDaoImpl(org.folio.dao.MappingRuleDaoImpl) JsonObject(io.vertx.core.json.JsonObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OkapiConnectionParams(org.folio.dataimport.util.OkapiConnectionParams) MappingParametersProvider(org.folio.services.mappers.processor.MappingParametersProvider) UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) MappingParameters(org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters) MarcRecordAnalyzer(org.folio.dataimport.util.marc.MarcRecordAnalyzer) Before(org.junit.Before)

Aggregations

UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)112 RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)84 Test (org.junit.Test)76 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)54 Async (io.vertx.ext.unit.Async)42 Before (org.junit.Before)33 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)28 Matchers.containsString (org.hamcrest.Matchers.containsString)26 JsonObject (io.vertx.core.json.JsonObject)22 TestContext (io.vertx.ext.unit.TestContext)20 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)19 IOException (java.io.IOException)19 RunWith (org.junit.runner.RunWith)19 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)15 URISyntaxException (java.net.URISyntaxException)15 STUB_TENANT (org.folio.test.util.TestUtil.STUB_TENANT)14 After (org.junit.After)14 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)13 HashMap (java.util.HashMap)13