Search in sources :

Example 6 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-inventory by folio-org.

the class DataImportKafkaHandlerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.openMocks(this);
    String[] hostAndPort = cluster.getBrokerList().split(":");
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(JOB_PROFILE_URL + "/.*"), true)).willReturn(WireMock.ok().withBody(Json.encode(profileSnapshotWrapper))));
    KafkaConfig kafkaConfig = KafkaConfig.builder().kafkaHost(hostAndPort[0]).kafkaPort(hostAndPort[1]).maxRequestSize(1048576).build();
    HttpClient client = vertx.createHttpClient(new HttpClientOptions().setConnectTimeout(3000));
    dataImportKafkaHandler = new DataImportKafkaHandler(vertx, mockedStorage, client, new ProfileSnapshotCache(vertx, client, 3600), kafkaConfig, new MappingMetadataCache(vertx, client, 3600));
    EventManager.clearEventHandlers();
    EventManager.registerKafkaEventPublisher(kafkaConfig, vertx, 1);
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) MappingMetadataCache(org.folio.inventory.dataimport.cache.MappingMetadataCache) HttpClient(io.vertx.core.http.HttpClient) ProfileSnapshotCache(org.folio.inventory.dataimport.cache.ProfileSnapshotCache) HttpClientOptions(io.vertx.core.http.HttpClientOptions) KafkaConfig(org.folio.kafka.KafkaConfig) Before(org.junit.Before)

Example 7 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-inventory by folio-org.

the class MappingMetadataCacheTest method shouldReturnEmptyOptionalWhenGetNotFoundOnSnapshotLoading.

@Test
public void shouldReturnEmptyOptionalWhenGetNotFoundOnSnapshotLoading(TestContext context) {
    Async async = context.async();
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.notFound()));
    Future<Optional<MappingMetadataDto>> optionalFuture = mappingMetadataCache.get(mappingMetadata.getJobExecutionId(), this.context);
    optionalFuture.onComplete(ar -> {
        context.assertTrue(ar.succeeded());
        context.assertTrue(ar.result().isEmpty());
        async.complete();
    });
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Optional(java.util.Optional) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 8 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project mod-inventory by folio-org.

the class MappingMetadataCacheTest method shouldReturnFailedFutureWhenGetServerErrorOnSnapshotLoading.

@Test
public void shouldReturnFailedFutureWhenGetServerErrorOnSnapshotLoading(TestContext context) {
    Async async = context.async();
    WireMock.stubFor(get(new UrlPathPattern(new RegexPattern(MAPPING_METADATA_URL + "/.*"), true)).willReturn(WireMock.serverError()));
    Future<Optional<MappingMetadataDto>> optionalFuture = mappingMetadataCache.get(mappingMetadata.getJobExecutionId(), this.context);
    optionalFuture.onComplete(ar -> {
        context.assertTrue(ar.failed());
        async.complete();
    });
}
Also used : UrlPathPattern(com.github.tomakehurst.wiremock.matching.UrlPathPattern) Optional(java.util.Optional) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 9 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.

the class NeoTokenTest method getUnclaimedGas.

@Test
public void getUnclaimedGas() throws IOException {
    String responseBody = loadFile("/responses/invokefunction_unclaimedgas.json");
    WireMock.stubFor(post(urlEqualTo("/")).withRequestBody(new RegexPattern("" + ".*\"method\":\"invokefunction\"" + ".*\"params\":" + ".*\"" + NEOTOKEN_SCRIPTHASH + "\"" + // function
    ".*\"unclaimedGas\"" + ".*\"f68f181731a47036a99f04dad90043a744edec0f\"" + // script hash
    ".*100.*")).willReturn(aResponse().withStatus(200).withBody(responseBody)));
    BigInteger result = new NeoToken(neow).unclaimedGas(Hash160.fromAddress("NMNB9beANndYi5bd8Cd3U35EMvzmWMDSy9"), 100);
    assertThat(result, is(new BigInteger("60000000000")));
    result = new NeoToken(neow).unclaimedGas(Account.fromAddress("NMNB9beANndYi5bd8Cd3U35EMvzmWMDSy9"), 100);
    assertThat(result, is(new BigInteger("60000000000")));
}
Also used : RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 10 with RegexPattern

use of com.github.tomakehurst.wiremock.matching.RegexPattern in project neow3j by neow3j.

the class NeoTokenTest method getNextBlockValidators.

@Test
public void getNextBlockValidators() throws IOException {
    String responseBody = loadFile("/responses/invokefunction_getnextblockvalidators.json");
    WireMock.stubFor(post(urlEqualTo("/")).withRequestBody(new RegexPattern("" + ".*\"method\":\"invokefunction\"" + ".*\"params\":" + ".*\"" + NEOTOKEN_SCRIPTHASH + "\"" + // function
    ".*\"getNextBlockValidators\".*")).willReturn(aResponse().withStatus(200).withBody(responseBody)));
    List<ECPublicKey> result = new NeoToken(neow).getNextBlockValidators();
    String expKeyHex = "02163946a133e3d2e0d987fb90cb01b060ed1780f1718e2da28edf13b965fd2b60";
    ECPublicKey expKey = new ECPublicKey(hexStringToByteArray(expKeyHex));
    assertThat(result, contains(expKey));
}
Also used : ECPublicKey(io.neow3j.crypto.ECKeyPair.ECPublicKey) RegexPattern(com.github.tomakehurst.wiremock.matching.RegexPattern) Test(org.junit.Test)

Aggregations

RegexPattern (com.github.tomakehurst.wiremock.matching.RegexPattern)148 Test (org.junit.Test)119 UrlPathPattern (com.github.tomakehurst.wiremock.matching.UrlPathPattern)79 Matchers.containsString (org.hamcrest.Matchers.containsString)46 Async (io.vertx.ext.unit.Async)33 JsonapiError (org.folio.rest.jaxrs.model.JsonapiError)31 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)26 Before (org.junit.Before)22 JsonObject (io.vertx.core.json.JsonObject)18 MappingParameters (org.folio.processing.mapping.defaultmapper.processor.parameters.MappingParameters)16 HashMap (java.util.HashMap)13 EqualToPattern (com.github.tomakehurst.wiremock.matching.EqualToPattern)12 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 TestContext (io.vertx.ext.unit.TestContext)10 WireMockConfiguration (com.github.tomakehurst.wiremock.core.WireMockConfiguration)9 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)9 IOException (java.io.IOException)9 ParsedRecord (org.folio.rest.jaxrs.model.ParsedRecord)9 RunWith (org.junit.runner.RunWith)9