Search in sources :

Example 1 with DefaultCollectionDataType

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

the class DefaultMuleMessageBuilderTestCase method createNewMessageCollectionViaMessageInterfaceCopy.

@Test
public void createNewMessageCollectionViaMessageInterfaceCopy() {
    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();
    Message copy = InternalMessage.builder(message).build();
    assertThat(copy.getPayload().getValue(), is(htmlStringList));
    assertThat(copy.getPayload().getDataType().getType(), equalTo(ArrayList.class));
    assertThat(copy.getPayload().getDataType().getMediaType(), is(ANY));
    assertThat(copy.getPayload().getDataType(), instanceOf(DefaultCollectionDataType.class));
    assertThat(((DefaultCollectionDataType) copy.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)

Example 2 with DefaultCollectionDataType

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

the class DataTypeBuilderTestCase method templateCollection.

@Test
public void templateCollection() {
    final DataType template = DataType.builder().type(Set.class).mediaType("text/plain;charset=ASCII").build();
    final DataType dataType = DataType.builder(template).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(Set.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(OBJECT));
    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 3 with DefaultCollectionDataType

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

the class DataTypeBuilderTestCase method buildTypedCollectionFromImplementationClass.

@Test
public void buildTypedCollectionFromImplementationClass() {
    final DataType dataType = DataType.builder().collectionType(SpecificCollection.class).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(SpecificCollection.class)));
    assertThat(((DefaultCollectionDataType) dataType).getItemDataType(), is(STRING));
}
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 4 with DefaultCollectionDataType

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

the class DataTypeFactoryTestCase method createsDataTypeForNonCollection.

@Test
public void createsDataTypeForNonCollection() {
    final DataType dataType = DataType.builder().collectionType(List.class).itemType(type).itemMediaType(mimeType).build();
    assertThat(dataType.getType(), equalTo(List.class));
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    final DataType itemDataType = ((DefaultCollectionDataType) dataType).getItemDataType();
    assertThat(itemDataType.getType(), equalTo(type));
    assertThat(itemDataType.getMediaType().getPrimaryType(), is(mimeType.split("/")[0]));
    assertThat(itemDataType.getMediaType().getSubType(), is(mimeType.split("/")[1]));
}
Also used : DataType(org.mule.runtime.api.metadata.DataType) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) List(java.util.List) DefaultCollectionDataType(org.mule.runtime.core.internal.metadata.DefaultCollectionDataType) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 5 with DefaultCollectionDataType

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

the class DataTypeBuilderTestCase method buildTypedCollection.

@Test
public void buildTypedCollection() {
    final DataType dataType = DataType.builder().collectionType(List.class).itemType(String.class).itemMediaType(APPLICATION_JSON).build();
    assertThat(dataType, instanceOf(DefaultCollectionDataType.class));
    assertThat(dataType.getType(), is(equalTo(List.class)));
    DataType itemDataType = ((DefaultCollectionDataType) dataType).getItemDataType();
    assertThat(itemDataType.getType(), equalTo(String.class));
    assertThat(itemDataType.getMediaType(), is(APPLICATION_JSON));
}
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) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) 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