use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class DsqlQueryMetadataResolverTestCase method getFullOutputMetadata.
@Test
public void getFullOutputMetadata() throws MetadataResolvingException, ConnectionException {
DsqlQuery dsqlQuery = dsqlParser.parse("dsql:SELECT * FROM Circle WHERE (diameter < 18)");
MetadataType outputMetadata = getQueryMetadataResolver().getOutputType(context, dsqlQuery);
ObjectType type = getAndAssertTypeOf(outputMetadata);
assertThat(type.getFields(), hasSize(3));
type.getFields().forEach(f -> {
String name = f.getKey().getName().getLocalPart();
assertThat(name, isIn(asList("color", "id", "diameter")));
});
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class ImportedTypesDeclarationEnricher method enrich.
@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
ExtensionDeclarer descriptor = extensionLoadingContext.getExtensionDeclarer();
ExtensionDeclaration extensionDeclaration = descriptor.getDeclaration();
final Optional<ExtensionTypeDescriptorModelProperty> extensionType = extensionDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!extensionType.isPresent()) {
return;
}
Type type = extensionType.get().getType();
final List<AnnotationValueFetcher<Import>> importTypes = parseRepeatableAnnotation(type, Import.class, c -> ((ImportedTypes) c).value());
if (!importTypes.isEmpty()) {
if (importTypes.stream().map(annotation -> annotation.getClassValue(Import::type)).distinct().collect(toList()).size() != importTypes.size()) {
throw new IllegalModelDefinitionException(format("There should be only one Import declaration for any given type in extension [%s]." + " Multiple imports of the same type are not allowed", extensionDeclaration.getName()));
}
importTypes.forEach(imported -> {
MetadataType importedType = imported.getClassValue(Import::type).asMetadataType();
if (!(importedType instanceof ObjectType)) {
throw new IllegalArgumentException(format("Type '%s' is not complex. Only complex types can be imported from other extensions.", type.getTypeName()));
}
extensionDeclaration.addImportedType(new ImportedTypeModel((ObjectType) importedType));
});
}
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class MetadataOperationTestCase method attributesDynamicPersonTypeMetadata.
@Test
public void attributesDynamicPersonTypeMetadata() throws Exception {
location = Location.builder().globalName(OUTPUT_ATTRIBUTES_WITH_DYNAMIC_METADATA).addProcessorsPart().addIndexPart(0).build();
final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY);
final OperationModel typedModel = metadataDescriptor.getModel();
MetadataType type = typedModel.getOutputAttributes().getType();
assertThat(type, is(instanceOf(ObjectType.class)));
ObjectType dictionary = (ObjectType) type;
assertThat(dictionary.getOpenRestriction().get(), is(instanceOf(StringType.class)));
}
use of org.mule.metadata.api.model.ObjectType in project mule by mulesoft.
the class MetadataOperationTestCase method metadataKeyDefaultValue.
@Test
public void metadataKeyDefaultValue() throws Exception {
location = Location.builder().globalName(METADATA_KEY_DEFAULT_VALUE).addProcessorsPart().addIndexPart(0).build();
MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location);
assertSuccessResult(result);
MetadataType type = result.get().getModel().getOutput().getType();
assertThat(type, is(instanceOf(ObjectType.class)));
ObjectType objectType = (ObjectType) type;
assertThat(objectType.getFields(), hasSize(2));
objectType.getFields().forEach(f -> assertThat(f.getKey().getName().getLocalPart(), isOneOf(TIRES, BRAND)));
Optional<MetadataKey> metadataKeyOptional = result.get().getMetadataAttributes().getKey();
assertThat(metadataKeyOptional.isPresent(), is(true));
assertThat(metadataKeyOptional.get().getId(), is(CAR));
}
Aggregations