@Test public void shouldAddMetaAndSetStatusToBadRequestIfMetaCallFails() { @SuppressWarnings({"unchecked", "rawtypes"}) final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class; ArgumentCaptor.forClass(entityType); // simulates fallback return final DynamicActionMetadata fallback = new DynamicActionMetadata.Builder().build(); when(metadataCommand.execute()).thenReturn(fallback); when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(false); final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap()); assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode()); @SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity(); final ConnectorDescriptor descriptor = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor) .inputDataShape(ConnectionActionHandler.ANY_SHAPE)// .outputDataShape(salesforceOutputShape)// .build(); assertThat(meta.getValue()).isEqualTo(descriptor); final MetaData metadata = meta.getData(); assertThat(metadata).isNotNull(); assertThat(metadata.getType()).contains(MetaData.Type.WARNING); assertThat(metadata.getMessage()).contains("The query did not succeed"); }
@Test public void shouldProvideActionDefinition() { @SuppressWarnings({"unchecked", "rawtypes"}) final Class<Entity<Map<String, Object>>> entityType = (Class) Entity.class; ArgumentCaptor.forClass(entityType); final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder() .putProperty("sObjectName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Account", "Account"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact"))) .build(); when(metadataCommand.execute()).thenReturn(suggestions); when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true); final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, Collections.emptyMap()); assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode()); @SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity(); final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder() .createFrom(createOrUpdateSalesforceObjectDescriptor) .replaceConfigurationProperty("sObjectName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Account", "Account"), ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact"))) .inputDataShape(ConnectionActionHandler.ANY_SHAPE)// .build(); assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin); }
.addTag("locked-action") .descriptor(new ConnectorDescriptor.Builder() .createFrom(startAction.getDescriptor()) .outputDataShape(startDataShape) .build()) .addTag("locked-action") .descriptor(new ConnectorDescriptor.Builder() .createFrom(endAction.getDescriptor()) .inputDataShape(endDataShape) .addConnectorCustomizer("io.syndesis.connector.rest.swagger.ResponseCustomizer")
.createFrom(createOrUpdateSalesforceObjectDescriptor) .replaceConfigurationProperty("sObjectName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact")))
protected Step newSqlEndpointStep(String actionId, Consumer<Step.Builder> stepConsumer, Consumer<ConnectorDescriptor.Builder> descriptorConsumer) { final Connector connector = getResourceManager().mandatoryLoadConnector("sql"); final ConnectorAction action = getResourceManager().mandatoryLookupAction(connector, actionId); final ConnectorDescriptor.Builder descriptorBuilder = new ConnectorDescriptor.Builder().createFrom(action.getDescriptor()); descriptorConsumer.accept(descriptorBuilder); final Step.Builder builder = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder().createFrom(action).descriptor(descriptorBuilder.build()).build()) .connection(new io.syndesis.common.model.connection.Connection.Builder() .connector(connector) .putConfiguredProperty("user", db.properties.getProperty("sql-connector.user")) .putConfiguredProperty("password", db.properties.getProperty("sql-connector.password")) .putConfiguredProperty("url", db.properties.getProperty("sql-connector.url")) .build()); stepConsumer.accept(builder); return builder.build(); } }
/** * Creates an immutable copy of a {@link ConnectorDescriptor} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable ConnectorDescriptor instance */ public static ConnectorDescriptor copyOf(ConnectorDescriptor instance) { if (instance instanceof ImmutableConnectorDescriptor) { return (ImmutableConnectorDescriptor) instance; } return new ConnectorDescriptor.Builder() .createFrom(instance) .build(); }