예제 #1
0
  @Test
  public void testChildren() throws RepositoryException {
    when(mockRes1.getPath()).thenReturn(RDF_PATH + "/res1");
    when(mockRes2.getPath()).thenReturn(RDF_PATH + "/res2");
    when(mockRes3.getPath()).thenReturn(RDF_PATH + "/res3");
    when(mockResourceNode.hasNodes()).thenReturn(true);
    final Stream<FedoraResource> first = of(mockRes1, mockRes2, mockRes3);
    final Stream<FedoraResource> second = of(mockRes1, mockRes2, mockRes3);
    when(mockResource.getChildren()).thenReturn(first).thenReturn(second);

    try (final ChildrenRdfContext context = new ChildrenRdfContext(mockResource, idTranslator)) {
      final Model results = context.collect(toModel());
      final Resource subject = idTranslator.reverse().convert(mockResource);

      final StmtIterator stmts =
          results.listStatements(subject, RdfLexicon.HAS_CHILD_COUNT, (RDFNode) null);

      assertTrue("There should have been a statement!", stmts.hasNext());
      final Statement stmt = stmts.nextStatement();
      assertTrue("Object should be a literal! " + stmt.getObject(), stmt.getObject().isLiteral());
      assertEquals(3, stmt.getInt());

      assertFalse("There should not have been a second statement!", stmts.hasNext());
    }
  }
 public void testFindPropertyAndObject() {
   StmtIterator iter = model.listStatements(new SimpleSelector(null, RDF.value, 123));
   int i = 0;
   while (iter.hasNext()) {
     i++;
     Statement stmt = iter.nextStatement();
     assertEquals(RDF.value, stmt.getPredicate());
     assertEquals(123, stmt.getInt());
   }
   assertEquals(2, i);
 }
예제 #3
0
  @Test
  public void testNoChildren() throws RepositoryException {
    when(mockResourceNode.hasNodes()).thenReturn(false);

    try (final ChildrenRdfContext childrenRdfContext =
        new ChildrenRdfContext(mockResource, idTranslator)) {
      final Model results = childrenRdfContext.collect(toModel());
      final Resource subject = idTranslator.reverse().convert(mockResource);

      final StmtIterator stmts =
          results.listStatements(subject, RdfLexicon.HAS_CHILD_COUNT, (RDFNode) null);

      assertTrue("There should have been a statement!", stmts.hasNext());
      final Statement stmt = stmts.nextStatement();
      assertTrue("Object should be a literal! " + stmt.getObject(), stmt.getObject().isLiteral());
      assertEquals(0, stmt.getInt());

      assertFalse("There should not have been a second statement!", stmts.hasNext());
    }
  }
예제 #4
0
파일: Spec.java 프로젝트: mmmmmrob/Vertere
 public int[] getSourceColumns(Resource resource) {
   if (_model.contains(resource, Vertere.source_column)) {
     Statement sourceColumn = _model.getProperty(resource, Vertere.source_column);
     return new int[] {sourceColumn.getInt()};
   } else if (_model.contains(resource, Vertere.source_columns)) {
     Statement sourceColumns = _model.getProperty(resource, Vertere.source_columns);
     Resource listResource = sourceColumns.getResource();
     RDFList list = listResource.as(RDFList.class);
     List<RDFNode> javalist = list.asJavaList();
     int[] sourceColumnNumbers = new int[javalist.size()];
     for (int i = 0; i < javalist.size(); i++) {
       RDFNode node = javalist.get(i);
       Literal value = node.asLiteral();
       sourceColumnNumbers[i] = value.getInt();
     }
     return sourceColumnNumbers;
   } else {
     return new int[0];
   }
 }