private OperationModel mockOperationModel(OutputModel output, OutputModel attributes, ParameterModel... params) { OperationModel op = mock(OperationModel.class, withSettings().lenient()); when(op.getOutput()).thenReturn(output); when(op.getOutputAttributes()).thenReturn(attributes); if (params != null) { mockParameters(op, params); } return op; } }
@Test public void operationOutputIsNotValidated() { when(operationModel.getAllParameterModels()).thenReturn(emptyList()); when(operationModel.getOutput()).thenReturn(outputModel); when(outputModel.getType()).thenReturn(toMetadataType(PojoWithParameterWithoutGetter.class)); validate(extensionModel, validator); }
private OperationModel mockOperationModel(OutputModel output, OutputModel attributes, ParameterModel... params) { OperationModel op = mock(OperationModel.class, withSettings().lenient()); when(op.getOutput()).thenReturn(output); when(op.getOutputAttributes()).thenReturn(attributes); if (params != null) { mockParameters(op, params); } return op; } }
private MetadataType getResolvedTypeFromList() { final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location); assertSuccessResult(result); ComponentMetadataDescriptor<OperationModel> descriptor = result.get(); MetadataType param = descriptor.getModel().getOutput().getType(); assertThat(param, is(instanceOf(ArrayType.class))); assertThat(getId(param).get(), is(List.class.getName())); return param; }
private void assertOperation(String operationName, ExtensionModel extensionModel, DeclarationOperation declarer, String outputDocumentation, String outputAttributeDocumentation) { final Optional<OperationModel> operationModelOptional = extensionModel.getOperationModel(operationName); assertThat(operationModelOptional.isPresent(), is(true)); final OperationModel operationModel = operationModelOptional.get(); assertThat(operationModel.getOutput().getType(), is(declarer.getOutput())); assertThat(operationModel.getOutput().getDescription(), is(outputDocumentation)); assertThat(operationModel.getOutputAttributes().getType(), is(declarer.getOutputAttributes())); assertThat(operationModel.getOutputAttributes().getDescription(), is(outputAttributeDocumentation)); }
@Before public void before() { ExtensionOperationDescriptorModelProperty modelProperty = new ExtensionOperationDescriptorModelProperty(operationElement); when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(operationModel.getOutput()) .thenReturn(new ImmutableOutputModel("Message.Payload", toMetadataType(String.class), false, emptySet())); when(operationModel.getName()).thenReturn("operation"); when(operationModel.getModelProperty(ExtensionOperationDescriptorModelProperty.class)).thenReturn(Optional.of(modelProperty)); when(operationElement.getReturnType()).thenReturn(new TypeWrapper(String.class, typeLoader)); visitableMock(operationModel); }
/** * The operation returns the result of one of its routes, keeping the attributes of the result message. * * @param model the model to assert on */ private void assertAssociatedProcessorsChangeOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
private void setUpOperationReturning(Object payload, Type type) throws InitialisationException { messageProcessor = createOperationMessageProcessor(); MetadataType mapType = new DefaultExtensionsTypeLoaderFactory().createTypeLoader().load(type); when(operationModel.getOutput()).thenReturn(new ImmutableOutputModel("desc", mapType, false, emptySet())); initialiseIfNeeded(messageProcessor, muleContext); when(operationExecutor.execute(any(ExecutionContext.class))) .thenReturn(just(payload)); } }
/** * The operation returns its input as the output. * * @param model the model to assert on */ private void assertOutputSameAsInput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(VoidType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
@Test public void operationIsVoid() throws Exception { when(operationModel.getOutput()) .thenReturn(new ImmutableOutputModel("Message.Payload", toMetadataType(void.class), false, emptySet())); messageProcessor = setUpOperationMessageProcessor(); when(operationExecutor.execute(any(ExecutionContext.class))).thenReturn(empty()); assertThat(messageProcessor.process(event), is(sameInstance(event))); }
/** * The operation buids its own output, leaving the resulting message without attrbiutes. * * @param model the model to assert on */ private void assertComponentDeterminesOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
@Test public void withOutputJsonType() throws Exception { OperationModel o = getOperation("jsonOutput"); assertJsonPerson(o.getOutput()); }
@Test public void customTypeOutputWithStaticAttributes() throws Exception { OperationModel o = getOperation("customTypeOutputWithStaticAttributes"); assertJsonPerson(o.getOutput()); assertThat(MetadataTypeUtils.getTypeId(o.getOutputAttributes().getType()).get(), is(Banana.class.getName())); }
@Test public void operationReturnsVoidType() { exception.expect(IllegalModelDefinitionException.class); exception .expectMessage("A Metadata OutputResolver named 'MockResolver' in category 'MockResolver' was defined for the Void Operation 'operation'. " + "Output resolvers cannot be used on Void Operations, since they produce no output."); mockMetadataResolverFactory(operationModel, new DefaultMetadataResolverFactory(NULL_RESOLVER_SUPPLIER, emptyMap(), MOCK_RESOLVER_SUPPLIER, NULL_RESOLVER_SUPPLIER)); when(operationModel.getOutput()).thenReturn(new ImmutableOutputModel(EMPTY, toMetadataType(Void.class), true, emptySet())); validate(extensionModel, validator); }
@Test public void nonBlockingExecutionType() { ExtensionModel extensionModel = loadExtension(MarvelExtension.class); OperationModel operation = extensionModel.getConfigurationModel(CONFIG_NAME).get().getOperationModel("fireMissile").get(); assertThat(operation.isBlocking(), is(false)); assertThat(operation.getExecutionType(), is(CPU_LITE)); assertThat(operation.getOutput().getType(), instanceOf(StringType.class)); assertThat(operation.getOutputAttributes().getType(), equalTo(typeLoader.load(void.class))); }
@Test public void pagedOperationResultWithAttributeResolverMetadataTestCase() throws Exception { location = Location.builder().globalName(PAGED_OPERATION_METADATA_RESULT_WITH_ATTRIBUTES).addProcessorsPart().addIndexPart(0) .build(); ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadata(PERSON_METADATA_KEY); MetadataType param = metadataDescriptor.getModel().getOutput().getType(); assertThat(param, is(instanceOf(ArrayType.class))); assertThat(getId(param).get(), is(Iterator.class.getName())); assertMessageType(((ArrayType) param).getType(), personType, personType); }
@Test public void operationReturnsDictionaryTypeWithPojoValue() { dictionaryType = typeBuilder.objectType() .openWith(toMetadataType(Apple.class)).build(); when(operationModel.getOutput()).thenReturn(new ImmutableOutputModel("", dictionaryType, false, emptySet())); mockMetadataResolverFactory(sourceModel, new DefaultMetadataResolverFactory(NULL_RESOLVER_SUPPLIER, emptyMap(), MOCK_RESOLVER_SUPPLIER, NULL_RESOLVER_SUPPLIER)); validate(extensionModel, validator); }
@Test public void dynamicOutputAndContentWithCache() throws Exception { location = Location.builder().globalName(CONTENT_AND_OUTPUT_CACHE_RESOLVER).addProcessorsPart().addIndexPart(0).build(); final ComponentMetadataDescriptor<OperationModel> metadataDescriptor = getSuccessComponentDynamicMetadataWithKey(PERSON_METADATA_KEY); final OperationModel typedModel = metadataDescriptor.getModel(); MetadataType outputType = typedModel.getOutput().getType(); MetadataType contentType = getParameter(typedModel, "content").getType(); assertThat(contentType, is(equalTo(outputType))); }
@Test public void operationWhichReturnsListOfMessages() throws Exception { location = Location.builder().globalName("listOfMessages").addProcessorsPart().addIndexPart(0).build(); final MetadataResult<ComponentMetadataDescriptor<OperationModel>> result = metadataService.getOperationMetadata(location); assertSuccessResult(result); ComponentMetadataDescriptor<OperationModel> descriptor = result.get(); MetadataType param = descriptor.getModel().getOutput().getType(); assertThat(param, is(instanceOf(ArrayType.class))); assertMessageType(((ArrayType) param).getType(), TYPE_LOADER.load(String.class), TYPE_LOADER.load(StringAttributes.class)); }
@Test public void getNativeQueryOutputArrayMetadata() throws Exception { location = builder().globalName(NATIVE_QUERY_LIST_FLOW).addProcessorsPart().addIndexPart(0).build(); MetadataKey nativeKey = newKey(NATIVE_QUERY).build(); MetadataResult<ComponentMetadataDescriptor<OperationModel>> entityMetadata = getComponentDynamicMetadata(nativeKey); assertThat(entityMetadata.isSuccess(), is(true)); MetadataType generatedType = entityMetadata.get().getModel().getOutput().getType(); assertThat(generatedType, is(instanceOf(ArrayType.class))); assertCircleType((ObjectType) ((ArrayType) generatedType).getType()); }