Search in sources :

Example 6 with DefaultCollectionDataType

use of org.mule.runtime.core.internal.metadata.DefaultCollectionDataType in project mule by mulesoft.

the class DataTypeBuilderTestCase method buildCollection.

@Test
public void buildCollection() {
    final DataType dataType = DataType.fromType(Set.class);
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(Set.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(OBJECT));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Example 7 with DefaultCollectionDataType

use of org.mule.runtime.core.internal.metadata.DefaultCollectionDataType in project mule by mulesoft.

the class DataTypeBuilderTestCase method templateTypedCollection.

@Test
public void templateTypedCollection() {
    final DataType template = DataType.builder().collectionType(List.class).itemType(String.class).itemMediaType("application/json;charset=UTF-8").mediaType("text/plain;charset=ASCII").build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(List.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(assignableTo(STRING)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getPrimaryType(), is("application"));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getSubType(), is("json"));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType().getMediaType().getCharset().get(), is(UTF_8));
    assertThat(dataType.getMediaType().getPrimaryType(), is("text"));
    assertThat(dataType.getMediaType().getSubType(), is("plain"));
    assertThat(dataType.getMediaType().getCharset().get(), is(US_ASCII));
}
Also used : DefaultFunctionDataType(org.mule.runtime.core.internal.metadata.DefaultFunctionDataType) SimpleDataType(org.mule.runtime.core.internal.metadata.SimpleDataType) FunctionDataType(org.mule.runtime.api.metadata.FunctionDataType) DefaultMapDataType(org.mule.runtime.core.internal.metadata.DefaultMapDataType) DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Example 8 with DefaultCollectionDataType

use of org.mule.runtime.core.internal.metadata.DefaultCollectionDataType in project mule by mulesoft.

the class DefaultMuleMessageBuilderTestCase method createNewMessageCollectionViaMessageInterface.

@Test
public void createNewMessageCollectionViaMessageInterface() {
    List<String> htmlStringList = new ArrayList<>();
    htmlStringList.add("HTML1");
    htmlStringList.add("HTML2");
    htmlStringList.add("HTML3");
    Message message = InternalMessage.builder().collectionValue(htmlStringList, String.class).itemMediaType(HTML).build();
    assertThat(message.getPayload().getValue(), is(htmlStringList));
    assertThat(message.getPayload().getDataType().getType(), equalTo(ArrayList.class));
    assertThat(message.getPayload().getDataType().getMediaType(), is(ANY));
    assertThat(message.getPayload().getDataType(), instanceOf(DefaultCollectionDataType.class));
    assertThat(((DefaultCollectionDataType) message.getPayload().getDataType()).getItemDataType().getMediaType(), equalTo(HTML));
}
Also used : Message(org.mule.runtime.api.message.Message) ArrayList(java.util.ArrayList) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 DefaultCollectionDataType (org.mule.runtime.core.internal.metadata.DefaultCollectionDataType)8 DataType (org.mule.runtime.api.metadata.DataType)6 FunctionDataType (org.mule.runtime.api.metadata.FunctionDataType)5 DefaultFunctionDataType (org.mule.runtime.core.internal.metadata.DefaultFunctionDataType)5 DefaultMapDataType (org.mule.runtime.core.internal.metadata.DefaultMapDataType)5 SimpleDataType (org.mule.runtime.core.internal.metadata.SimpleDataType)5 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Message (org.mule.runtime.api.message.Message)2 Collections.singletonList (java.util.Collections.singletonList)1 LinkedList (java.util.LinkedList)1 SmallTest (org.mule.tck.size.SmallTest)1