/** Validate that the expected Properties Models were found */ private void validatePropertiesModels(GraphContext context) throws Exception { GraphService<PropertiesModel> service = new GraphService<>(context, PropertiesModel.class); int numberFound = 0; for (PropertiesModel model : service.findAll()) { numberFound++; Properties props = model.getProperties(); Assert.assertEquals("value1", props.getProperty("example1")); Assert.assertEquals("anothervalue", props.getProperty("anotherproperty")); Assert.assertEquals("1234", props.getProperty("timetaken")); } Assert.assertEquals(1, numberFound); }
public void perform(GraphRewrite event, EvaluationContext context, FileModel payload) { GraphService<PropertiesModel> service = getPropertiesService(event.getGraphContext()); PropertiesModel properties = service.create(); properties.setFileResource(payload); try (InputStream is = payload.asInputStream()) { Properties props = new Properties(); props.load(is); for (Object key : props.keySet()) { String property = StringUtils.trim(key.toString()); String propertyValue = StringUtils.trim(props.get(key).toString()); properties.setProperty(property, propertyValue); } } catch (IOException e) { throw new WindupException( "Failed to load properties file: " + payload.getFilePath() + " due to: " + e.getMessage()); } }