Skip to content

Commit

Permalink
issue syndesisio#2436: add missing bit to connector template, rework …
Browse files Browse the repository at this point in the history
…component proxy and customizers
  • Loading branch information
lburgazzoli authored and zregvart committed Apr 12, 2019
1 parent 1e83f7e commit 987874e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 31 deletions.
4 changes: 1 addition & 3 deletions app/connector/rest-swagger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@
<dependency>
<groupId>io.syndesis.integration</groupId>
<artifactId>integration-component-proxy</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.syndesis.connector</groupId>
<artifactId>connector-support-processor</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -71,7 +69,7 @@
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rest-swagger</artifactId>
<scope>provided</scope>
<scope>runtime</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.models.Info;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.syndesis.common.model.Dependency;
import io.syndesis.common.model.action.ActionsSummary;
import io.syndesis.common.model.action.ConnectorAction;
import io.syndesis.common.model.action.ConnectorDescriptor;
Expand All @@ -32,14 +34,10 @@
import io.syndesis.common.model.connection.Connector;
import io.syndesis.common.model.connection.ConnectorSettings;
import io.syndesis.common.util.openapi.OpenApiHelper;

import org.junit.Test;

import com.fasterxml.jackson.databind.node.ObjectNode;

import static io.syndesis.server.api.generator.swagger.TestHelper.reformatJson;
import static io.syndesis.server.api.generator.swagger.TestHelper.resource;

import static org.assertj.core.api.Assertions.assertThat;

public class BaseSwaggerConnectorGeneratorTest extends AbstractSwaggerConnectorTest {
Expand All @@ -53,6 +51,38 @@ ConnectorDescriptor.Builder createDescriptor(final ObjectNode json, final Swagge
}
};

@Test
public void includesRestSwaggerConnectorDependency() throws IOException {
final ConnectorSettings connectorSettings = createReverbSettings();
final Connector connector = generator.generate(SWAGGER_TEMPLATE, connectorSettings);

assertThat(connector.getDependencies()).isNotEmpty();
assertThat(connector.getDependencies()).anyMatch(d -> d.getType() == Dependency.Type.MAVEN && d.getId().startsWith("io.syndesis.connector:connector-rest-swagger"));
}

@Test
public void includesRestSwaggerConnectorCustomizers() throws IOException {
final ConnectorSettings connectorSettings = createReverbSettings();
final Connector connector = generator.generate(SWAGGER_TEMPLATE, connectorSettings);

assertThat(connector.getConnectorCustomizers()).isNotEmpty();
assertThat(connector.getConnectorCustomizers()).contains(
"io.syndesis.connector.rest.swagger.SpecificationResourceCustomizer",
"io.syndesis.connector.rest.swagger.AuthenticationCustomizer",
"io.syndesis.connector.rest.swagger.RequestCustomizer",
"io.syndesis.connector.rest.swagger.ResponseCustomizer"
);
}

@Test
public void includesRestSwaggerConnectorFactory() throws IOException {
final ConnectorSettings connectorSettings = createReverbSettings();
final Connector connector = generator.generate(SWAGGER_TEMPLATE, connectorSettings);

assertThat(connector.getConnectorFactory()).isPresent();
assertThat(connector.getConnectorFactory()).hasValue("io.syndesis.connector.rest.swagger.SwaggerConnectorFactory");
}

@Test
public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException {
final String specification = resource("/swagger/petstore.swagger.json");
Expand Down Expand Up @@ -242,4 +272,13 @@ private static ConnectorSettings createSettingsFrom(final Swagger swagger) {
.build();
}

private static ConnectorSettings createReverbSettings() throws IOException {
return new ConnectorSettings.Builder()
.name("Reverb API")
.description("Invokes Reverb API")
.icon("fa-music")
.putConfiguredProperty("specification", resource("/swagger/reverb.swagger.yaml"))
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public void shouldCreateNewConnectorsBasedOnConnectorTemplates() {

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)//
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();
Expand All @@ -87,25 +87,26 @@ public APISummary info(final ConnectorTemplate connectorTemplate, final Connecto
}
});

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")//
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)//
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);
Expand All @@ -131,8 +132,8 @@ public void shouldProvideInfoAboutAppliedConnectorSettings() {

@Test
public void shouldThrowEntityNotFoundIfNoConnectorTemplateExists() {
assertThatThrownBy(() -> new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(//
new ConnectorSettings.Builder().connectorTemplateId("non-existent").build())//
assertThatThrownBy(() -> new CustomConnectorHandler(dataManager, applicationContext, iconDao).create(
new ConnectorSettings.Builder().connectorTemplateId("non-existent").build())
).isInstanceOf(EntityNotFoundException.class).hasMessage("Connector template: non-existent");
}

Expand Down

0 comments on commit 987874e

Please sign in to comment.