use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method before.
@Before
public void before() {
initMocks(this);
initializeExtensionMock(extension);
when(configuration.getName()).thenReturn(CONFIGURATION_NAME);
when(configuration.getParameterGroupModels()).thenReturn(asList(parameterGroupModel));
when(configuration.getOperationModels()).thenReturn(asList(operation));
when(configuration.getSourceModels()).thenReturn(asList(source));
when(configuration.getConnectionProviders()).thenReturn(asList(connectionProvider));
when(behaviourParameter.getName()).thenReturn(BEHAVIOUR_NAME);
when(behaviourParameter.getExpressionSupport()).thenReturn(ExpressionSupport.NOT_SUPPORTED);
when(behaviourParameter.getModelProperty(any())).thenReturn(empty());
when(behaviourParameter.getDslConfiguration()).thenReturn(ParameterDslConfiguration.getDefaultInstance());
when(behaviourParameter.getLayoutModel()).thenReturn(empty());
when(behaviourParameter.getRole()).thenReturn(BEHAVIOUR);
when(behaviourParameter.getType()).thenReturn(TYPE_LOADER.load(String.class));
when(listParameter.getName()).thenReturn(LIST_NAME);
when(listParameter.getExpressionSupport()).thenReturn(ExpressionSupport.NOT_SUPPORTED);
when(listParameter.getModelProperty(any())).thenReturn(empty());
when(listParameter.getDslConfiguration()).thenReturn(ParameterDslConfiguration.getDefaultInstance());
when(listParameter.getLayoutModel()).thenReturn(empty());
when(listParameter.getRole()).thenReturn(BEHAVIOUR);
when(listParameter.getType()).thenReturn(TYPE_BUILDER.arrayType().of(TYPE_LOADER.load(String.class)).build());
when(contentParameter.getName()).thenReturn(CONTENT_NAME);
when(contentParameter.getExpressionSupport()).thenReturn(ExpressionSupport.SUPPORTED);
when(contentParameter.getModelProperty(any())).thenReturn(empty());
when(contentParameter.getDslConfiguration()).thenReturn(ParameterDslConfiguration.getDefaultInstance());
when(contentParameter.getLayoutModel()).thenReturn(empty());
when(contentParameter.getRole()).thenReturn(CONTENT);
ObjectTypeBuilder type = TYPE_BUILDER.objectType();
type.addField().key("field").value(TYPE_LOADER.load(String.class)).build();
when(contentParameter.getType()).thenReturn(type.build());
List<ParameterModel> parameterModels = asList(contentParameter, behaviourParameter, listParameter);
when(parameterGroupModel.getName()).thenReturn(DEFAULT_GROUP_NAME);
when(parameterGroupModel.isShowInDsl()).thenReturn(false);
when(parameterGroupModel.getParameterModels()).thenReturn(parameterModels);
when(parameterGroupModel.getParameter(anyString())).thenReturn(empty());
when(source.getName()).thenReturn(SOURCE_NAME);
when(source.getParameterGroupModels()).thenReturn(asList(parameterGroupModel));
when(source.getSuccessCallback()).thenReturn(empty());
when(source.getErrorCallback()).thenReturn(empty());
when(operation.getName()).thenReturn(OPERATION_NAME);
when(operation.getParameterGroupModels()).thenReturn(asList(parameterGroupModel));
visitableMock(operation, source);
when(connectionProvider.getName()).thenReturn(CONNECTION_PROVIDER_NAME);
when(connectionProvider.getParameterGroupModels()).thenReturn(asList(parameterGroupModel));
when(typeCatalog.getSubTypes(any())).thenReturn(emptySet());
when(typeCatalog.getSuperTypes(any())).thenReturn(emptySet());
when(typeCatalog.getAllBaseTypes()).thenReturn(emptySet());
when(typeCatalog.getAllSubTypes()).thenReturn(emptySet());
when(typeCatalog.getTypes()).thenReturn(emptySet());
complexType = (ObjectType) TYPE_LOADER.load(ComplexTypePojo.class);
when(typeCatalog.getType(any())).thenReturn(Optional.of(complexType));
when(typeCatalog.containsBaseType(any())).thenReturn(false);
when(dslContext.getExtension(any())).thenReturn(Optional.of(extension));
when(dslContext.getExtensions()).thenReturn(singleton(extension));
when(dslContext.getTypeCatalog()).thenReturn(typeCatalog);
Stream.of(configuration, operation, connectionProvider, source).forEach(model -> when(model.getAllParameterModels()).thenReturn(parameterModels));
}
use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getDataTypeFromObject.
@Test
public void getDataTypeFromObject() {
Class<Object> objectClass = Object.class;
ObjectTypeBuilder objectTypeBuilder = BaseTypeBuilder.create(JAVA).objectType().id(objectClass.getName());
DataType dataType = toDataType(objectTypeBuilder.build());
assertThat(dataType.getType(), is(equalTo(objectClass)));
}
use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.
the class DsqlQueryMetadataResolver method getOutputType.
/**
* Automatically resolves the output metadata for the {@link DsqlQuery}.
* <p>
* The base entity is resolved using the component {@link QueryEntityResolver} and assuming the key of the entity is the DSQL
* {@link DsqlQuery#getType() type}.
*
* @param context {@link MetadataContext} of the MetaData resolution
* @param query the {@link DsqlQuery} to resolve the output metadata from.
*/
@Override
public MetadataType getOutputType(MetadataContext context, Object query) throws MetadataResolvingException, ConnectionException {
if (query instanceof DsqlQuery) {
DsqlQuery dsqlQuery = (DsqlQuery) query;
MetadataType entityMetadata = entityResolver.getEntityMetadata(context, dsqlQuery.getType().getName());
BaseTypeBuilder builder = context.getTypeBuilder();
final List<Field> fields = dsqlQuery.getFields();
if (fields.size() == 1 && fields.get(0).getName().equals("*")) {
return entityMetadata;
}
entityMetadata.accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
ObjectTypeBuilder objectTypeBuilder = builder.objectType();
objectType.getFields().stream().filter(p -> fields.stream().anyMatch(f -> f.getName().equalsIgnoreCase(p.getKey().getName().getLocalPart()))).forEach(p -> {
ObjectFieldTypeBuilder field = objectTypeBuilder.addField();
field.key(p.getKey().getName());
field.value(p.getValue());
});
}
});
return builder.build();
} else {
return nativeOutputResolver.getOutputType(context, query);
}
}
use of org.mule.metadata.api.builder.ObjectTypeBuilder in project mule by mulesoft.
the class TestMultiLevelKeyResolver method getInputMetadata.
@Override
public MetadataType getInputMetadata(MetadataContext context, LocationKey key) throws MetadataResolvingException, ConnectionException {
checkLocationKey(key);
final ObjectTypeBuilder objectBuilder = BaseTypeBuilder.create(new MetadataFormat(key.toString(), key.toString(), APPLICATION_JAVA_MIME_TYPE)).objectType();
objectBuilder.addField().key("CONTINENT").value().stringType();
objectBuilder.addField().key("COUNTRY").value().stringType();
objectBuilder.addField().key("CITY").value().stringType();
return objectBuilder.build();
}
Aggregations