public <T extends WithId<T>> void store(ModelData<T> modelData) { try { final Kind kind = modelData.getKind(); final T entity = modelData.getData(); LOGGER.debug("{}:{}", kind, modelData.getDataAsJson()); store(entity, kind.getModelClass()); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { LOGGER.warn("Cannot load entity from file: ", e); throw SyndesisServerException.launderThrowable(e); } }
@Test public void loadApiClientDataTest() throws IOException { List<ModelData<?>> modelDataList = new ReadApiClientData().readDataFromFile("io/syndesis/dao/deployment.json"); // System.out.println("Found " + modelDataList.size() + " entities."); Assert.assertTrue("We should find some ModelData", 0 < modelDataList.size()); List<Connector> connectorList = new ArrayList<>(); for (ModelData<?> md : modelDataList) { if (md.getKind() == Kind.Connector) { Connector cg = (Connector) md.getData(); connectorList.add(cg); } } // System.out.println("Found " + connectorList.size() + " Connectors"); Assert.assertTrue("We should find some Connectors", 0 < connectorList.size()); }
@Test public void tokenReplacementDataTest() throws IOException { final String fileName = "io/syndesis/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); // System.out.println("Found " + modelDataList.size() + " entities."); 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); } } }