Search in sources :

Example 6 with DynamicActionMetadata

use of io.syndesis.common.model.connection.DynamicActionMetadata in project syndesis by syndesisio.

the class ConnectionActionHandlerTest method shouldAddMetaAndSetStatusToBadRequestIfMetaCallFails.

@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");
}
Also used : Entity(javax.ws.rs.client.Entity) Meta(io.syndesis.server.endpoint.v1.dto.Meta) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) Response(javax.ws.rs.core.Response) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) MetaData(io.syndesis.server.endpoint.v1.dto.MetaData) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Example 7 with DynamicActionMetadata

use of io.syndesis.common.model.connection.DynamicActionMetadata in project syndesis by syndesisio.

the class ConnectionActionHandlerTest method shouldElicitActionPropertySuggestions.

@Test
public void shouldElicitActionPropertySuggestions() {
    final DynamicActionMetadata suggestions = new DynamicActionMetadata.Builder().putProperty("sObjectName", Collections.singletonList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Contact", "Contact"))).putProperty("sObjectIdName", Arrays.asList(DynamicActionMetadata.ActionPropertySuggestion.Builder.of("ID", "Contact ID"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("Email", "Email"), DynamicActionMetadata.ActionPropertySuggestion.Builder.of("TwitterScreenName__c", "Twitter Screen Name"))).inputShape(// 
    salesforceContactShape).build();
    when(metadataCommand.execute()).thenReturn(suggestions);
    when(((HystrixInvokableInfo<?>) metadataCommand).isSuccessfulExecution()).thenReturn(true);
    final ConnectorDescriptor enrichedDefinitioin = new ConnectorDescriptor.Builder().createFrom(createOrUpdateSalesforceObjectDescriptor).replaceConfigurationProperty("sObjectName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Contact", "Contact"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("ID", "Contact ID"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("Email", "Email"))).replaceConfigurationProperty("sObjectIdName", c -> c.addEnum(ConfigurationProperty.PropertyValue.Builder.of("TwitterScreenName__c", "Twitter Screen Name"))).inputDataShape(// 
    salesforceContactShape).build();
    final Map<String, String> parameters = new HashMap<>();
    parameters.put("sObjectName", "Contact");
    final Response response = handler.enrichWithMetadata(SALESFORCE_CREATE_OR_UPDATE, parameters);
    assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
    @SuppressWarnings("unchecked") final Meta<ConnectorDescriptor> meta = (Meta<ConnectorDescriptor>) response.getEntity();
    assertThat(meta.getValue()).isEqualTo(enrichedDefinitioin);
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Arrays(java.util.Arrays) MetaData(io.syndesis.server.endpoint.v1.dto.MetaData) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) EncryptionComponent(io.syndesis.server.dao.manager.EncryptionComponent) ArgumentCaptor(org.mockito.ArgumentCaptor) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Status(javax.ws.rs.core.Response.Status) DataShape(io.syndesis.common.model.DataShape) MetadataConfigurationProperties(io.syndesis.server.verifier.MetadataConfigurationProperties) Connector(io.syndesis.common.model.connection.Connector) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Entity(javax.ws.rs.client.Entity) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) Meta(io.syndesis.server.endpoint.v1.dto.Meta) Response(javax.ws.rs.core.Response) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) HystrixExecutable(com.netflix.hystrix.HystrixExecutable) Mockito.withSettings(org.mockito.Mockito.withSettings) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) Meta(io.syndesis.server.endpoint.v1.dto.Meta) HashMap(java.util.HashMap) DynamicActionMetadata(io.syndesis.common.model.connection.DynamicActionMetadata) Response(javax.ws.rs.core.Response) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) HystrixInvokableInfo(com.netflix.hystrix.HystrixInvokableInfo) Test(org.junit.Test)

Aggregations

DynamicActionMetadata (io.syndesis.common.model.connection.DynamicActionMetadata)7 HystrixInvokableInfo (com.netflix.hystrix.HystrixInvokableInfo)6 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)6 Meta (io.syndesis.server.endpoint.v1.dto.Meta)6 Response (javax.ws.rs.core.Response)6 Entity (javax.ws.rs.client.Entity)4 Test (org.junit.Test)4 HystrixExecutable (com.netflix.hystrix.HystrixExecutable)3 DataShape (io.syndesis.common.model.DataShape)3 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)3 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)3 Connector (io.syndesis.common.model.connection.Connector)3 EncryptionComponent (io.syndesis.server.dao.manager.EncryptionComponent)3 MetadataConfigurationProperties (io.syndesis.server.verifier.MetadataConfigurationProperties)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Status (javax.ws.rs.core.Response.Status)3 Api (io.swagger.annotations.Api)2 ApiOperation (io.swagger.annotations.ApiOperation)2