TypesHandler implements Types { @Override public Set<Axiom<URI>> getTypes(NamedResource individual, URI context, boolean includeInferred) { final Collection<Statement> statements = getStatements(individual, context, includeInferred); final Assertion assertion = Assertion.createClassAssertion(includeInferred); return statements.stream().filter(s -> s.getObject().isResource() && !s.getObject().isAnon()) .map(s -> new AxiomImpl<>(individual, assertion, new Value<>(URI.create(s.getObject().asResource().getURI())))).collect( Collectors.toSet()); } TypesHandler(StorageConnector connector, InferredStorageConnector inferenceConnector); @Override Set<Axiom<URI>> getTypes(NamedResource individual, URI context, boolean includeInferred); @Override void addTypes(NamedResource individual, URI context, Set<URI> types); @Override void removeTypes(NamedResource individual, URI context, Set<URI> types);  }
@Test public void getTypesLoadsTypesFromStorage() { final Set<Statement> statements = generateTypesStatements(); final Set<Axiom<URI>> result = handler.getTypes(SUBJECT, null, false); verifyLoadedTypes(statements, result, false); verify(inferredConnectorMock, never()).findWithInference(any(), any(), any(), anyString()); verify(connectorMock).find(SUBJECT_RESOURCE, RDF.type, null, null); }
@Test public void getTypesLoadsTypesFromContext() { final URI context = Generator.generateUri(); final Set<Statement> statements = generateTypesStatements(); final Set<Axiom<URI>> result = handler.getTypes(SUBJECT, context, false); verifyLoadedTypes(statements, result, false); verify(connectorMock).find(SUBJECT_RESOURCE, RDF.type, null, context.toString()); }
@Test public void getTypesLoadsTypesWithInferenceWhenInferredSwitchIsOn() { final Set<Statement> statements = statementsForTypes(); when(inferredConnectorMock.findWithInference(any(), any(), any(), any())).thenReturn(statements); final Set<Axiom<URI>> result = handler.getTypes(SUBJECT, null, true); verifyLoadedTypes(statements, result, true); verify(connectorMock, never()).find(SUBJECT_RESOURCE, RDF.type, null, null); verify(inferredConnectorMock).findWithInference(SUBJECT_RESOURCE, RDF.type, null, null); }