public void testCreateListFromEmptyIterator() { RDFList list = model.createList(new ArrayList<RDFNode>().iterator()); Assert.assertEquals(0, list.size()); }
public void testCreateListFromEmptyIterator() { RDFList list = model.createList(new ArrayList<RDFNode>().iterator()); Assert.assertEquals(0, list.size()); }
@Override public RDFList append(final RDFList list) throws ReadDeniedException, AuthenticationRequiredException { if (holder.getBaseItem().isEmpty()) { return list.size() == 0 ? ModelFactory.createDefaultModel() .createList() : list.copy(); } else { final RDFList copy = copy(); if (list.size() > 0) { copy.concatenate(list.copy()); } return copy; } }
@Override public SecuredRDFList append(final Iterator<? extends RDFNode> nodes) throws ReadDeniedException, AuthenticationRequiredException { SecuredRDFList copy = copy(); if (nodes.hasNext()) { if (((RDFList) copy.getBaseItem()).size() > 0) { copy.concatenate(copy.getModel().createList(nodes)); } else { copy = copy.getModel().createList(nodes); } } return copy; }
public void testConcatenate() { model.read(getFileName("ontology/list5.rdf")); final Resource nil = model.getResource(RDF.nil.getURI()); RDFList list = nil.as(RDFList.class); final Resource r = model.createResource(TestList.NS + "foo"); // create a list of foos for (int i = 0; i < 5; i++) { list = list.cons(r); } final int listLen = list.size(); // now append foos to the root list final RDFList root = getListRoot(model); final int rootLen = root.size(); root.concatenate(list); // original list should be unchanged checkValid("concatTest0", list, true); Assert.assertEquals("Original list should be unchanged", listLen, list.size()); // but lhs list has changed checkValid("concatTest1", root, true); Assert.assertEquals("Root list should be new length", rootLen + listLen, root.size()); }
public void testCount() { for (int i = 0; i <= 5; i++) { model.removeAll(); model.read( getFileName("ontology/list" + i + ".rdf")); final RDFList l0 = getListRoot(model); Assert.assertEquals("List size should be " + i, i, l0.size()); } }
@Override public int size() throws ReadDeniedException, AuthenticationRequiredException { checkRead(); final Triple t = new Triple(Node.ANY, listFirst().asNode(), Node.ANY); if (canRead(t)) { return holder.getBaseItem().size(); } final ExtendedIterator<RDFNode> iter = iterator(); int i = 0; while (iter.hasNext()) { i++; iter.next(); } return i; }
public void testConcatenate() { model.read(getFileName("ontology/list5.rdf")); final Resource nil = model.getResource(RDF.nil.getURI()); RDFList list = nil.as(RDFList.class); final Resource r = model.createResource(TestList.NS + "foo"); // create a list of foos for (int i = 0; i < 5; i++) { list = list.cons(r); } final int listLen = list.size(); // now append foos to the root list final RDFList root = getListRoot(model); final int rootLen = root.size(); root.concatenate(list); // original list should be unchanged checkValid("concatTest0", list, true); Assert.assertEquals("Original list should be unchanged", listLen, list.size()); // but lhs list has changed checkValid("concatTest1", root, true); Assert.assertEquals("Root list should be new length", rootLen + listLen, root.size()); }
public void testCount() { for (int i = 0; i <= 5; i++) { model.removeAll(); model.read( getFileName("ontology/list" + i + ".rdf")); final RDFList l0 = getListRoot(model); Assert.assertEquals("List size should be " + i, i, l0.size()); } }
@Test public void testGet() { try { getSecuredRDFList().get(0); if (!securityEvaluator.evaluate(Action.Read)) { Assert.fail("Should have thrown ReadDeniedException Exception"); } } catch (final ReadDeniedException e) { if (securityEvaluator.evaluate(Action.Read)) { Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple())); } } catch (final ListIndexException e) { if (((RDFList) getBaseRDFNode()).size() < 0) { // acceptable exception } else { throw e; } } }
@Test public void testGetTail() { try { getSecuredRDFList().getTail(); if (!securityEvaluator.evaluate(Action.Read)) { Assert.fail("Should have thrown ReadDeniedException Exception"); } } catch (final ReadDeniedException e) { if (securityEvaluator.evaluate(Action.Read)) { Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple())); } } catch (final ListIndexException e) { if (((RDFList) getBaseRDFNode()).size() == 0) { // acceptable exception } else { throw e; } } }
@Test public void testGetHead() { try { getSecuredRDFList().getHead(); if (!securityEvaluator.evaluate(Action.Read)) { Assert.fail("Should have thrown ReadDeniedException Exception"); } } catch (final ReadDeniedException e) { if (securityEvaluator.evaluate(Action.Read)) { Assert.fail(String.format("Should not have thrown ReadDeniedException Exception: %s - %s", e, e.getTriple())); } } catch (final ListIndexException e) { if (((RDFList) getBaseRDFNode()).size() == 0) { // acceptable exception } else { throw e; } } }
public void testSetTail() { final Model m = ModelFactory.createDefaultModel(); final Resource root = m.createResource(TestList.NS + "root"); final Property p = m.createProperty(TestList.NS, "p"); final Resource nil = RDF.nil; m.add(nil, RDF.type, RDF.List); final Resource list0 = m.createResource(); m.add(list0, RDF.type, RDF.List); m.add(list0, RDF.first, "fred"); m.add(list0, RDF.rest, nil); m.add(root, p, list0); final RDFList l1 = getListRoot(m); checkValid("settail1", l1, true); final Resource list1 = m.createResource(); m.add(list1, RDF.type, RDF.List); m.add(list1, RDF.first, "george"); m.add(list1, RDF.rest, nil); final RDFList l2 = list1.as(RDFList.class); Assert.assertNotNull("as(RDFList) should not return null for root", l2); checkValid("settail2", l2, true); Assert.assertEquals("l1 should have length 1", 1, l1.size()); Assert.assertEquals("l2 should have length 1", 1, l2.size()); // use set tail to join the lists together l1.setTail(l2); checkValid("settail3", l1, true); checkValid("settail4", l2, true); Assert.assertEquals("l1 should have length 2", 2, l1.size()); Assert.assertEquals("l2 should have length 1", 1, l2.size()); }
@Test public void testAppendRDFList() { final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create }); try { getSecuredRDFList().append(baseModel.createList()); if (!securityEvaluator.evaluate(Action.Update)) { Assert.fail("Should have thrown UpdateDeniedException Exception"); } if (!securityEvaluator.evaluate(Action.Create) && (baseList.size() > 0 && securityEvaluator.evaluate(Action.Read))) { Assert.fail("Should have thrown AddDeniedException Exception"); } } catch (final AccessDeniedException e) { if (securityEvaluator.evaluate(perms)) { Assert.fail(String.format("Should not have thrown AccessDeniedException Exception: %s - %s", e, e.getTriple())); } } }
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); AllDifferent a = m.createAllDifferent(); OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addDistinctMember( b ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); a.addDistinctMember( c ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 2", 2, a.getDistinctMembers().size() ); iteratorTest( a.listDistinctMembers(), new Object[] {b, c} ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); assertTrue( "a should have c as distinct", a.hasDistinctMember( c ) ); a.setDistinctMembers( m.createList( new RDFNode[] {b} ) ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); assertTrue( "a should not have c as distinct", !a.hasDistinctMember( c ) ); a.removeDistinctMember( b ); assertTrue( "a should have not b as distinct", !a.hasDistinctMember( b ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); EnumeratedClass A = m.createEnumeratedClass( NS + "A", null ); OntResource a = m.getResource( NS + "a" ).as( OntResource.class ); OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); A.addOneOf( a ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have a as enumerated member", A.getOneOf().contains( a ) ); A.addOneOf( b ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 2", 2, A.getOneOf().size() ); iteratorTest( A.listOneOf(), new Object[] {a,b} ); A.setOneOf( m.createList( new RDFNode[] {b} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.ONE_OF() ) ); assertEquals( "Size should be 1", 1, A.getOneOf().size() ); assertTrue( "A should have b in the enum", A.hasOneOf( b ) ); assertTrue( "A should not have a in the enum", !A.hasOneOf( a ) ); A.removeOneOf( a ); assertTrue( "Should have b as an enum value", A.hasOneOf( b ) ); A.removeOneOf( b ); assertTrue( "Should not have b as an enum value", !A.hasOneOf( b ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); AllDifferent a = m.createAllDifferent(); OntResource b = m.getResource( NS + "b" ).as( OntResource.class ); OntResource c = m.getResource( NS + "c" ).as( OntResource.class ); a.addDistinctMember( b ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); a.addDistinctMember( c ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 2", 2, a.getDistinctMembers().size() ); iteratorTest( a.listDistinctMembers(), new Object[] {b, c} ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); assertTrue( "a should have c as distinct", a.hasDistinctMember( c ) ); a.setDistinctMembers( m.createList( new RDFNode[] {b} ) ); assertEquals( "Cardinality should be 1", 1, a.getCardinality( prof.DISTINCT_MEMBERS() ) ); assertEquals( "List size should be 1", 1, a.getDistinctMembers().size() ); assertTrue( "a should have b as distinct", a.hasDistinctMember( b ) ); assertTrue( "a should not have c as distinct", !a.hasDistinctMember( c ) ); a.removeDistinctMember( b ); assertTrue( "a should have not b as distinct", !a.hasDistinctMember( b ) ); } },
@Override public void ontTest( OntModel m ) { Profile prof = m.getProfile(); IntersectionClass A = m.createIntersectionClass( NS + "A", null ); OntClass B = m.createClass( NS + "B" ); OntClass C = m.createClass( NS + "C" ); A.addOperand( B ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have a as intersection member", A.getOperands().contains( B ) ); A.addOperand( C ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 2", 2, A.getOperands().size() ); iteratorTest( A.listOperands(), new Object[] {B,C} ); ClosableIterator<? extends Resource> i = A.listOperands(); assertTrue( "Argument should be an OntClass", i.next() instanceof OntClass ); i.close(); A.setOperands( m.createList( new RDFNode[] {C} ) ); assertEquals( "Cardinality should be 1", 1, A.getCardinality( prof.INTERSECTION_OF() ) ); assertEquals( "Size should be 1", 1, A.getOperands().size() ); assertTrue( "A should have C in the intersection", A.hasOperand( C ) ); assertTrue( "A should not have B in the intersection", !A.hasOperand( B ) ); A.removeOperand( B ); assertTrue( "Should have C as an operand", A.hasOperand( C ) ); A.removeOperand( C ); assertTrue( "Should not have C as an operand", !A.hasOperand( C ) ); } },
@Override public void ontTest( OntModel m ) { Literal x = m.createTypedLiteral( 42 ); Literal y = m.createTypedLiteral( true ); Literal z = m.createTypedLiteral( "life" ); RDFList lits = m.createList( new RDFNode[] {x,y} ); DataRange d0 = m.createDataRange( lits ); assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.removeOneOf( z ); assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.removeOneOf( x ); assertFalse( "datarange should not contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.addOneOf( z ); assertEquals( "datarange should be size 2", 2, d0.getOneOf().size() ); iteratorTest( d0.listOneOf(), new Object[] {y,z} ); d0.setOneOf( m.createList( new RDFNode[] {x} ) ); iteratorTest( d0.listOneOf(), new Object[] {x} ); } },
@Override public void ontTest( OntModel m ) { Literal x = m.createTypedLiteral( 42 ); Literal y = m.createTypedLiteral( true ); Literal z = m.createTypedLiteral( "life" ); RDFList lits = m.createList( new RDFNode[] {x,y} ); DataRange d0 = m.createDataRange( lits ); assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.removeOneOf( z ); assertTrue( "datarange should contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.removeOneOf( x ); assertFalse( "datarange should not contain x", d0.hasOneOf( x ) ); assertTrue( "datarange should contain y", d0.hasOneOf( y ) ); assertFalse( "datarange should not contain z", d0.hasOneOf( z ) ); d0.addOneOf( z ); assertEquals( "datarange should be size 2", 2, d0.getOneOf().size() ); iteratorTest( d0.listOneOf(), new Object[] {y,z} ); d0.setOneOf( m.createList( new RDFNode[] {x} ) ); iteratorTest( d0.listOneOf(), new Object[] {x} ); } },