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);
}
}
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());
}
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());
}
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);
}
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);
}
Aggregations