本文整理汇总了Java中org.apache.commons.rdf.api.IRI类的典型用法代码示例。如果您正苦于以下问题:Java IRI类的具体用法?Java IRI怎么用?Java IRI使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IRI类属于org.apache.commons.rdf.api包,在下文中一共展示了IRI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testResource2
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testResource2() {
final IRI subject = rdf.createIRI("ex:subject");
when(mockResource.stream()).thenAnswer((x) -> of(
rdf.createQuad(prefer, subject, DC.title, rdf.createLiteral("A title")),
rdf.createQuad(PreferUserManaged, subject, DC.title, rdf.createLiteral("Other title"))));
assertEquals(1L, mockResource.stream(prefer).count());
assertEquals(1L, mockResource.stream(singleton(prefer)).count());
assertFalse(mockResource.getMembershipResource().isPresent());
assertFalse(mockResource.getMemberRelation().isPresent());
assertFalse(mockResource.getMemberOfRelation().isPresent());
assertFalse(mockResource.getInsertedContentRelation().isPresent());
assertFalse(mockResource.getMemberRelation().isPresent());
assertFalse(mockResource.getBinary().isPresent());
assertFalse(mockResource.isMemento());
assertFalse(mockResource.getInbox().isPresent());
assertFalse(mockResource.getAnnotationService().isPresent());
}
示例2: testPutLdpNRDescription2
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testPutLdpNRDescription2() {
when(mockResource.getBinary()).thenReturn(of(testBinary));
when(mockLdpRequest.getContentType()).thenReturn(TEXT_TURTLE);
final File entity = new File(getClass().getResource("/simpleLiteral.ttl").getFile());
final PutHandler putHandler = new PutHandler(mockLdpRequest, entity, mockResourceService,
mockIoService, mockBinaryService, null);
final Response res = putHandler.setResource(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.NonRDFSource)));
verify(mockBinaryService, never()).setContent(any(IRI.class), any(InputStream.class));
verify(mockIoService).read(any(InputStream.class), anyString(), any(RDFSyntax.class));
}
示例3: testInternalExternal
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testInternalExternal() {
final String baseUrl = "http://example.com/";
final IRI external = rdf.createIRI(baseUrl + "repository/resource");
final IRI internal = rdf.createIRI("trellis:repository/resource");
final IRI other = rdf.createIRI("http://example.org/repository/resource");
assertEquals(internal, mockResourceService.toInternal(external, baseUrl));
assertEquals(external, mockResourceService.toExternal(internal, baseUrl));
assertEquals(other, mockResourceService.toInternal(other, baseUrl));
assertEquals(other, mockResourceService.toExternal(other, baseUrl));
final BlankNode bnode = rdf.createBlankNode();
assertEquals(bnode, mockResourceService.toInternal(bnode, baseUrl));
assertEquals(bnode, mockResourceService.toExternal(bnode, baseUrl));
final Literal literal = rdf.createLiteral("A literal");
assertEquals(literal, mockResourceService.toInternal(literal, baseUrl));
assertEquals(literal, mockResourceService.toExternal(literal, baseUrl));
}
示例4: read
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
/**
* Read the state of the resource data at a particular point in time
* @param directory the directory
* @param identifier the identifier
* @param time the time
* @return the resource data, if it exists
*/
public static Optional<ResourceData> read(final File directory, final IRI identifier, final Instant time) {
LOGGER.debug("Reading journal to generate the resource data");
return of(new File(directory, RESOURCE_JOURNAL)).filter(File::exists).flatMap(file -> {
final List<Instant> mementos = new ArrayList<>();
final List<VersionRange> ranges = asTimeMap(file);
ranges.stream().map(VersionRange::getFrom).findFirst().ifPresent(mementos::add);
ranges.stream().map(VersionRange::getUntil).forEachOrdered(mementos::add);
try (final Stream<Quad> stream = asStream(rdf, file, identifier, time)) {
try (final Dataset dataset = stream.filter(isResourceTriple).collect(toDataset())) {
LOGGER.debug("Creating resource: {} at {}", identifier, time);
return from(identifier, dataset, mementos);
} catch (final Exception ex) {
throw new RuntimeTrellisException("Error processing dataset", ex);
}
}
});
}
示例5: testPutLdpResourceDefaultType
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testPutLdpResourceDefaultType() {
when(mockLdpRequest.getLink()).thenReturn(fromUri(LDP.Resource.getIRIString()).rel("type").build());
when(mockLdpRequest.getContentType()).thenReturn(TEXT_TURTLE);
final File entity = new File(getClass().getResource("/simpleTriple.ttl").getFile());
final PutHandler putHandler = new PutHandler(mockLdpRequest, entity, mockResourceService,
mockIoService, mockBinaryService, null);
final Response res = putHandler.setResource(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.NonRDFSource)));
verify(mockBinaryService, never()).setContent(any(IRI.class), any(InputStream.class));
verify(mockIoService).read(any(InputStream.class), eq(baseUrl + "resource"), eq(TURTLE));
}
示例6: testExport
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testExport() {
final Set<IRI> graphs = new HashSet<>();
graphs.add(Trellis.PreferAccessControl);
graphs.add(Trellis.PreferAudit);
graphs.add(Trellis.PreferServerManaged);
graphs.add(Trellis.PreferUserManaged);
when(mockResource.getIdentifier()).thenReturn(existing);
when(mockResource.stream(eq(graphs))).thenAnswer(inv ->
Stream.of(rdf.createTriple(existing, DC.title, rdf.createLiteral("A title"))));
final ResourceService svc = new MyResourceService(curator.getConnectString(), null, null);
final List<Quad> export = svc.export(graphs).collect(toList());
assertEquals(1L, export.size());
assertEquals(of(existing), export.get(0).getGraphName());
assertEquals(existing, export.get(0).getSubject());
assertEquals(DC.title, export.get(0).getPredicate());
assertEquals(rdf.createLiteral("A title"), export.get(0).getObject());
}
示例7: testPutLdpResourceEmpty
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testPutLdpResourceEmpty() {
final File entity = new File(getClass().getResource("/emptyData.txt").getFile());
final PutHandler putHandler = new PutHandler(mockLdpRequest, entity, mockResourceService,
mockIoService, mockBinaryService, null);
final Response res = putHandler.setResource(mockResource).build();
assertEquals(NO_CONTENT, res.getStatusInfo());
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.Resource)));
assertTrue(res.getLinks().stream().anyMatch(hasType(LDP.RDFSource)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.Container)));
assertFalse(res.getLinks().stream().anyMatch(hasType(LDP.NonRDFSource)));
verify(mockBinaryService, never()).setContent(any(IRI.class), any(InputStream.class));
verify(mockIoService).read(any(InputStream.class), anyString(), any(RDFSyntax.class));
}
示例8: testResource2
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testResource2() {
final IRI subject = rdf.createIRI("ex:subject");
when(mockResource.stream()).thenAnswer((x) -> of(
rdf.createQuad(prefer, subject, DC.title, rdf.createLiteral("A title")),
rdf.createQuad(PreferUserManaged, subject, DC.title, rdf.createLiteral("Other title"))));
assertEquals(1L, mockResource.stream(prefer).count());
assertEquals(1L, mockResource.stream(singleton(prefer)).count());
assertFalse(mockResource.getMembershipResource().isPresent());
assertFalse(mockResource.getMemberRelation().isPresent());
assertFalse(mockResource.getMemberOfRelation().isPresent());
assertFalse(mockResource.getInsertedContentRelation().isPresent());
assertFalse(mockResource.getMemberRelation().isPresent());
assertFalse(mockResource.getBinary().isPresent());
assertFalse(mockResource.isMemento());
assertFalse(mockResource.getExtraLinkRelations().findFirst().isPresent());
assertFalse(mockResource.isDeleted());
}
示例9: testGetResolver
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testGetResolver() {
final Properties props = new Properties();
props.setProperty("prefix", "file:");
final Map<String, Properties> config = new HashMap<>();
config.put("repository", props);
final BinaryService.Resolver resolver = new FileResolver(emptyMap());
final IRI fileIRI = rdf.createIRI("file:a_file_resource");
final BinaryService service = new DefaultBinaryService(mockIdService, config, asList(resolver));
assertEquals(of(resolver), service.getResolver(fileIRI));
assertEquals(of(resolver), service.getResolverForPartition("repository"));
assertFalse(service.getResolver(rdf.createIRI("test:ex")).isPresent());
assertFalse(service.getResolverForPartition("blah").isPresent());
}
示例10: checkCardinality
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
private static Predicate<Graph> checkCardinality(final IRI model) {
return graph -> {
final Map<IRI, Long> cardinality = graph.stream()
.filter(triple -> propertiesWithUriRange.contains(triple.getPredicate()))
.collect(groupingBy(Triple::getPredicate, counting()));
if (LDP.IndirectContainer.equals(model)) {
if (isNull(cardinality.get(LDP.insertedContentRelation)) || !hasMembershipProps(cardinality)) {
return true;
}
} else if (LDP.DirectContainer.equals(model) && !hasMembershipProps(cardinality)) {
return true;
}
return cardinality.entrySet().stream().map(Map.Entry::getValue).anyMatch(val -> val > 1);
};
}
示例11: testPurge
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testPurge() throws Exception {
final Map<String, String> myPartitions = singletonMap("repository",
new File(getClass().getResource("/purgeable").toURI()).getAbsolutePath());
service = new FileResourceService(myPartitions, partitionUrls, curator, mockProducer, mockEventService,
mockIdSupplier, false);
assertTrue(service.get(identifier).isPresent());
final List<IRI> binaries = service.purge(identifier).collect(toList());
assertEquals(1L, binaries.size());
assertEquals(rdf.createIRI("s3://bucket/some-resource"), binaries.get(0));
assertFalse(service.get(identifier).isPresent());
assertTrue(service.get(testResource).isPresent());
assertEquals(0L, service.purge(testResource).count());
assertFalse(service.get(testResource).isPresent());
}
示例12: setUp
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@BeforeEach
public void setUp() {
initMocks(this);
when(mockBinaryService.getIdentifierSupplier()).thenReturn(() -> "file:" + randomUUID());
when(mockResourceService.put(any(IRI.class), any(IRI.class), any(Dataset.class)))
.thenReturn(completedFuture(true));
when(mockResourceService.skolemize(any(Literal.class))).then(returnsFirstArg());
when(mockResourceService.skolemize(any(IRI.class))).then(returnsFirstArg());
when(mockResourceService.skolemize(any(BlankNode.class))).thenAnswer(inv ->
rdf.createIRI(TRELLIS_BNODE_PREFIX + ((BlankNode) inv.getArgument(0)).uniqueReference()));
when(mockRequest.getSession()).thenReturn(new HttpSession());
when(mockRequest.getPath()).thenReturn("");
when(mockRequest.getBaseUrl()).thenReturn(baseUrl);
when(mockResourceService.toInternal(any(RDFTerm.class), any())).thenAnswer(inv -> {
final RDFTerm term = (RDFTerm) inv.getArgument(0);
if (term instanceof IRI) {
final String iri = ((IRI) term).getIRIString();
if (iri.startsWith(baseUrl)) {
return rdf.createIRI(TRELLIS_PREFIX + iri.substring(baseUrl.length()));
}
}
return term;
});
}
示例13: testNotification
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testNotification() {
final IRI resource = rdf.createIRI(identifier);
final Dataset dataset = rdf.createDataset();
dataset.add(rdf.createQuad(Trellis.PreferUserManaged, resource, LDP.inbox, inbox));
dataset.add(rdf.createQuad(Trellis.PreferAudit, rdf.createBlankNode(), PROV.wasAssociatedWith, agent));
dataset.add(rdf.createQuad(Trellis.PreferServerManaged, resource, type, LDP.RDFSource));
dataset.add(rdf.createQuad(Trellis.PreferUserManaged, resource, type, SKOS.Concept));
dataset.add(rdf.createQuad(Trellis.PreferAudit, rdf.createBlankNode(), type, PROV.Activity));
dataset.add(rdf.createQuad(Trellis.PreferAudit, rdf.createBlankNode(), type, AS.Create));
final Instant time = now();
final Notification event = new Notification(identifier, dataset);
assertFalse(time.isAfter(event.getCreated()));
assertTrue(event.getIdentifier().getIRIString().startsWith("urn:uuid:"));
assertEquals(of(resource), event.getTarget());
assertEquals(of(inbox), event.getInbox());
assertEquals(1L, event.getAgents().size());
assertTrue(event.getAgents().contains(agent));
final Collection<IRI> targetTypes = event.getTargetTypes();
assertEquals(2L, targetTypes.size());
assertTrue(targetTypes.contains(LDP.RDFSource));
assertTrue(targetTypes.contains(SKOS.Concept));
final Collection<IRI> eventTypes = event.getTypes();
assertEquals(2L, eventTypes.size());
assertTrue(eventTypes.contains(AS.Create));
assertTrue(eventTypes.contains(PROV.Activity));
}
示例14: getSubject
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
/**
* Get the subject of the triple as a string.
*
* @return a string form of the subject
*/
public String getSubject() {
if (triple.getSubject() instanceof IRI) {
return ((IRI) triple.getSubject()).getIRIString();
}
return triple.getSubject().ntriplesString();
}
示例15: testMultipartPostInterruptedExecutionError
import org.apache.commons.rdf.api.IRI; //导入依赖的package包/类
@Test
public void testMultipartPostInterruptedExecutionError() throws Exception {
when(mockResourceService.put(any(IRI.class), any(IRI.class), any(Dataset.class)))
.thenReturn(mockFuture);
doThrow(InterruptedException.class).when(mockFuture).get();
final BinaryService.MultipartUpload upload = new BinaryService.MultipartUpload(BASE_URL, BINARY_PATH,
new HttpSession(), mockBinary);
when(mockBinaryResolver.uploadSessionExists(eq(UPLOAD_SESSION_ID))).thenReturn(true);
when(mockBinaryResolver.completeUpload(eq(UPLOAD_SESSION_ID), any())).thenReturn(upload);
final Response res = target("upload/" + UPLOAD_SESSION_ID).request()
.post(entity("{\"20\": \"value\"}", APPLICATION_JSON_TYPE));
assertEquals(INTERNAL_SERVER_ERROR, res.getStatusInfo());
}