Search in sources :

Example 1 with ObjectTypeBuilder

use of org.mule.metadata.api.builder.ObjectTypeBuilder 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 ObjectTypeBuilder

use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.

the class NativeQueryOutputResolver method getOutputType.

@Override
public MetadataType getOutputType(MetadataContext context, String key) throws MetadataResolvingException, ConnectionException {
    if (!key.equals(NATIVE_QUERY)) {
        throw new IllegalArgumentException("Native Query Key was not the expected one");
    }
    final ObjectTypeBuilder objectType = context.getTypeBuilder().objectType();
    objectType.addField().key("id").value().numberType();
    return objectType.build();
}
Also used : ObjectTypeBuilder(org.mule.metadata.api.builder.ObjectTypeBuilder)

Example 3 with ObjectTypeBuilder

use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.

the class JsonInputStaticTypeResolver method getStaticMetadata.

@Override
public MetadataType getStaticMetadata() {
    ObjectTypeBuilder object = BaseTypeBuilder.create(MetadataFormat.JSON).objectType();
    object.id("json-object");
    object.addField().key("name").value().stringType();
    object.addField().key("last-name").value().stringType();
    return object.build();
}
Also used : ObjectTypeBuilder(org.mule.metadata.api.builder.ObjectTypeBuilder)

Example 4 with ObjectTypeBuilder

use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.

the class TestOutputAttributesResolverWithKeyResolver method getAttributesType.

@Override
public MetadataType getAttributesType(MetadataContext context, String key) throws MetadataResolvingException, ConnectionException {
    ObjectTypeBuilder builder = BaseTypeBuilder.create(JAVA).objectType();
    builder.openWith().stringType();
    return builder.build();
}
Also used : ObjectTypeBuilder(org.mule.metadata.api.builder.ObjectTypeBuilder)

Example 5 with ObjectTypeBuilder

use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.

the class TestMetadataResolverUtils method getMetadata.

public static MetadataType getMetadata(String key) throws MetadataResolvingException {
    final ObjectTypeBuilder objectBuilder = BaseTypeBuilder.create(JAVA).objectType();
    switch(key) {
        case MetadataConnection.CAR:
            objectBuilder.addField().key(TIRES).value().numberType();
            objectBuilder.addField().key(BRAND).value().stringType();
            break;
        case MetadataConnection.HOUSE:
            objectBuilder.addField().key(DIRECTION).value().stringType();
            objectBuilder.addField().key(SIZE).value().numberType();
            break;
        case MetadataConnection.PERSON:
            objectBuilder.addField().key(NAME).value().stringType();
            objectBuilder.addField().key(AGE).value().numberType();
            break;
        case MetadataConnection.NULL:
            return BaseTypeBuilder.create(JAVA).nullType().build();
        case MetadataConnection.VOID:
            return BaseTypeBuilder.create(JAVA).voidType().build();
        default:
            throw new MetadataResolvingException("Unknown key " + key, INVALID_METADATA_KEY);
    }
    return objectBuilder.build();
}
Also used : MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) ObjectTypeBuilder(org.mule.metadata.api.builder.ObjectTypeBuilder)

Aggregations

ObjectTypeBuilder (org.mule.metadata.api.builder.ObjectTypeBuilder)9 Test (org.junit.Test)2 MapDataType (org.mule.runtime.api.metadata.MapDataType)2 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)2 SmallTest (org.mule.tck.size.SmallTest)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 BaseTypeBuilder (org.mule.metadata.api.builder.BaseTypeBuilder)1 ObjectFieldTypeBuilder (org.mule.metadata.api.builder.ObjectFieldTypeBuilder)1 MetadataFormat (org.mule.metadata.api.model.MetadataFormat)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)1 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1