Search in sources :

Example 1 with MapDataType

use of org.mule.runtime.api.metadata.MapDataType in project mule by mulesoft.

the class IntrospectionUtilsTestCase method getDataTypeFromMap.

@Test
public void getDataTypeFromMap() {
    Class<Date> dateClass = Date.class;
    Class<Map> mapClass = Map.class;
    ObjectTypeBuilder objectTypeBuilder = BaseTypeBuilder.create(JAVA).objectType().with(new ClassInformationAnnotation(Map.class));
    objectTypeBuilder.openWith().objectType().id(dateClass.getName());
    MapDataType dataType = (MapDataType) toDataType(objectTypeBuilder.build());
    assertThat(dataType.getType(), is(equalTo(mapClass)));
    assertThat(dataType.getKeyDataType().getType(), is(equalTo(String.class)));
    assertThat(dataType.getValueDataType().getType(), is(equalTo(dateClass)));
}
Also used : MapDataType(org.mule.runtime.api.metadata.MapDataType) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Date(java.util.Date) ObjectTypeBuilder(org.mule.metadata.api.builder.ObjectTypeBuilder) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MapDataType

use of org.mule.runtime.api.metadata.MapDataType in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsResultMapWithCorrectDataType.

@Test
public void operationReturnsResultMapWithCorrectDataType() throws Exception {
    Object payload = new HashMap<>();
    setUpOperationReturning(Result.builder().output(payload).build(), new TypeToken<Map<String, String>>() {
    }.getType());
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    DataType dataType = message.getPayload().getDataType();
    assertThat(dataType, instanceOf(MapDataType.class));
    assertThat(((MapDataType) dataType).getKeyDataType(), like(String.class, ANY.withCharset(null)));
    assertThat(((MapDataType) dataType).getValueDataType(), like(String.class, ANY));
}
Also used : Message(org.mule.runtime.api.message.Message) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) MapDataType(org.mule.runtime.api.metadata.MapDataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) MapDataType(org.mule.runtime.api.metadata.MapDataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MapDataType

use of org.mule.runtime.api.metadata.MapDataType in project mule by mulesoft.

the class OperationMessageProcessorTestCase method operationReturnsMapWithCorrectDataType.

@Test
public void operationReturnsMapWithCorrectDataType() throws Exception {
    Object payload = new HashMap<>();
    setUpOperationReturning(payload, new TypeToken<Map<String, String>>() {
    }.getType());
    Message message = messageProcessor.process(event).getMessage();
    assertThat(message, is(notNullValue()));
    assertThat(message.getPayload().getValue(), is(sameInstance(payload)));
    DataType dataType = message.getPayload().getDataType();
    assertThat(dataType, instanceOf(MapDataType.class));
    assertThat(((MapDataType) dataType).getKeyDataType(), like(String.class, ANY.withCharset(null)));
    assertThat(((MapDataType) dataType).getValueDataType(), like(String.class, ANY));
}
Also used : Message(org.mule.runtime.api.message.Message) HashMap(java.util.HashMap) TypeToken(com.google.common.reflect.TypeToken) MapDataType(org.mule.runtime.api.metadata.MapDataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) MapDataType(org.mule.runtime.api.metadata.MapDataType) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 Test (org.junit.Test)3 MapDataType (org.mule.runtime.api.metadata.MapDataType)3 SmallTest (org.mule.tck.size.SmallTest)3 TypeToken (com.google.common.reflect.TypeToken)2 Message (org.mule.runtime.api.message.Message)2 CollectionDataType (org.mule.runtime.api.metadata.CollectionDataType)2 DataType (org.mule.runtime.api.metadata.DataType)2 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ObjectTypeBuilder (org.mule.metadata.api.builder.ObjectTypeBuilder)1 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)1