Search in sources :

Example 1 with ConnectorGenerator

use of io.syndesis.server.api.generator.ConnectorGenerator 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.getArgument(0));
    when(applicationContext.getBean("connector-template-id")).thenReturn(new ConnectorGenerator(new Connector.Builder().addTags("from-connector").build()) {

        @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 APISummary 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").addTag("from-connector").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.api.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) APISummary(io.syndesis.common.model.api.APISummary) 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 2 with ConnectorGenerator

use of io.syndesis.server.api.generator.ConnectorGenerator in project syndesis by syndesisio.

the class BaseConnectorGeneratorHandler method withGeneratorAndTemplate.

final <T> T withGeneratorAndTemplate(final String templateId, final BiFunction<ConnectorGenerator, ConnectorTemplate, T> callback) {
    final ConnectorTemplate connectorTemplate = getDataManager().fetch(ConnectorTemplate.class, templateId);
    if (connectorTemplate == null) {
        throw new EntityNotFoundException("Connector template: " + templateId);
    }
    final ConnectorGenerator connectorGenerator = determineConnectorGenerator(templateId);
    return callback.apply(connectorGenerator, connectorTemplate);
}
Also used : ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGenerator(io.syndesis.server.api.generator.ConnectorGenerator) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 3 with ConnectorGenerator

use of io.syndesis.server.api.generator.ConnectorGenerator 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 APISummary preparedSummary = new APISummary.Builder().build();
    when(dataManager.fetch(ConnectorTemplate.class, "connector-template")).thenReturn(template);
    when(applicationContext.getBean("connector-template")).thenReturn(connectorGenerator);
    when(connectorGenerator.info(same(template), same(connectorSettings))).thenReturn(preparedSummary);
    final APISummary info = handler.info(connectorSettings);
    assertThat(info).isSameAs(preparedSummary);
}
Also used : APISummary(io.syndesis.common.model.api.APISummary) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorGenerator(io.syndesis.server.api.generator.ConnectorGenerator) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Aggregations

ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)3 ConnectorGenerator (io.syndesis.server.api.generator.ConnectorGenerator)3 APISummary (io.syndesis.common.model.api.APISummary)2 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)2 Test (org.junit.Test)2 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connector (io.syndesis.common.model.connection.Connector)1 ConnectorGroup (io.syndesis.common.model.connection.ConnectorGroup)1 HashMap (java.util.HashMap)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1