Search in sources :

Example 6 with PetStoreClient

use of org.mule.test.petstore.extension.PetStoreClient in project mule by mulesoft.

the class PetStoreCachedConnectionWithDynamicParameterTestCase method getDynamicConnectionParametersOnCachedConnection.

@Test
public void getDynamicConnectionParametersOnCachedConnection() throws Exception {
    PetStoreClient client = (PetStoreClient) flowRunner(FLOW_NAME).withVariable(USERNAME, "john").withVariable(PASSWORD, "doe").withVariable(DATE, parseDateTime("2008-09-15T15:53:23+05:00").getTime()).run().getMessage().getPayload().getValue();
    assertThat(client.getUsername(), is("john"));
    assertThat(client.getPassword(), is("doe"));
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(client.getOpeningDate());
    assertEquals(calendar.get(Calendar.YEAR), 2008);
    assertEquals(calendar.get(Calendar.MONTH) + 1, 9);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 15);
    client = (PetStoreClient) flowRunner(FLOW_NAME).withVariable(USERNAME, "john").withVariable(PASSWORD, "doe").withVariable(DATE, parseDateTime("2017-02-10").getTime()).run().getMessage().getPayload().getValue();
    assertThat(client.getUsername(), is("john"));
    assertThat(client.getPassword(), is("doe"));
    calendar.setTime(client.getOpeningDate());
    assertEquals(calendar.get(Calendar.YEAR), 2017);
    assertEquals(calendar.get(Calendar.MONTH) + 1, 2);
    assertEquals(calendar.get(Calendar.DAY_OF_MONTH), 10);
}
Also used : PetStoreClient(org.mule.test.petstore.extension.PetStoreClient) Calendar(java.util.Calendar) Test(org.junit.Test)

Example 7 with PetStoreClient

use of org.mule.test.petstore.extension.PetStoreClient in project mule by mulesoft.

the class PetStoreTlsConnectionTestCase method tls.

@Test
public void tls() throws Exception {
    PetStoreClient client = (PetStoreClient) runFlow("getClient").getMessage().getPayload().getValue();
    assertThat(client.getTlsContext(), is(notNullValue()));
}
Also used : PetStoreClient(org.mule.test.petstore.extension.PetStoreClient) Test(org.junit.Test)

Example 8 with PetStoreClient

use of org.mule.test.petstore.extension.PetStoreClient in project mule by mulesoft.

the class PetStoreConnectionPoolingTestCase method exhaustion.

@Test
public void exhaustion() throws Exception {
    if (NO_POOLING.equals(name)) {
        // test does not apply
        return;
    }
    executorService = Executors.newFixedThreadPool(poolSize);
    List<Future<PetStoreClient>> clients = new ArrayList<>(poolSize);
    for (int i = 0; i < poolSize; i++) {
        clients.add(getClientOnLatch());
    }
    testLatch.await();
    try {
        getClient();
        fail("was expecting pool to be exhausted when using config: " + name);
    } catch (Exception e) {
        assertThat(e.getCause(), is(instanceOf(ConnectionException.class)));
    }
    connectionLatch.release();
    for (Future<PetStoreClient> future : clients) {
        PollingProber prober = new PollingProber(1000, 100);
        prober.check(new JUnitProbe() {

            @Override
            protected boolean test() throws Exception {
                PetStoreClient client = future.get(100, MILLISECONDS);
                assertValidClient(client);
                return true;
            }

            @Override
            public String describeFailure() {
                return "Could not obtain valid client";
            }
        });
    }
    // now test that the pool is usable again
    assertValidClient(getClient());
}
Also used : JUnitProbe(org.mule.tck.probe.JUnitProbe) PetStoreClient(org.mule.test.petstore.extension.PetStoreClient) PollingProber(org.mule.tck.probe.PollingProber) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) Test(org.junit.Test)

Aggregations

PetStoreClient (org.mule.test.petstore.extension.PetStoreClient)8 Test (org.junit.Test)7 Calendar (java.util.Calendar)2 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Future (java.util.concurrent.Future)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 JUnitProbe (org.mule.tck.probe.JUnitProbe)1 PollingProber (org.mule.tck.probe.PollingProber)1