Search in sources :

Example 11 with HeisenbergExtension

use of org.mule.test.heisenberg.extension.HeisenbergExtension in project mule by mulesoft.

the class SingleConfigParserTestCase method initializedOptionalValueWithoutDefaultValue.

@Test
public void initializedOptionalValueWithoutDefaultValue() throws Exception {
    CoreEvent event = null;
    try {
        event = getHeisenbergEvent();
        HeisenbergExtension config = lookupHeisenberg(HEISENBERG_EXPRESSION_BYREF, event);
        assertThat(config.getWeapon(), is(not(nullValue())));
        assertThat(config.getWeapon(), is(instanceOf(Ricin.class)));
    } finally {
        if (event != null) {
            ((BaseEventContext) event.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 12 with HeisenbergExtension

use of org.mule.test.heisenberg.extension.HeisenbergExtension in project mule by mulesoft.

the class SingleConfigParserTestCase method configWithExpressionFunctionStillDynamic.

@Test
public void configWithExpressionFunctionStillDynamic() throws Exception {
    CoreEvent event = null;
    CoreEvent anotherEvent = null;
    try {
        event = getHeisenbergEvent();
        anotherEvent = CoreEvent.builder(getHeisenbergEvent()).addVariable("age", 40).build();
        HeisenbergExtension config = lookupHeisenberg(HEISENBERG_EXPRESSION, event);
        HeisenbergExtension anotherConfig = lookupHeisenberg(HEISENBERG_EXPRESSION, anotherEvent);
        assertThat(config, is(not(sameInstance(anotherConfig))));
    } finally {
        if (event != null) {
            ((BaseEventContext) event.getContext()).success();
        }
        if (anotherEvent != null) {
            ((BaseEventContext) anotherEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 13 with HeisenbergExtension

use of org.mule.test.heisenberg.extension.HeisenbergExtension in project mule by mulesoft.

the class SubTypesMappingParserTestCase method subtypeContributionToOtherExtension.

@Test
public void subtypeContributionToOtherExtension() throws Exception {
    HeisenbergExtension heisenberg = lookupHeisenberg("heisenberg");
    assertThat(heisenberg, is(notNullValue()));
    List<? extends Weapon> wildCardWeapons = heisenberg.getWildCardWeapons();
    assertThat(wildCardWeapons, is(notNullValue()));
    assertThat(wildCardWeapons, hasSize(2));
    assertThat(wildCardWeapons.get(0), instanceOf(Ricin.class));
    assertThat(((Ricin) wildCardWeapons.get(0)).getMicrogramsPerKilo(), is(10L));
    assertThat(((Ricin) wildCardWeapons.get(0)).getDestination(), is(notNullValue()));
    assertThat(((Ricin) wildCardWeapons.get(0)).getDestination().getVictim(), is("Krazy-8"));
    assertThat(wildCardWeapons.get(1), instanceOf(Revolver.class));
    assertThat(((Revolver) wildCardWeapons.get(1)).getBullets(), is(3));
}
Also used : Revolver(org.mule.test.subtypes.extension.Revolver) Ricin(org.mule.test.heisenberg.extension.model.Ricin) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 14 with HeisenbergExtension

use of org.mule.test.heisenberg.extension.HeisenbergExtension in project mule by mulesoft.

the class DynamicConfigurationProviderTestCase method resolveProviderParamsDifferentInstance.

@Test
public void resolveProviderParamsDifferentInstance() throws Exception {
    HeisenbergExtension config = (HeisenbergExtension) provider.get(event).getValue();
    mockConfigurationInstance(configurationModel, MODULE_CLASS.newInstance());
    ResolverSet providerResolverSet = mock(ResolverSet.class);
    when(connectionProviderResolver.getResolverSet()).thenReturn(of(providerResolverSet));
    when(connectionProviderResolver.getObjectBuilder()).thenReturn(empty());
    when(providerResolverSet.resolve(from(event))).thenReturn(mock(ResolverSetResult.class));
    assertThat(provider.get(event).getValue(), is(not(sameInstance(config))));
    verify(resolverSet, times(2)).resolve(from(event));
    verify(providerResolverSet, times(1)).resolve(from(event));
    verify(connectionProviderResolver, times(2)).resolve(from(event));
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 15 with HeisenbergExtension

use of org.mule.test.heisenberg.extension.HeisenbergExtension in project mule by mulesoft.

the class DynamicConfigurationProviderTestCase method resolveCached.

@Test
public void resolveCached() throws Exception {
    final int count = 10;
    HeisenbergExtension config = (HeisenbergExtension) provider.get(event).getValue();
    for (int i = 1; i < count; i++) {
        assertThat(provider.get(event).getValue(), is(sameInstance(config)));
    }
    verify(resolverSet, times(count)).resolve(from(event));
}
Also used : HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)28 Test (org.junit.Test)24 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)10 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 SmallTest (org.mule.tck.size.SmallTest)6 List (java.util.List)3 ResolverSetResult (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult)3 ArrayList (java.util.ArrayList)2 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)2 ImmutableList (com.google.common.collect.ImmutableList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 Optional.empty (java.util.Optional.empty)1 Optional.of (java.util.Optional.of)1 MINUTES (java.util.concurrent.TimeUnit.MINUTES)1 CoreMatchers.is (org.hamcrest.CoreMatchers.is)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 CoreMatchers.sameInstance (org.hamcrest.CoreMatchers.sameInstance)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 After (org.junit.After)1