@Override protected void onOperation(OperationDeclaration declaration) { Optional<MetadataType> outputType = declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class) .map(ExtensionOperationDescriptorModelProperty::getOperationElement) .map(OperationElement::getOperationReturnMetadataType); declareMimeTypeParameters(declaration, outputType); }
private void enrichOperation(OperationDeclaration declaration) { declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class) .map(ExtensionOperationDescriptorModelProperty::getOperationElement) .ifPresent(annotatedElement -> enrichDeclaration(declaration, annotatedElement)); }
@Override protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration operation) { operation.getModelProperty(ImplementingMethodModelProperty.class) .map(ImplementingMethodModelProperty::getMethod) .ifPresent(method -> { getOutputType(method).ifPresent(type -> declareCustomType(operation.getOutput(), type)); getAttributesType(method).ifPresent(type -> declareCustomType(operation.getOutputAttributes(), type)); }); declareParametersCustomStaticTypes(operation); }
@Override protected void onOperation(OperationDeclaration declaration) { declaration.getModelProperty(OperationComponentModelModelProperty.class) .ifPresent(modelProperty -> { ComponentModel bodyComponentModel = modelProperty.getBodyComponentModel(); declaration.getAllParameters().stream() .filter(parameterDeclaration -> parameterDeclaration.getType() instanceof StringType) .forEach(parameterDeclaration -> traverseProperty(bodyComponentModel.getInnerComponents(), parameterDeclaration)); }); } }.walk(extensionDeclaration);
private void enrichOperationMetadata(OperationDeclaration declaration) { declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class) .map(ExtensionOperationDescriptorModelProperty::getOperationElement) .ifPresent(operation -> { if (operation.isAnnotatedWith(Query.class)) { enrichWithDsql(declaration, operation); } else { MetadataScopeAdapter metadataScope = new DefaultMetadataScopeAdapter(extensionType, operation, declaration); enrichResolversInformation(declaration, metadataScope); } }); }
@Override public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) { final StereotypeModel defaultStereotype = createStereotype(declaration.getName(), processorParent); ifPresent(declaration.getModelProperty(ImplementingMethodModelProperty.class) .map(ImplementingMethodModelProperty::getMethod) .map(method -> new OperationWrapper(method, typeLoader)), methodElement -> resolveStereotype(methodElement, declaration, defaultStereotype), () -> declaration.withStereotype(defaultStereotype)); addConfigRefStereoTypesIfNeeded(declaration); }
private void mockExtensionOperationDescriptorModelProperty(String operationMethodName) throws NoSuchMethodException { Method operationMethod = TestMethods.class.getMethod(operationMethodName); OperationElement operationElement = new OperationWrapper(operationMethod, typeLoader); when(operation.getModelProperty(ExtensionOperationDescriptorModelProperty.class)) .thenReturn(of(new ExtensionOperationDescriptorModelProperty(operationElement))); }
@Before public void before() throws Exception { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getOperations()).thenReturn(asList(operationDeclaration)); when(operationDeclaration.getModelProperty(ImplementingMethodModelProperty.class)) .thenReturn(Optional.of(new ImplementingMethodModelProperty(TestOperations.class.getMethods()[0]))); }
@Test public void typeResolverInformationSkippedForStaticResolver() throws Exception { OperationDeclaration operation = getDeclaration(declaration.getOperations(), "outputAttributesWithDeclaredSubtypesMetadata"); Optional<TypeResolversInformationModelProperty> info = operation .getModelProperty(TypeResolversInformationModelProperty.class); assertThat("Static resolvers information should not be declared in the model", info.isPresent(), is(false)); }
@Test public void typeResolverInformationSkippedForDsql() throws Exception { OperationDeclaration query = getDeclaration(declaration.getOperations(), "doQuery"); Optional<TypeResolversInformationModelProperty> info = query .getModelProperty(TypeResolversInformationModelProperty.class); assertThat("Query resolvers information should not be declared in the model", info.isPresent(), is(false)); }
@Test public void schemaNotFound() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Can't load schema [invalid.xsd]. It was not found in the resources."); when(operationDeclaration.getModelProperty(ImplementingMethodModelProperty.class)) .thenReturn(Optional.of(new ImplementingMethodModelProperty(TestOperations.class.getMethod("schemaNotFound")))); enricher.enrich(extensionLoadingContext); }
@Before public void before() { when(extensionLoadingContext.getExtensionDeclarer()).thenReturn(extensionDeclarer); when(extensionDeclarer.getDeclaration()).thenReturn(extensionDeclaration); when(extensionDeclaration.getOperations()).thenReturn(singletonList(operation)); when(extensionDeclaration.getMessageSources()).thenReturn(singletonList(source)); when(source.getSuccessCallback()).thenReturn(empty()); when(source.getErrorCallback()).thenReturn(empty()); when(source.getModelProperty(ExtensionTypeDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getModelProperty(ExtensionOperationDescriptorModelProperty.class)).thenReturn(empty()); when(operation.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); when(source.getParameterGroup(DEFAULT_GROUP_NAME)).thenReturn(new ParameterGroupDeclaration(DEFAULT_GROUP_NAME)); mockMediaType(operation, false); mockMediaType(source, false); }
@Test public void enrichConnectedOperation() throws Exception { enricher.enrich(extensionLoadingContext); verify(connectedOperation).addModelProperty(isA(InterceptorsModelProperty.class)); InterceptorsModelProperty interceptors = connectedOperation.getModelProperty(InterceptorsModelProperty.class).get(); assertThat(interceptors.getInterceptorFactories(), hasSize(2)); assertThat(interceptors.getInterceptorFactories().get(0).createInterceptor(), is(instanceOf(ConnectionInterceptor.class))); assertThat(interceptors.getInterceptorFactories().get(1).createInterceptor(), is(instanceOf(CursorResetInterceptor.class))); }
private void enrichOperation(OperationDeclaration declaration) { declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class) .map(ExtensionOperationDescriptorModelProperty::getOperationMethod) .ifPresent(annotatedElement -> enrichDeclaration(declaration, annotatedElement)); }
@Override protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration operation) { operation.getModelProperty(ImplementingMethodModelProperty.class) .map(ImplementingMethodModelProperty::getMethod) .ifPresent(method -> { getOutputType(method).ifPresent(type -> declareCustomType(operation.getOutput(), type)); getAttributesType(method).ifPresent(type -> declareCustomType(operation.getOutputAttributes(), type)); }); declareParametersCustomStaticTypes(operation); }
@Override public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) { declaration.getModelProperty(ImplementingMethodModelProperty.class) .map(ImplementingMethodModelProperty::getMethod) .map((Method method) -> new MethodWrapper(method, typeLoader)) .ifPresent(methodElement -> new MethodStereotypeResolver(methodElement, declaration, namespace, PROCESSOR, stereotypes) .resolveStereotype()); }
assertTransactional(operation, false); java.util.Optional<ExceptionHandlerFactory> exceptionEnricherFactory = operation .getModelProperty(ExceptionHandlerModelProperty.class) .map(ExceptionHandlerModelProperty::getExceptionHandlerFactory); assertThat(operation.getModelProperty(PagedOperationModelProperty.class).isPresent(), is(true)); assertThat(operation.getOutput().getType(), is(instanceOf(ArrayType.class))); ArrayType outputType = (ArrayType) operation.getOutput().getType();
private void enrichOperationMetadata(OperationDeclaration declaration) { declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class) .map(ExtensionOperationDescriptorModelProperty::getOperationMethod) .ifPresent(operation -> { if (operation.isAnnotatedWith(Query.class)) { enrichWithDsql(declaration, operation); } else { MetadataScopeAdapter metadataScope = new MetadataScopeAdapter(extensionType, operation, declaration); declareMetadataResolverFactory(declaration, metadataScope); enrichMetadataKeyParameters(declaration, metadataScope.getKeysResolver().get()); } }); }