Search in sources :

Example 66 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method parseLogStream.

@Test
@Description("Verifies that streams are logged in DW but not in MVEL.")
public void parseLogStream() throws MuleException {
    ByteArrayInputStream stream = new ByteArrayInputStream("hello".getBytes());
    CoreEvent event = getEventBuilder().message(Message.of(stream)).build();
    assertThat(expressionManager.parseLogTemplate("this is #[payload]", event, TEST_CONNECTOR_LOCATION, NULL_BINDING_CONTEXT), is("this is hello"));
    assertThat(expressionManager.parseLogTemplate("this is #[mel:payload]", event, TEST_CONNECTOR_LOCATION, NULL_BINDING_CONTEXT), both(startsWith("this is ")).and(containsString(stream.getClass().getSimpleName())));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 67 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method parse.

@Test
@Description("Verifies that parsing works for plain String scenarios.")
public void parse() throws MuleException {
    String expression = "this is a test";
    assertThat(expressionManager.parse(expression, testEvent(), TEST_CONNECTOR_LOCATION), is(expression));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 68 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method transformationNotNeeded.

@Test
@Description("Verifies that a simple transformation works even when it's not required.")
public void transformationNotNeeded() throws MuleException {
    String expression = "payload";
    TypedValue result = expressionManager.evaluate(expression, STRING, builder().build(), testEvent());
    assertThat(result.getValue(), is(TEST_PAYLOAD));
    assertThat(result.getDataType(), is(STRING));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 69 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method transformation.

@Test
@Description("Verifies that a simple transformation works.")
public void transformation() throws MuleException {
    String expression = "payload";
    TypedValue result = expressionManager.evaluate(expression, BYTE_ARRAY, builder().build(), testEvent());
    assertThat(result.getValue(), is(TEST_PAYLOAD.getBytes()));
    assertThat(result.getDataType(), is(BYTE_ARRAY));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Example 70 with Description

use of io.qameta.allure.Description in project mule by mulesoft.

the class DefaultExpressionManagerTestCase method globals.

@Test
@Description("Verifies that global bindings can be added.")
public void globals() {
    DataType integerType = fromType(Integer.class);
    ExpressionFunction multiply = new ExpressionFunction() {

        @Override
        public Object call(Object[] objects, BindingContext bindingContext) {
            return ((Integer) objects[0]) * ((Integer) objects[1]);
        }

        @Override
        public Optional<DataType> returnType() {
            return of(integerType);
        }

        @Override
        public List<FunctionParameter> parameters() {
            return asList(new FunctionParameter("x", integerType), new FunctionParameter("y", integerType));
        }
    };
    BindingContext globalContext = builder().addBinding("aNum", new TypedValue<>(4, fromType(Integer.class))).addBinding("times", new TypedValue<>(multiply, fromFunction(multiply))).build();
    expressionManager.addGlobalBindings(globalContext);
    TypedValue result = expressionManager.evaluate("aNum times 5");
    assertThat(result.getValue(), is(20));
    expressionManager.addGlobalBindings(builder().addBinding("otherNum", new TypedValue(3, integerType)).build());
    result = expressionManager.evaluate("(times(7, 3) + otherNum) / aNum");
    assertThat(result.getValue(), is(6));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) ExpressionFunction(org.mule.runtime.api.el.ExpressionFunction) BindingContext(org.mule.runtime.api.el.BindingContext) FunctionParameter(org.mule.runtime.api.metadata.FunctionParameter) TypedValue(org.mule.runtime.api.metadata.TypedValue) Description(io.qameta.allure.Description) Test(org.junit.Test)

Aggregations

Description (io.qameta.allure.Description)117 Test (org.junit.Test)111 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)41 Matchers.containsString (org.hamcrest.Matchers.containsString)15 Message (org.mule.runtime.api.message.Message)13 TypedValue (org.mule.runtime.api.metadata.TypedValue)13 RoutingPair (org.mule.runtime.core.internal.routing.ForkJoinStrategy.RoutingPair)12 MessageProcessorChain (org.mule.runtime.core.privileged.processor.chain.MessageProcessorChain)12 OperationParameters (org.mule.runtime.extension.api.client.OperationParameters)12 Matchers.anyString (org.mockito.Matchers.anyString)8 List (java.util.List)7 MavenConfiguration (org.mule.maven.client.api.model.MavenConfiguration)7 Processor (org.mule.runtime.core.api.processor.Processor)7 RemoteRepository (org.mule.maven.client.api.model.RemoteRepository)6 Event (org.mule.runtime.api.event.Event)6 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)6 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)6 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)6 SmallTest (org.mule.tck.size.SmallTest)6 TestTransaction (org.mule.tck.testmodels.mule.TestTransaction)6