Search in sources :

Example 21 with Connection

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

the class WebhookCustomizerTest method testOpenApiCustomizer.

@Test
public void testOpenApiCustomizer() throws Exception {
    TestResourceManager manager = new TestResourceManager();
    Connector connector;
    ConnectorAction webhookIncomingAction;
    try (InputStream is = WebhookCustomizerTest.class.getResourceAsStream("/META-INF/syndesis/connector/webhook.json")) {
        connector = JsonUtils.readFromStream(is, Connector.class);
        webhookIncomingAction = connector.getActions(ConnectorAction.class).stream().filter(a -> a.getId().get().equals("io.syndesis:webhook-incoming")).findFirst().orElseThrow(IllegalArgumentException::new);
    }
    webhookIncomingAction = webhookIncomingAction.builder().descriptor(new ConnectorDescriptor.Builder().connectorId("webhook").build()).build();
    Integration integration = manager.newIntegration(new Step.Builder().stepKind(StepKind.endpoint).putConfiguredProperty("contextPath", "token").action(webhookIncomingAction).connection(new Connection.Builder().connector(connector).build()).build());
    IntegrationDeployment deployment = new IntegrationDeployment.Builder().userId("user").id("idId").spec(integration).build();
    CamelKIntegrationCustomizer customizer = new WebhookCustomizer();
    io.syndesis.server.controller.integration.camelk.crd.Integration i = customizer.customize(deployment, new io.syndesis.server.controller.integration.camelk.crd.Integration(), EnumSet.of(Exposure.SERVICE));
    assertThat(i.getSpec().getConfiguration()).hasSize(1);
    assertThat(i.getSpec().getConfiguration()).anyMatch(c -> Objects.equals("customizer.platform-http.path=/webhook/", c.getValue()) && Objects.equals("property", c.getType()));
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Step(io.syndesis.common.model.integration.Step) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Connector(io.syndesis.common.model.connection.Connector) Test(org.junit.Test) Objects(java.util.Objects) JsonUtils(io.syndesis.common.util.json.JsonUtils) Connection(io.syndesis.common.model.connection.Connection) Exposure(io.syndesis.server.openshift.Exposure) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) EnumSet(java.util.EnumSet) InputStream(java.io.InputStream) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) Connector(io.syndesis.common.model.connection.Connector) Integration(io.syndesis.common.model.integration.Integration) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) IntegrationDeployment(io.syndesis.common.model.integration.IntegrationDeployment) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) TestResourceManager(io.syndesis.server.controller.integration.camelk.TestResourceManager) Test(org.junit.Test)

Example 22 with Connection

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

the class ApplicatorTest method shouldNotApplyNullOrEmptyPropertyValues.

@Test
public void shouldNotApplyNullOrEmptyPropertyValues() {
    final Connection.Builder connection = new Connection.Builder();
    Applicator.applyProperty(connection, "emptyProperty", "");
    Applicator.applyProperty(connection, "nullProperty", "");
    final Connection built = connection.build();
    assertThat(built.getConfiguredProperties()).isEmpty();
}
Also used : Connection(io.syndesis.common.model.connection.Connection) Test(org.junit.Test)

Example 23 with Connection

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

the class OAuth1ApplicatorTest method shouldApplyTokens.

@Test
public void shouldApplyTokens() {
    final SocialProperties properties = new SocialProperties() {
    };
    properties.setAppId("appId");
    properties.setAppSecret("appSecret");
    final OAuth1Applicator applicator = new OAuth1Applicator(properties);
    applicator.setAccessTokenSecretProperty("accessTokenSecretProperty");
    applicator.setAccessTokenValueProperty("accessTokenValueProperty");
    applicator.setConsumerKeyProperty("consumerKeyProperty");
    applicator.setConsumerSecretProperty("consumerSecretProperty");
    final Connection connection = new Connection.Builder().build();
    final Connection result = applicator.applyTo(connection, new OAuthToken("tokenValue", "tokenSecret"));
    final Connection expected = new Connection.Builder().putConfiguredProperty("accessTokenSecretProperty", "tokenSecret").putConfiguredProperty("accessTokenValueProperty", "tokenValue").putConfiguredProperty("consumerKeyProperty", "appId").putConfiguredProperty("consumerSecretProperty", "appSecret").build();
    assertThat(result).isEqualToIgnoringGivenFields(expected, "lastUpdated");
    assertThat(result.getLastUpdated()).isPresent();
}
Also used : OAuthToken(org.springframework.social.oauth1.OAuthToken) Connection(io.syndesis.common.model.connection.Connection) Test(org.junit.Test)

Example 24 with Connection

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

the class CredentialsTest method shouldApplyReceivedCredentialsToConnections.

@Test
public void shouldApplyReceivedCredentialsToConnections() {
    final CredentialProvider credentialProvider = mock(CredentialProvider.class);
    when(locator.providerWithId("providerId")).thenReturn(credentialProvider);
    final CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder().providerId("providerId").returnUrl(URI.create("/ui#state")).code("code").state("state").build();
    final Connection connection = new Connection.Builder().connector(new Connector.Builder().putProperty("key", new ConfigurationProperty.Builder().build()).build()).build();
    when(credentialProvider.applyTo(new Connection.Builder().createFrom(connection).isDerived(true).build(), flowState)).then(a -> new Connection.Builder().createFrom(a.getArgument(0)).putConfiguredProperty("key", "value").build());
    final Connection finishedConnection = credentials.apply(connection, flowState);
    assertThat(finishedConnection).isNotNull();
    assertThat(finishedConnection.getConfiguredProperties()).contains(entry("key", "value"));
    assertThat(finishedConnection.isDerived()).isTrue();
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connection(io.syndesis.common.model.connection.Connection) Test(org.junit.Test)

Example 25 with Connection

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

the class OAuth2Applicator method applyTo.

/**
 * Default implementation that applies {@link SocialProperties} and
 * {@link AccessGrant} to {@link Connection.Builder}.
 */
@Override
public final Connection applyTo(final Connection connection, final AccessGrant accessGrant) {
    final Connection.Builder mutableConnection = new Connection.Builder().createFrom(connection).lastUpdated(new Date());
    Applicator.applyProperty(mutableConnection, clientIdProperty, socialProperties.getAppId());
    Applicator.applyProperty(mutableConnection, clientSecretProperty, socialProperties.getAppSecret());
    Applicator.applyProperty(mutableConnection, accessTokenProperty, accessGrant.getAccessToken());
    Applicator.applyProperty(mutableConnection, refreshTokenProperty, accessGrant.getRefreshToken());
    final Long expireTime = accessGrant.getExpireTime();
    Applicator.applyProperty(mutableConnection, accessTokenExpiresAtProperty, expireTime == null ? null : expireTime.toString());
    additionalApplication(mutableConnection, accessGrant);
    return mutableConnection.build();
}
Also used : Connection(io.syndesis.common.model.connection.Connection) Date(java.util.Date)

Aggregations

Connection (io.syndesis.common.model.connection.Connection)111 Connector (io.syndesis.common.model.connection.Connector)65 Test (org.junit.Test)48 Step (io.syndesis.common.model.integration.Step)40 Integration (io.syndesis.common.model.integration.Integration)38 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)26 ConnectorDescriptor (io.syndesis.common.model.action.ConnectorDescriptor)26 List (java.util.List)24 HashMap (java.util.HashMap)21 Action (io.syndesis.common.model.action.Action)18 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)18 ArrayList (java.util.ArrayList)17 Map (java.util.Map)16 IOException (java.io.IOException)14 InputStream (java.io.InputStream)14 IntegrationDeployment (io.syndesis.common.model.integration.IntegrationDeployment)13 StepDefinition (io.syndesis.qe.bdd.entities.StepDefinition)12 DataManager (io.syndesis.server.dao.manager.DataManager)11 Given (cucumber.api.java.en.Given)10 Flow (io.syndesis.common.model.integration.Flow)10