@Before public void before() { when(extensionModel.getSourceModels()).thenReturn(singletonList(sourceModel)); when(sourceModel.getSuccessCallback()).thenReturn(empty()); when(sourceModel.getErrorCallback()).thenReturn(empty()); }
@Test public void sourceNameClashesWithSourceName() { exception.expect(IllegalModelDefinitionException.class); SourceModel anotherSourceModel = mock(SourceModel.class); when(anotherSourceModel.getName()).thenReturn(SOURCE_NAME); when(anotherSourceModel.getErrorCallback()).thenReturn(empty()); when(anotherSourceModel.getSuccessCallback()).thenReturn(empty()); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel, anotherSourceModel)); validate(); }
@Test public void sourceWithFixedBackPressureStrategy() { SourceModel source = heisenbergExtension.getSourceModels().get(0); Optional<ParameterModel> parameter = source.getAllParameterModels().stream() .filter(p -> BACK_PRESSURE_STRATEGY_PARAMETER_NAME.equals(p.getName())) .findAny(); assertThat(parameter.isPresent(), is(false)); }
@Before public void setUp() throws Exception { problemsReporter = new ProblemsReporter(extensionModel); validator = new SourceCallbacksModelValidator(); when(extensionModel.getSourceModels()).thenReturn(singletonList(sourceModel)); when(sourceModel.getTerminateCallback()).thenReturn(of(onTerminateCallback)); when(sourceModel.getSuccessCallback()).thenReturn(Optional.empty()); when(sourceModel.getErrorCallback()).thenReturn(Optional.empty()); }
@Test(expected = IllegalModelDefinitionException.class) public void repeatedEncodingSourceField() { when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); when(sourceModel.getSuccessCallback()).thenReturn(java.util.Optional.empty()); when(sourceModel.getErrorCallback()).thenReturn(java.util.Optional.empty()); mockImplementingType(sourceModel, SourceRepeatedEncoding.class); validate(extensionModel, validator); }
@Before public void setUp() { when(extensionModel.getSourceModels()).thenReturn(singletonList(sourceModel)); when(extensionModel.getOperationModels()).thenReturn(singletonList(operationModel)); when(sourceModel.getErrorCallback()).thenReturn(Optional.empty()); when(sourceModel.getSuccessCallback()).thenReturn(Optional.empty()); when(sourceModel.getParameterGroupModels()).thenReturn(singletonList(parameterGroupModel)); when(sourceModel.isTransactional()).thenReturn(true); when(operationModel.isTransactional()).thenReturn(true); when(parameterGroupModel.getParameterModels()).thenReturn(singletonList(txParameter)); when(txParameter.getName()).thenReturn(TRANSACTIONAL_ACTION_PARAMETER_NAME); when(txParameter.getModelProperty(TransactionalActionModelProperty.class)).thenReturn(transactionalActionModelProperty); problemsReporter = new ProblemsReporter(extensionModel); }
@Test(expected = IllegalModelDefinitionException.class) public void repeatedEncodingPojoField() { when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); when(sourceModel.getSuccessCallback()).thenReturn(java.util.Optional.empty()); when(sourceModel.getErrorCallback()).thenReturn(java.util.Optional.empty()); ParameterModel parameterModel = mock(ParameterModel.class); when(parameterModel.getType()).thenReturn(toMetadataType(RepeatedEncoding.class)); mockParameters(sourceModel, parameterModel); mockImplementingType(sourceModel, SourceRepeatedEncoding.class); validate(extensionModel, validator); }
@Test public void sourceWithRepeatedParameterNameAmongCallbackAndSource() { exception.expect(IllegalModelDefinitionException.class); ParameterModel offending = getParameter(SIMPLE_PARAM_NAME, String.class); SourceCallbackModel sourceCallbackModel = mock(SourceCallbackModel.class); mockParameters(sourceCallbackModel, simpleConfigParam); ParameterGroupModel group = mock(ParameterGroupModel.class); when(group.getName()).thenReturn(DEFAULT_GROUP_NAME); when(group.getModelProperty(ParameterGroupModelProperty.class)).thenReturn(empty()); when(group.isShowInDsl()).thenReturn(false); when(group.getParameterModels()).thenReturn(asList(offending)); SourceModel sourceModel = new ImmutableSourceModel(SOURCE_NAME, "", false, false, asList(group), emptyList(), null, null, of(sourceCallbackModel), empty(), empty(), false, false, false, null, SOURCE, emptySet(), emptySet(), emptySet(), null); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); validate(); }
@Before public void doSetup() { when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getConfigurationModels()).thenReturn(emptyList()); when(extensionModel.getConstructModels()).thenReturn(emptyList()); when(extensionModel.getFunctionModels()).thenReturn(emptyList()); when(extensionModel.getConnectionProviders()).thenReturn(emptyList()); when(extensionModel.getSourceModels()).thenReturn(emptyList()); when(extensionModel.getDeprecationModel()).thenReturn(empty()); when(extensionModel.getName()).thenReturn("extensionName"); when(operationModel.getParameterGroupModels()).thenReturn(asList(parameterGroupModel)); when(operationModel.getDeprecationModel()).thenReturn(empty()); when(operationModel.getName()).thenReturn("extensionOperation"); when(parameterGroupModel.getParameterModels()).thenReturn(asList(parameterModel)); when(parameterModel.isDeprecated()).thenReturn(false); when(parameterModel.getDeprecationModel()).thenReturn(empty()); when(parameterModel.getName()).thenReturn("parameterName"); when(extensionModel.getModelProperty(CompileTimeModelProperty.class)).thenReturn(ofNullable(new CompileTimeModelProperty())); }
@Before public void before() { when(extensionModel.getName()).thenReturn("dummyExtension"); when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); when(extensionModel.getSubTypes()).thenReturn(emptySet()); when(extensionModel.getModelProperty(ImplementingTypeModelProperty.class)) .thenReturn(Optional.of(new ImplementingTypeModelProperty(Object.class))); when(operationModel.getName()).thenReturn("dummyOperation"); when(operationModel.getOutput()).thenReturn(outputModel); when(sourceModel.getOutput()).thenReturn(outputModel); when(outputModel.getType()).thenReturn(toMetadataType(void.class)); when(sourceModel.getName()).thenReturn("dummySource"); when(sourceModel.getErrorCallback()).thenReturn(of(sourceCallbackModel)); when(sourceModel.getSuccessCallback()).thenReturn(of(sourceCallbackModel)); when(sourceModel.getTerminateCallback()).thenReturn(of(sourceCallbackModel)); visitableMock(operationModel, sourceModel); }
@Before public void before() throws Exception { when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); when(sourceModel.getSuccessCallback()).thenReturn(empty()); when(sourceModel.getErrorCallback()).thenReturn(empty()); when(sourceModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class)).thenReturn(of(descriptorModelProperty)); when(operationModel.getModelProperty(ExtensionOperationDescriptorModelProperty.class)) .thenReturn(of(operationDescriptorModelProperty)); when(sourceModel.getModelProperty(MediaTypeModelProperty.class)).thenReturn(empty()); when(operationModel.getModelProperty(MediaTypeModelProperty.class)).thenReturn(empty()); when(operationModel.getOutput()).thenReturn(operationOutputModel); when(sourceModel.getOutput()).thenReturn(sourceOutputModel); when(operationOutputModel.getType()).thenReturn(toMetadataType(Object.class)); when(sourceOutputModel.getType()).thenReturn(toMetadataType(Object.class)); when(sourceModel.getName()).thenReturn("source"); when(operationModel.getName()).thenReturn("operation"); mockExtensionOperationDescriptorModelProperty("returnsObject"); mockExtensionTypeDescriptorModelProperty(TestObjectSource.class); setCompileTime(true); visitableMock(operationModel, sourceModel); }
@Test public void operationWithAttributeResolverButNoAttributes() { exception.expect(IllegalModelDefinitionException.class); exception.expectMessage("has an AttributesTypeResolver defined but it doesn't declare any attributes"); when(extensionModel.getSourceModels()).thenReturn(emptyList()); mockMetadataResolverFactory(operationModel, new DefaultMetadataResolverFactory(NULL_RESOLVER_SUPPLIER, emptyMap(), SIMPLE_OUTPUT_RESOLVER, SIMPLE_OUTPUT_RESOLVER)); when(operationModel.getModelProperty(MetadataKeyIdModelProperty.class)).thenReturn(empty()); when(operationModel.getOutput()).thenReturn(new ImmutableOutputModel(EMPTY, toMetadataType(Object.class), false, emptySet())); when(operationModel.getOutputAttributes()) .thenReturn(new ImmutableOutputModel(EMPTY, toMetadataType(void.class), false, emptySet())); validate(extensionModel, validator); }
@Before public void before() throws Exception { mockConfigurationInstance(configurationModel, new TestConfig()); mockInterceptors(configurationModel, asList(() -> interceptor1, () -> interceptor2)); when(configurationModel.getOperationModels()).thenReturn(ImmutableList.of()); when(configurationModel.getSourceModels()).thenReturn(ImmutableList.of()); when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); when(operationModel.getModelProperty(ConnectivityModelProperty.class)) .thenReturn(of(new ConnectivityModelProperty(Banana.class))); when(sourceModel.getModelProperty(ConnectivityModelProperty.class)) .thenReturn(of(new ConnectivityModelProperty(Banana.class))); when(sourceModel.getErrorCallback()).thenReturn(of(sourceCallbackModel)); when(sourceModel.getSuccessCallback()).thenReturn(of(sourceCallbackModel)); when(muleContext.getConfiguration().getDefaultEncoding()).thenReturn(ENCODING); resolverSet = ConfigurationObjectBuilderTestCase.createResolverSet(); factory = new ConfigurationInstanceFactory<>(extensionModel, configurationModel, resolverSet, new ReflectionCache(), expressionManager, muleContext); }
@Test public void assertDeclaration() { assertThat(extensionModel.getName(), is(EXTENSION_NAME)); assertThat(extensionModel.getDescription(), is(EXTENSION_DESCRIPTION)); assertThat(extensionModel.getVersion(), is(VERSION)); assertThat(extensionModel.getConfigurationModels(), hasSize(2)); assertThat(extensionModel.getVendor(), is(VENDOR)); assertThat(extensionModel.getOperationModels(), hasSize(1)); assertThat(extensionModel.getConnectionProviders(), is(empty())); assertThat(extensionModel.getSourceModels(), is(empty())); }
@Override @Before public void before() throws Exception { mockConfigurationInstance(configurationModel, MODULE_CLASS.newInstance()); mockInterceptors(configurationModel, null); when(configurationModel.getOperationModels()).thenReturn(asList(operationModel)); when(configurationModel.getSourceModels()).thenReturn(ImmutableList.of()); mockClassLoaderModelProperty(extensionModel, getClass().getClassLoader()); when(extensionModel.getSourceModels()).thenReturn(ImmutableList.of()); when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getConfigurationModels()).thenReturn(asList(configurationModel)); when(operationModel.requiresConnection()).thenReturn(true); when(configurationModel.getOperationModels()).thenReturn(asList(operationModel)); when(configurationModel.getSourceModels()).thenReturn(ImmutableList.of()); when(expressionManager.openSession(any())).thenReturn(mock(ExpressionManagerSession.class)); ValueResolvingContext ctx = ValueResolvingContext.builder(event).withExpressionManager(expressionManager).build(); when(resolverSet.resolve(ctx)).thenReturn(resolverSetResult); when(resolverSetResult.asMap()).thenReturn(new HashMap<>()); visitableMock(operationModel); expirationPolicy = new ImmutableExpirationPolicy(5, MINUTES, timeSupplier); when(connectionProviderResolver.getResolverSet()).thenReturn(empty()); when(connectionProviderResolver.resolve(any())).thenReturn(null); provider = new DynamicConfigurationProvider(CONFIG_NAME, extensionModel, configurationModel, resolverSet, connectionProviderResolver, expirationPolicy, new ReflectionCache(), expressionManager, muleContext); super.before(); provider.initialise(); provider.start(); }
@Before public void before() { when(extensionModel.getOperationModels()).thenReturn(asList(operationModel)); when(extensionModel.getSourceModels()).thenReturn(asList(sourceModel)); ExtensionTypeDescriptorModelProperty descriptorModelProperty = mock(ExtensionTypeDescriptorModelProperty.class); when(extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class)).thenReturn(of(descriptorModelProperty));
when(extensionModel.getOperationModels()).thenReturn(singletonList(operationModel)); when(extensionModel.getConnectionProviders()).thenReturn(singletonList(connectionProviderModel)); when(extensionModel.getSourceModels()).thenReturn(singletonList(sourceModel)); when(extensionModel.getConstructModels()).thenReturn(singletonList(constructModel)); when(extensionModel.getXmlDslModel()).thenReturn(xmlDslModel);
assertThat(coreExtensionModel.getConstructModels(), hasSize(15)); assertThat(coreExtensionModel.getConnectionProviders(), empty()); assertThat(coreExtensionModel.getSourceModels(), hasSize(1));
@Override public void write(JsonWriter out, ExtensionModel model) throws IOException { out.beginObject(); out.name(NAME).value(model.getName()); out.name(DESCRIPTION).value(model.getDescription()); out.name(VERSION).value(model.getVersion()); out.name(VENDOR).value(model.getVendor()); writeWithDelegate(model.getCategory(), CATEGORY, out, new TypeToken<Category>() {}); writeWithDelegate(model.getXmlDslModel(), XML_DSL, out, new TypeToken<XmlDslModel>() {}); writeWithDelegate(model.getResources(), RESOURCES, out, new TypeToken<Set<String>>() {}); writeWithDelegate(model.getSubTypes(), SUB_TYPES, out, new TypeToken<Set<SubTypesModel>>() {}); writeWithDelegate(model.getPrivilegedPackages(), PRIVILEGED_PACKAGES, out, new TypeToken<Set<String>>() {}); writeWithDelegate(model.getPrivilegedArtifacts(), PRIVILEGED_ARTIFACTS, out, new TypeToken<Set<String>>() {}); writeWithDelegate(model.getExternalLibraryModels(), EXTERNAL_LIBRARIES, out, new TypeToken<Set<ExternalLibraryModel>>() {}); writeImportedTypes(out, model.getImportedTypes()); writeWithDelegate(model.getDisplayModel().orElse(null), DISPLAY_MODEL, out, new TypeToken<DisplayModel>() {}); writeWithDelegate(model.getConfigurationModels(), CONFIGURATIONS, out, new TypeToken<List<ConfigurationModel>>() {}); writeWithDelegate(model.getOperationModels(), OPERATIONS, out, new TypeToken<List<OperationModel>>() {}); writeWithDelegate(model.getFunctionModels(), FUNCTIONS, out, new TypeToken<List<FunctionModel>>() {}); writeWithDelegate(model.getConstructModels(), CONSTRUCTS, out, new TypeToken<List<ConstructModel>>() {}); writeWithDelegate(model.getConnectionProviders(), CONNECTION_PROVIDERS, out, new TypeToken<List<ConnectionProviderModel>>() {}); writeWithDelegate(model.getSourceModels(), MESSAGE_SOURCES, out, new TypeToken<List<SourceModel>>() {}); notificationModelDelegate.writeNotifications(model.getNotificationModels(), out); errorModelDelegate.writeErrors(model.getErrorModels(), out); writeExtensionLevelModelProperties(out, model); writeTypes(TYPES, out, model.getTypes()); out.endObject(); }
assertThat(coreExtensionModel.getConstructModels(), hasSize(14)); assertThat(coreExtensionModel.getConnectionProviders(), empty()); assertThat(coreExtensionModel.getSourceModels(), hasSize(1));