Search in sources :

Example 11 with Banana

use of org.mule.tck.testmodels.fruit.Banana in project mule by mulesoft.

the class CachedConnectionHandlerTestCase method getConnectionConcurrentlyAndConnectOnlyOnce.

@Test
public void getConnectionConcurrentlyAndConnectOnlyOnce() throws Exception {
    Banana mockConnection = mock(Banana.class);
    connectionProvider = mock(ConnectionProvider.class);
    before();
    Latch latch = new Latch();
    when(connectionProvider.connect()).thenAnswer(invocation -> {
        new Thread(() -> {
            try {
                latch.release();
                getConnection();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }).start();
        return mockConnection;
    });
    Banana connection = managedConnection.getConnection();
    assertThat(latch.await(5, TimeUnit.SECONDS), is(true));
    assertThat(connection, is(sameInstance(mockConnection)));
    verify(connectionProvider).connect();
}
Also used : Latch(org.mule.runtime.api.util.concurrent.Latch) Banana(org.mule.tck.testmodels.fruit.Banana) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 12 with Banana

use of org.mule.tck.testmodels.fruit.Banana in project mule by mulesoft.

the class FlowListenerOperationExecutionTestCase method listenSuccessfulFlow.

@Test
public void listenSuccessfulFlow() throws Exception {
    Message message = flowRunner("listenAndByteBanana").run().getMessage();
    assertThat(message.getPayload().getValue(), is(instanceOf(Banana.class)));
    final Banana banana = (Banana) message.getPayload().getValue();
    check(() -> {
        assertThat(banana.isPeeled(), is(true));
        assertThat(banana.isBitten(), is(true));
        assertThat(config.getBananasCount(), is(1));
        assertThat(config.getNonBananasCount(), is(0));
        assertThat(config.getExceptionCount(), is(0));
    });
}
Also used : Message(org.mule.runtime.api.message.Message) Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test)

Example 13 with Banana

use of org.mule.tck.testmodels.fruit.Banana in project mule by mulesoft.

the class ParameterDslFunctionalTestCase method eatPealed.

@Test
public void eatPealed() throws Exception {
    Banana banana = (Banana) flowRunner("eatPealedBanana").run().getMessage().getPayload().getValue();
    assertThat(banana.isBitten(), is(true));
}
Also used : Banana(org.mule.tck.testmodels.fruit.Banana) Test(org.junit.Test)

Example 14 with Banana

use of org.mule.tck.testmodels.fruit.Banana in project mule by mulesoft.

the class VeganBananaConnectionProvider method connect.

@Override
public Banana connect() throws ConnectionException {
    Banana banana = new Banana();
    banana.setOrigin(originCountry);
    return banana;
}
Also used : Banana(org.mule.tck.testmodels.fruit.Banana) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride)

Example 15 with Banana

use of org.mule.tck.testmodels.fruit.Banana in project mule by mulesoft.

the class FlowListenerBananaOperations method getLunch.

@OutputResolver(output = FruitMetadataResolver.class)
public Fruit getLunch(@Config BananaConfig config, FlowListener listener) {
    final Banana banana = new Banana();
    listener.onSuccess(message -> {
        if (message.getPayload().getValue() instanceof Banana) {
            config.onBanana();
        } else {
            config.onNotBanana();
        }
    });
    listener.onError(exception -> config.onException());
    listener.onComplete(() -> banana.peel());
    return banana;
}
Also used : Banana(org.mule.tck.testmodels.fruit.Banana) OutputResolver(org.mule.runtime.extension.api.annotation.metadata.OutputResolver)

Aggregations

Banana (org.mule.tck.testmodels.fruit.Banana)17 Test (org.junit.Test)13 Apple (org.mule.tck.testmodels.fruit.Apple)7 SmallTest (org.mule.tck.size.SmallTest)6 Orange (org.mule.tck.testmodels.fruit.Orange)5 FruitBowl (org.mule.tck.testmodels.fruit.FruitBowl)4 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)3 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)2 Fruit (org.mule.tck.testmodels.fruit.Fruit)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Before (org.junit.Before)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 Message (org.mule.runtime.api.message.Message)1 Latch (org.mule.runtime.api.util.concurrent.Latch)1 SimpleConfigurationBuilder (org.mule.runtime.core.api.config.builders.SimpleConfigurationBuilder)1 Transformer (org.mule.runtime.core.api.transformer.Transformer)1 TransformerException (org.mule.runtime.core.api.transformer.TransformerException)1 MuleContextWithRegistries (org.mule.runtime.core.internal.context.MuleContextWithRegistries)1