Search in sources :

Example 1 with Container

use of org.apache.jena.rdf.model.Container in project jena by apache.

the class AbstractContainerMethods method testContainerOfIntegers.

public void testContainerOfIntegers() {
    final int num = 10;
    final Container c = createContainer();
    for (int i = 0; i < num; i += 1) {
        c.add(i);
    }
    Assert.assertEquals(num, c.size());
    final NodeIterator it = c.iterator();
    for (int i = 0; i < num; i += 1) {
        Assert.assertEquals(i, ((Literal) it.nextNode()).getInt());
    }
    Assert.assertFalse(it.hasNext());
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) Container(org.apache.jena.rdf.model.Container)

Example 2 with Container

use of org.apache.jena.rdf.model.Container in project jena by apache.

the class AbstractContainerMethods method testContainerOfIntegersWithRemoving.

protected void testContainerOfIntegersWithRemoving(final boolean[] retain) {
    final int num = retain.length;
    final boolean[] found = new boolean[num];
    final Container c = createContainer();
    for (int i = 0; i < num; i += 1) {
        c.add(i);
    }
    final NodeIterator it = c.iterator();
    for (boolean aRetain : retain) {
        it.nextNode();
        if (aRetain == false) {
            it.remove();
        }
    }
    final NodeIterator s = c.iterator();
    while (s.hasNext()) {
        final int v = ((Literal) s.nextNode()).getInt();
        Assert.assertFalse(found[v]);
        found[v] = true;
    }
    for (int i = 0; i < num; i += 1) {
        Assert.assertEquals("element " + i, retain[i], found[i]);
    }
}
Also used : NodeIterator(org.apache.jena.rdf.model.NodeIterator) Container(org.apache.jena.rdf.model.Container) Literal(org.apache.jena.rdf.model.Literal)

Example 3 with Container

use of org.apache.jena.rdf.model.Container in project jena by apache.

the class SecuredContainerTest method setup.

@Override
@Before
public void setup() {
    super.setup();
    final Container container = baseModel.getBag("http://example.com/testContainer");
    container.add("SomeDummyItem");
    setSecuredRDFNode(SecuredContainerImpl.getInstance(securedModel, container), container);
}
Also used : Container(org.apache.jena.rdf.model.Container) SecuredContainer(org.apache.jena.permissions.model.SecuredContainer) Before(org.junit.Before)

Example 4 with Container

use of org.apache.jena.rdf.model.Container in project jena by apache.

the class AbstractContainerMethods method testFillingContainer.

public void testFillingContainer() {
    final Container c = createContainer();
    final String lang = "fr";
    final Literal tvLiteral = model.createLiteral("test 12 string 2");
    // Resource tvResObj = model.createResource( new ResTestObjF() );
    c.add(AbstractModelTestBase.tvBoolean);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvBoolean));
    c.add(AbstractModelTestBase.tvByte);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvByte));
    c.add(AbstractModelTestBase.tvShort);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvShort));
    c.add(AbstractModelTestBase.tvInt);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvInt));
    c.add(AbstractModelTestBase.tvLong);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvLong));
    c.add(AbstractModelTestBase.tvChar);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvChar));
    c.add(AbstractModelTestBase.tvFloat);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvFloat));
    c.add(AbstractModelTestBase.tvString);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvString));
    c.add(AbstractModelTestBase.tvString, lang);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvString, lang));
    c.add(tvLiteral);
    Assert.assertTrue(c.contains(tvLiteral));
    // c.add( tvResObj ); assertTrue( c.contains( tvResObj ) );
    c.add(AbstractModelTestBase.tvLitObj);
    Assert.assertTrue(c.contains(AbstractModelTestBase.tvLitObj));
    Assert.assertEquals(11, c.size());
}
Also used : Container(org.apache.jena.rdf.model.Container) Literal(org.apache.jena.rdf.model.Literal)

Example 5 with Container

use of org.apache.jena.rdf.model.Container in project jena by apache.

the class AbstractContainerMethods method testEmptyContainer.

public void testEmptyContainer() {
    final Container c = createContainer();
    Assert.assertTrue(model.contains(c, RDF.type, getContainerType()));
    Assert.assertEquals(0, c.size());
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvBoolean));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvByte));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvShort));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvInt));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvLong));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvChar));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvFloat));
    Assert.assertFalse(c.contains(AbstractModelTestBase.tvString));
}
Also used : Container(org.apache.jena.rdf.model.Container)

Aggregations

Container (org.apache.jena.rdf.model.Container)5 Literal (org.apache.jena.rdf.model.Literal)2 NodeIterator (org.apache.jena.rdf.model.NodeIterator)2 SecuredContainer (org.apache.jena.permissions.model.SecuredContainer)1 Before (org.junit.Before)1