SimpleApplicationWrapper implements ApplicationWrapper { @Activate protected void start(Map<String, Object> props) { ApplicationConfig config = Configurable.createConfigurable(ApplicationConfig.class, props); LOG.trace("Starting \"" + config.id() + "\" application..."); validateConfig(props); this.applicationId = config.id(); Application application = appFactory.createNew(factory.createIRI(NAMESPACE + applicationId)); application.setProperty(factory.createLiteral(config.title()), factory.createIRI(DCTERMS.TITLE.stringValue())); if (config.description() != null && !config.description().equals("")) { application.setProperty(factory.createLiteral(config.description()), factory.createIRI(DCTERMS.DESCRIPTION.stringValue())); } try (RepositoryConnection conn = repository.getConnection()) { if (conn.contains(application.getResource(), null, null)) { LOG.warn("Replacing existing application \"" + applicationId + "\"."); conn.remove(application.getResource(), null, null); } conn.add(application.getModel()); } LOG.debug("Application \"" + applicationId + "\" started."); }  @Override void validateConfig(Map<String, Object> props); @Override String getId(); @Override Application getApplication();  }
@Test public void startTest() throws Exception { Map<String, Object> props = new HashMap<>(); props.put("id", "id"); props.put("title", "Title"); props.put("description", "Description"); wrapper.start(props); assertEquals(props.get("id").toString(), wrapper.applicationId); RepositoryConnection conn = repo.getConnection(); Model appModel = MODEL_FACTORY.createModel(); Resource appIri = VALUE_FACTORY.createIRI(namespace + props.get("id")); conn.getStatements(appIri, null, null).forEach(appModel::add); assertFalse(appModel.isEmpty()); assertTrue(appModel.contains(appIri, VALUE_FACTORY.createIRI(RDF.TYPE.stringValue()), VALUE_FACTORY.createIRI(Application.TYPE))); assertTrue(appModel.contains(appIri, VALUE_FACTORY.createIRI(DCTERMS.TITLE.stringValue()), VALUE_FACTORY.createLiteral(props.get("title").toString()))); assertTrue(appModel.contains(appIri, VALUE_FACTORY.createIRI(DCTERMS.DESCRIPTION.stringValue()), VALUE_FACTORY.createLiteral(props.get("description").toString()))); conn.close(); }