Search in sources :

Example 1 with ModelData

use of io.syndesis.common.model.ModelData in project syndesis by syndesisio.

the class ReadApiClientDataTest method tokenReplacementDataTest.

@Test
public void tokenReplacementDataTest() throws IOException {
    final String fileName = "io/syndesis/server/dao/test-data.json";
    final Map<String, String> env = new HashMap<>();
    env.put("POSTGRESQL_SAMPLEDB_PASSWORD", "password123");
    try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)) {
        ReadApiClientData readApiClientData = new ReadApiClientData();
        String jsonText = readApiClientData.from(is);
        jsonText = readApiClientData.findAndReplaceTokens(jsonText, env);
        Assert.assertTrue(jsonText.contains("@SECRET_NOT_IN_ENV@"));
        Assert.assertFalse(jsonText.contains("@POSTGRESQL_SAMPLEDB_PASSWORD@"));
        // passing in the updated String with replaced tokens
        List<ModelData<?>> modelDataList = readApiClientData.readDataFromString(jsonText);
        Assert.assertTrue("We should find some ModelData", 0 < modelDataList.size());
        // the second item is the sampledb-connection
        Connection connection = (Connection) modelDataList.get(1).getData();
        String pw = connection.getConfiguredProperties().get("password");
        Assert.assertEquals("password123", pw);
    }
}
Also used : ModelData(io.syndesis.common.model.ModelData) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Connection(io.syndesis.common.model.connection.Connection) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData) Test(org.junit.Test)

Example 2 with ModelData

use of io.syndesis.common.model.ModelData in project syndesis by syndesisio.

the class ReadApiClientDataTest method loadApiClientDataTest.

@Test
public void loadApiClientDataTest() throws IOException {
    List<ModelData<?>> modelDataList = new ReadApiClientData().readDataFromFile("io/syndesis/server/dao/deployment.json");
    Assert.assertTrue("We should find some ModelData", 0 < modelDataList.size());
    List<Object> items = new ArrayList<>();
    for (ModelData<?> md : modelDataList) {
        if (md.getKind() == Kind.ConnectorTemplate) {
            items.add(md.getData());
        }
    }
    Assert.assertFalse("We should find some Connectors", items.isEmpty());
}
Also used : ModelData(io.syndesis.common.model.ModelData) ArrayList(java.util.ArrayList) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData) Test(org.junit.Test)

Example 3 with ModelData

use of io.syndesis.common.model.ModelData in project syndesis by syndesisio.

the class ReadApiClientDataTest method deserializeModelDataTest.

@Test
public void deserializeModelDataTest() throws IOException {
    Integration integrationIn = new Integration.Builder().tags(new TreeSet<>(Arrays.asList("tag1", "tag2"))).createdAt(System.currentTimeMillis()).build();
    String integrationJson = Json.writer().writeValueAsString(integrationIn);
    Integration integrationOut = Json.reader().forType(Integration.class).readValue(integrationJson);
    // serialize
    ConnectorGroup cg = new ConnectorGroup.Builder().id("label").name("label").build();
    ModelData<ConnectorGroup> mdIn = new ModelData<>(Kind.ConnectorGroup, cg);
    Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdIn.getDataAsJson());
    // deserialize
    String json = Json.writer().writeValueAsString(mdIn);
    ModelData<?> mdOut = Json.reader().forType(ModelData.class).readValue(json);
    Assert.assertEquals("{\"id\":\"label\",\"name\":\"label\"}", mdOut.getDataAsJson());
}
Also used : ModelData(io.syndesis.common.model.ModelData) Integration(io.syndesis.common.model.integration.Integration) ConnectorGroup(io.syndesis.common.model.connection.ConnectorGroup) Test(org.junit.Test)

Example 4 with ModelData

use of io.syndesis.common.model.ModelData in project syndesis by syndesisio.

the class T3stSupportITCase method createAndGetIntegration.

@Test
public void createAndGetIntegration() {
    // Reset to fresh startup state..
    get("/api/v1/test-support/reset-db", Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // We should have some initial data in the snapshot since we start up with deployment.json
    @SuppressWarnings({ "unchecked", "rawtypes" }) Class<ModelData<?>[]> type = (Class) ModelData[].class;
    ResponseEntity<ModelData<?>[]> r1 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r1.getBody().length).isGreaterThan(1);
    // restoring to no data should.. leave us with no data.
    ModelData<?>[] noData = new ModelData<?>[] {};
    post("/api/v1/test-support/restore-db", noData, (Class<?>) null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Lets add an integration...
    Integration integration = new Integration.Builder().id("3001").name("test").build();
    post("/api/v1/integrations", integration, Integration.class);
    // Snapshot should only contain the integration entity..
    ResponseEntity<ModelData<?>[]> r2 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r2.getBody()).isNotEmpty();
    long r2Integrations = Arrays.stream(r2.getBody()).filter(b -> b.getKind() == Kind.Integration).count();
    assertThat(r2Integrations).isEqualTo(1);
    // Reset to fresh startup state..
    get("/api/v1/test-support/reset-db", Void.class, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Verify that the new state has the same number of entities as the original
    ResponseEntity<ModelData<?>[]> r3 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r3.getBody().length).isEqualTo(r1.getBody().length);
    // restoring 1 item of data
    post("/api/v1/test-support/restore-db", r2.getBody(), (Class<?>) null, tokenRule.validToken(), HttpStatus.NO_CONTENT);
    // Snapshot should only contain the integration entity..
    ResponseEntity<ModelData<?>[]> r4 = get("/api/v1/test-support/snapshot-db", type);
    assertThat(r4.getBody()).isNotEmpty();
    long r4Integrations = Arrays.stream(r4.getBody()).filter(b -> b.getKind() == Kind.Integration).count();
    assertThat(r4Integrations).isEqualTo(1);
}
Also used : ModelData(io.syndesis.common.model.ModelData) HttpStatus(org.springframework.http.HttpStatus) Arrays(java.util.Arrays) Kind(io.syndesis.common.model.Kind) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) ResponseEntity(org.springframework.http.ResponseEntity) Integration(io.syndesis.common.model.integration.Integration) ModelData(io.syndesis.common.model.ModelData) Integration(io.syndesis.common.model.integration.Integration) Test(org.junit.Test)

Example 5 with ModelData

use of io.syndesis.common.model.ModelData in project syndesis by syndesisio.

the class Application method generateIntegrationProject.

private void generateIntegrationProject(File project) throws IOException {
    final ReadApiClientData reader = new ReadApiClientData();
    final ArrayList<Step> steps = new ArrayList<>();
    String deploymentText;
    try (InputStream is = resourceLoader.getResource("io/syndesis/server/dao/deployment.json").getInputStream()) {
        deploymentText = reader.from(is);
    }
    final List<ModelData<?>> modelList = reader.readDataFromString(deploymentText);
    for (final ModelData<?> model : modelList) {
        if (model.getKind() == Kind.Connector) {
            final Connector connector = (Connector) model.getData();
            for (final Action action : connector.getActions()) {
                steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
            }
        }
        if (model.getKind() == Kind.ConnectorTemplate) {
            final ConnectorTemplate template = (ConnectorTemplate) model.getData();
            steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connectorId("connector-" + template.getId()).build()).action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().camelConnectorGAV(template.getCamelConnectorGAV()).camelConnectorPrefix(template.getCamelConnectorPrefix()).build()).build()).build());
        }
    }
    try {
        final ResourcePatternResolver resolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader);
        final Resource[] resources = resolver.getResources("classpath:/META-INF/syndesis/connector/*.json");
        if (resources != null) {
            for (Resource resource : resources) {
                Connector connector = Json.reader().forType(Connector.class).readValue(resource.getInputStream());
                if (connector != null) {
                    for (final Action action : connector.getActions()) {
                        steps.add(new Step.Builder().stepKind(StepKind.endpoint).connection(new Connection.Builder().connector(connector).connectorId(connector.getId().get()).build()).action(action).build());
                    }
                }
            }
        }
    } catch (FileNotFoundException ignored) {
    // ignore
    }
    Integration integration = new Integration.Builder().id("Integration").name("Integration").description("This integration is used to prime the .m2 repo").steps(steps).build();
    generate(integration, project);
}
Also used : ModelData(io.syndesis.common.model.ModelData) Connector(io.syndesis.common.model.connection.Connector) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) Integration(io.syndesis.common.model.integration.Integration) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) FileNotFoundException(java.io.FileNotFoundException) Step(io.syndesis.common.model.integration.Step) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ReadApiClientData(io.syndesis.server.dao.init.ReadApiClientData)

Aggregations

ModelData (io.syndesis.common.model.ModelData)6 ReadApiClientData (io.syndesis.server.dao.init.ReadApiClientData)4 Test (org.junit.Test)4 Integration (io.syndesis.common.model.integration.Integration)3 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)2 Connection (io.syndesis.common.model.connection.Connection)2 Connector (io.syndesis.common.model.connection.Connector)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Kind (io.syndesis.common.model.Kind)1 Action (io.syndesis.common.model.action.Action)1 ConnectorGroup (io.syndesis.common.model.connection.ConnectorGroup)1 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)1 Step (io.syndesis.common.model.integration.Step)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1