Search in sources :

Example 6 with ConnectorSummary

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

the class CustomConnectorHandlerTest method shouldCreateNewConnectorsBasedOnConnectorTemplates.

@Test
public void shouldCreateNewConnectorsBasedOnConnectorTemplates() {
    final Map<String, ConfigurationProperty> properties = new HashMap<>();
    properties.put("prop1", new ConfigurationProperty.Builder().build());
    final Map<String, ConfigurationProperty> connectorProperties = new HashMap<>();
    connectorProperties.put("prop2", new ConfigurationProperty.Builder().build());
    connectorProperties.put("prop3", new ConfigurationProperty.Builder().build());
    final ConnectorGroup group = new ConnectorGroup.Builder().name("connector template group").build();
    final ConnectorTemplate connectorTemplate = // 
    new ConnectorTemplate.Builder().id(// 
    "connector-template-id").name(// 
    "connector template").properties(properties).connectorProperties(// 
    connectorProperties).connectorGroup(// 
    group).build();
    final ConnectorAction action = new ConnectorAction.Builder().name("action").build();
    when(dataManager.fetch(ConnectorTemplate.class, "connector-template-id")).thenReturn(connectorTemplate);
    when(dataManager.create(any(Connector.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, Connector.class));
    when(applicationContext.getBean("connector-template-id", ConnectorGenerator.class)).thenReturn(new ConnectorGenerator() {

        @Override
        public Connector generate(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
            return new Connector.Builder().createFrom(baseConnectorFrom(connectorTemplate, connectorSettings)).putAllProperties(connectorProperties).putConfiguredProperty("prop1", "value1").addAction(action).build();
        }

        @Override
        public ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
            return null;
        }
    });
    final Connector created = // 
    new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(// 
    new ConnectorSettings.Builder().connectorTemplateId(// 
    "connector-template-id").name(// 
    "new connector").description(// 
    "new connector description").icon(// 
    "new connector icon").putConfiguredProperty("prop1", // 
    "value1").putConfiguredProperty("unknown-prop", // 
    "unknown-value").build());
    final Connector expected = // 
    new Connector.Builder().id(// 
    created.getId()).name(// 
    "new connector").description(// 
    "new connector description").icon(// 
    "new connector icon").connectorGroup(// 
    group).properties(// 
    connectorProperties).putConfiguredProperty("prop1", // 
    "value1").addAction(// 
    action).build();
    assertThat(created).isEqualTo(expected);
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) HashMap(java.util.HashMap) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Test(org.junit.Test)

Example 7 with ConnectorSummary

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

the class CustomConnectorHandlerTest method shouldProvideInfoAboutAppliedConnectorSettings.

@Test
public void shouldProvideInfoAboutAppliedConnectorSettings() {
    final CustomConnectorHandler handler = new CustomConnectorHandler(dataManager, applicationContext, iconDao);
    final ConnectorGenerator connectorGenerator = mock(ConnectorGenerator.class);
    final ConnectorTemplate template = new ConnectorTemplate.Builder().build();
    final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().connectorTemplateId("connector-template").build();
    final ConnectorSummary preparedSummary = new ConnectorSummary.Builder().build();
    when(dataManager.fetch(ConnectorTemplate.class, "connector-template")).thenReturn(template);
    when(applicationContext.getBean("connector-template", ConnectorGenerator.class)).thenReturn(connectorGenerator);
    when(connectorGenerator.info(same(template), same(connectorSettings))).thenReturn(preparedSummary);
    final ConnectorSummary info = handler.info(connectorSettings);
    assertThat(info).isSameAs(preparedSummary);
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 8 with ConnectorSummary

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

the class CustomSwaggerConnectorITCase method shouldOfferCustomConnectorInfoForUploadedSwagger.

@Test
public void shouldOfferCustomConnectorInfoForUploadedSwagger() throws IOException {
    final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().connectorTemplateId(TEMPLATE_ID).build();
    final ResponseEntity<ConnectorSummary> response = post("/api/v1/connectors/custom/info", multipartBodyForInfo(connectorSettings, getClass().getResourceAsStream("/io/syndesis/server/runtime/test-swagger.json")), ConnectorSummary.class, tokenRule.validToken(), HttpStatus.OK, multipartHeaders());
    final ConnectorSummary expected = // \
    new ConnectorSummary.Builder().name(// 
    "Todo App API").description(// 
    "unspecified").actionsSummary(// 
    TestConfiguration.ACTIONS_SUMMARY).addWarning(new Violation.Builder().error("missing-response-schema").message("Operation DELETE /api/{id} does not provide a response schema for code 204").build()).build();
    final ConnectorSummary got = response.getBody();
    assertThat(got).isEqualToIgnoringGivenFields(expected, "icon");
    assertThat(got.getIcon()).startsWith("data:image");
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) Violation(io.syndesis.common.model.Violation) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Aggregations

ConnectorSummary (io.syndesis.common.model.connection.ConnectorSummary)8 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)7 Test (org.junit.Test)6 Connector (io.syndesis.common.model.connection.Connector)3 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)3 ConnectorGenerator (io.syndesis.server.connector.generator.ConnectorGenerator)3 ActionsSummary (io.syndesis.common.model.action.ActionsSummary)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)2 HttpMethod (io.swagger.models.HttpMethod)1 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Swagger (io.swagger.models.Swagger)1 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1 Parameter (io.swagger.models.parameters.Parameter)1 RefParameter (io.swagger.models.parameters.RefParameter)1 DataShape (io.syndesis.common.model.DataShape)1 DataShapeKinds (io.syndesis.common.model.DataShapeKinds)1