Search in sources :

Example 21 with HeisenbergExtension

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

the class StatefulOperationTestCase method assertRemainingMoney.

private void assertRemainingMoney(String configName, String name, long expectedAmount) throws Exception {
    CoreEvent event = CoreEvent.builder(testEvent()).message(of("")).addVariable("myName", name).build();
    HeisenbergExtension heisenbergExtension = ExtensionsTestUtils.getConfigurationFromRegistry(configName, event, muleContext);
    assertThat(heisenbergExtension.getMoney(), equalTo(BigDecimal.valueOf(expectedAmount)));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension)

Example 22 with HeisenbergExtension

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

the class ParameterizedConfigParserTestCase method config.

@Test
public void config() throws Exception {
    HeisenbergExtension heisenberg = lookupHeisenberg(testConfig);
    assertHeisenbergConfig(heisenberg);
}
Also used : HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 23 with HeisenbergExtension

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

the class ParameterizedConfigParserTestCase method lifecycle.

@Test
public void lifecycle() throws Exception {
    HeisenbergExtension heisenberg = lookupHeisenberg(testConfig);
    assertThat(heisenberg.getInitialise(), is(1));
    assertThat(heisenberg.getStart(), is(1));
    muleContext.stop();
    muleContext.dispose();
    assertThat(heisenberg.getStop(), is(1));
    assertThat(heisenberg.getDispose(), is(1));
}
Also used : HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) Test(org.junit.Test)

Example 24 with HeisenbergExtension

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

the class SingleConfigParserTestCase method configWithExpressionFunctionIsSameInstanceForDifferentEvents.

@Test
public void configWithExpressionFunctionIsSameInstanceForDifferentEvents() throws Exception {
    CoreEvent event = null;
    try {
        event = getHeisenbergEvent();
        CoreEvent anotherEvent = testEvent();
        HeisenbergExtension config = lookupHeisenberg(HEISENBERG_BYNAME, event);
        HeisenbergExtension anotherConfig = lookupHeisenberg(HEISENBERG_BYNAME, anotherEvent);
        assertThat(config, is(sameInstance(anotherConfig)));
    } 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 25 with HeisenbergExtension

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

the class DynamicConfigurationProviderTestCase method getExpired.

@Test
public void getExpired() throws Exception {
    HeisenbergExtension instance1 = (HeisenbergExtension) provider.get(event).getValue();
    HeisenbergExtension instance2 = makeAlternateInstance();
    DynamicConfigurationProvider provider = (DynamicConfigurationProvider) this.provider;
    timeSupplier.move(1, MINUTES);
    List<ConfigurationInstance> expired = provider.getExpired();
    assertThat(expired.isEmpty(), is(true));
    timeSupplier.move(10, MINUTES);
    expired = provider.getExpired();
    assertThat(expired.isEmpty(), is(false));
    List<Object> configs = expired.stream().map(config -> config.getValue()).collect(toImmutableList());
    assertThat(configs, containsInAnyOrder(instance1, instance2));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) ExtensionsTestUtils.mockInterceptors(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockInterceptors) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Optional.of(java.util.Optional.of) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) ExpirationPolicy(org.mule.runtime.extension.api.runtime.ExpirationPolicy) SmallTest(org.mule.tck.size.SmallTest) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Pair(org.mule.runtime.api.util.Pair) RETURNS_DEEP_STUBS(org.mockito.Answers.RETURNS_DEEP_STUBS) Collectors.toImmutableList(org.mule.runtime.api.util.collection.Collectors.toImmutableList) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) Matchers.any(org.mockito.Matchers.any) Lifecycle(org.mule.runtime.api.lifecycle.Lifecycle) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Mockito.withSettings(org.mockito.Mockito.withSettings) Mockito.mock(org.mockito.Mockito.mock) ValueResolvingContext.from(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolvingContext.from) Optional.empty(java.util.Optional.empty) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) MINUTES(java.util.concurrent.TimeUnit.MINUTES) HashMap(java.util.HashMap) ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImmutableList(com.google.common.collect.ImmutableList) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException.none(org.junit.rules.ExpectedException.none) ExtensionModelTestUtils.visitableMock(org.mule.runtime.api.util.ExtensionModelTestUtils.visitableMock) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Before(org.junit.Before) ThrowableMessageMatcher.hasMessage(org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) ImmutableExpirationPolicy(org.mule.runtime.core.internal.config.ImmutableExpirationPolicy) ConnectionProviderResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) ExtensionsTestUtils.mockClassLoaderModelProperty(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockClassLoaderModelProperty) ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance) ExtensionsTestUtils.mockConfigurationInstance(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockConfigurationInstance) 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