SimpleStateManager implements StateManager { @Override public Model getState(Resource stateId) { if (!stateExists(stateId)) { throw new IllegalArgumentException("State not found"); } Model result = modelFactory.createModel(); Model stateModel = modelFactory.createModel(); try (RepositoryConnection conn = repository.getConnection()) { conn.getStatements(stateId, null, null).forEach(stateModel::add); stateModel.filter(stateId, factory.createIRI(State.stateResource_IRI), null).objects().forEach(value -> conn.getStatements((Resource) value, null, null).forEach(result::add)); return result; } }  @Override boolean stateExists(Resource stateId); @Override boolean stateExistsForUser(Resource stateId, String username); @Override Map<Resource, Model> getStates(@Nullable String username, @Nullable String applicationId,
                                          Set<Resource> subjects); @Override Resource storeState(Model newState, String username); @Override Resource storeState(Model newState, String username, String applicationId); @Override Model getState(Resource stateId); @Override void updateState(Resource stateId, Model newState); @Override void deleteState(Resource stateId);  }
@Test public void getStateTest() throws Exception { Model resources = MODEL_FACTORY.createModel(); resources.add(VALUE_FACTORY.createIRI("http: State state = stateFactory.createNew(VALUE_FACTORY.createIRI("http: state.setStateResource(Collections.singleton(VALUE_FACTORY.createIRI("http: RepositoryConnection conn = repo.getConnection(); conn.add(state.getModel()); conn.add(resources); Model result = manager.getState(state.getResource()); assertFalse(result.isEmpty()); assertTrue(result.containsAll(resources)); conn.close(); }
@Test public void getStateThatIsEmptyTest() throws Exception { State state = stateFactory.createNew(VALUE_FACTORY.createIRI("http: RepositoryConnection conn = repo.getConnection(); conn.add(state.getModel()); Model result = manager.getState(state.getResource()); assertTrue(result.isEmpty()); conn.close(); }
@Test(expected = IllegalArgumentException.class) public void getStateThatDoesNotExistTest() { manager.getState(VALUE_FACTORY.createIRI("http: }