Package org.apache.marmotta.commons.sesame.facading.api

Examples of org.apache.marmotta.commons.sesame.facading.api.Facading


    @Ignore("currently fails for H2 database because of transaction locking")
    public void testParallelFacading() throws RepositoryException {
        final RepositoryConnection fc = repositoryRDF.getConnection();
        try {
            fc.begin();
            final Facading facading = FacadingFactory.createFacading(fc);

            final FooFacade ff = facading.createFacade(subject, FooFacade.class);

            Assert.assertNull(ff.getString());
            final String v = UUID.randomUUID().toString();
            ff.setString(v);
            Assert.assertEquals(v, ff.getString());

            final RepositoryConnection fc2 = repositoryRDF.getConnection();
            try {
                fc2.begin();

                final Facading f2 = FacadingFactory.createFacading(fc2);
                Assert.assertNull(f2.createFacade(subject, FooFacade.class).getString());

                fc2.commit();
            } finally {
                if (fc2.isActive()) fc2.rollback();
                fc2.close();
            }

            fc.commit();

            final RepositoryConnection fc3 = repositoryRDF.getConnection();
            try {
                fc3.begin();

                final Facading f3 = FacadingFactory.createFacading(fc3);
                Assert.assertEquals(v, f3.createFacade(subject, FooFacade.class).getString());

                fc3.commit();
            } finally {
                if (fc3.isActive()) fc3.rollback();
                fc3.close();
View Full Code Here


        final RepositoryConnection mainCon = repositoryRDF.getConnection();
        try {
            mainCon.begin();
            Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
           
            final Facading facading = FacadingFactory.createFacading(mainCon);
            Assert.assertFalse(facading.isFacadeable(subject, TypeFacade.class));
            Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));


            final TypeFacade ff = facading.createFacade(subject, TypeFacade.class);
            Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));
            Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));

            Assert.assertNull(ff.getTitle());
            final String v = UUID.randomUUID().toString();
            ff.setTitle(v);
            Assert.assertEquals(v, ff.getTitle());
            Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
            Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));

            { // before-commit
                final RepositoryConnection subCon_1 = repositoryRDF.getConnection();
                try {
                    subCon_1.begin();
                    Assert.assertFalse(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));

                    final Facading f_1 = FacadingFactory.createFacading(subCon_1);
                    Assert.assertFalse(f_1.isFacadeable(subject, TypeFacade.class));

                    final TypeFacade tf_1 = f_1.createFacade(subject, TypeFacade.class);
                    Assert.assertNull(tf_1.getTitle());
                    Assert.assertTrue(f_1.isFacadeable(subject, TypeFacade.class));
                    Assert.assertTrue(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));

                    subCon_1.rollback();
                } finally {
                    if (subCon_1.isActive()) subCon_1.rollback();
                    subCon_1.close();
                }
            }

            mainCon.commit();

            { // after-commit
                final RepositoryConnection subCon_2 = repositoryRDF.getConnection();
                try {
                    subCon_2.begin();
                    Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));

                    final Facading f_2 = FacadingFactory.createFacading(subCon_2);
                    Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));

                    Assert.assertEquals(v, f_2.createFacade(subject, TypeFacade.class).getTitle());
                    Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));
                    Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));

                    subCon_2.commit();
                } finally {
                    if (subCon_2.isActive()) subCon_2.rollback();
                    subCon_2.close();
View Full Code Here

    @Test
    public void testParallelFacading() throws RepositoryException {
        final RepositoryConnection fc = repositoryRDF.getConnection();
        try {
            fc.begin();
            final Facading facading = FacadingFactory.createFacading(fc);

            final FooFacade ff = facading.createFacade(subject, FooFacade.class);

            Assert.assertNull(ff.getString());
            final String v = UUID.randomUUID().toString();
            ff.setString(v);
            Assert.assertEquals(v, ff.getString());

            final RepositoryConnection fc2 = repositoryRDF.getConnection();
            try {
                fc2.begin();

                final Facading f2 = FacadingFactory.createFacading(fc2);
                Assert.assertNull(f2.createFacade(subject, FooFacade.class).getString());

                fc2.commit();
            } finally {
                if (fc2.isActive()) fc2.rollback();
                fc2.close();
            }

            fc.commit();

            final RepositoryConnection fc3 = repositoryRDF.getConnection();
            try {
                fc3.begin();

                final Facading f3 = FacadingFactory.createFacading(fc3);
                Assert.assertEquals(v, f3.createFacade(subject, FooFacade.class).getString());

                fc3.commit();
            } finally {
                if (fc3.isActive()) fc3.rollback();
                fc3.close();
View Full Code Here

            while(triples.hasNext()) {
                resources.add(triples.next().getSubject());
            }
            triples.close();

            Facading facading = FacadingFactory.createFacading(connectionRDF);

            // test individual resource
            URI u_hans_meier = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
            URI u_anna_schmidt = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt");
            Person hans_meier = facading.createFacade(u_hans_meier,Person.class);

            Assert.assertEquals("Hans Meier",hans_meier.getName());
            Assert.assertEquals(2,hans_meier.getFriends().size());
            Assert.assertThat(hans_meier.getOnlineAccounts(),
                    CoreMatchers.<OnlineAccount> hasItem(hasProperty("accountName", is("Example"))));

            Assert.assertThat(hans_meier.getFriends(), allOf(
                    CoreMatchers.<Person> hasItem(hasProperty("name", is("Anna Schmidt"))),
                    CoreMatchers.<Person> hasItem(hasProperty("name", is("Sepp Huber")))
                    ));

            // test collection
            Collection<Person> persons = facading.createFacade(resources,Person.class);
            Assert.assertEquals(3, persons.size());
            Assert.assertThat(persons,allOf(
                    CoreMatchers.<Person> hasItem(hasProperty("name", is("Hans Meier"))),
                    CoreMatchers.<Person> hasItem(hasProperty("name", is("Anna Schmidt"))),
                    CoreMatchers.<Person> hasItem(hasProperty("name", is("Sepp Huber")))
View Full Code Here

        final RepositoryConnection mainCon = repositoryRDF.getConnection();
        try {
            mainCon.begin();
            Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));

            final Facading facading = FacadingFactory.createFacading(mainCon);
            Assert.assertFalse(facading.isFacadeable(subject, TypeFacade.class));
            Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));


            final TypeFacade ff = facading.createFacade(subject, TypeFacade.class);
            Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));
            Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));

            Assert.assertNull(ff.getTitle());
            final String v = UUID.randomUUID().toString();
            ff.setTitle(v);
            Assert.assertEquals(v, ff.getTitle());
            Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
            Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));

            { // before-commit
                final RepositoryConnection subCon_1 = repositoryRDF.getConnection();
                try {
                    subCon_1.begin();
                    Assert.assertFalse(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));

                    final Facading f_1 = FacadingFactory.createFacading(subCon_1);
                    Assert.assertFalse(f_1.isFacadeable(subject, TypeFacade.class));

                    final TypeFacade tf_1 = f_1.createFacade(subject, TypeFacade.class);
                    Assert.assertNull(tf_1.getTitle());
                    Assert.assertTrue(f_1.isFacadeable(subject, TypeFacade.class));
                    Assert.assertTrue(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));

                    subCon_1.rollback();
                } finally {
                    if (subCon_1.isActive()) subCon_1.rollback();
                    subCon_1.close();
                }
            }

            mainCon.commit();

            { // after-commit
                final RepositoryConnection subCon_2 = repositoryRDF.getConnection();
                try {
                    subCon_2.begin();
                    Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));

                    final Facading f_2 = FacadingFactory.createFacading(subCon_2);
                    Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));

                    Assert.assertEquals(v, f_2.createFacade(subject, TypeFacade.class).getTitle());
                    Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));
                    Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));

                    subCon_2.commit();
                } finally {
                    if (subCon_2.isActive()) subCon_2.rollback();
                    subCon_2.close();
View Full Code Here

            while(triples.hasNext()) {
                resources.add(triples.next().getSubject());
            }
            triples.close();

            Facading facading = FacadingFactory.createFacading(connectionRDF);

            // test individual resource
            URI u_hans_meier = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
            Person hans_meier = facading.createFacade(u_hans_meier,Person.class);

            Assert.assertNull(hans_meier.getNick());

            // set nick name and check if it is now set
            hans_meier.setNick("hansi");
            Assert.assertNotNull(hans_meier.getNick());
            Assert.assertEquals("hansi",hans_meier.getNick());

            // check in triple store if the triple is there
            URI p_foaf_nick = connectionRDF.getValueFactory().createURI(Namespaces.NS_FOAF + "nick");
            RepositoryResult<Statement> nicknames = connectionRDF.getStatements(u_hans_meier,p_foaf_nick,null,true);
            Assert.assertTrue(nicknames.hasNext());
            Assert.assertEquals("hansi",nicknames.next().getObject().stringValue());
            nicknames.close();

            // test creating a completely new resource
            URI u_fritz_fischer = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/fritz_fischer");
            Person fritz_fischer = facading.createFacade(u_fritz_fischer,Person.class);
            fritz_fischer.setName("Fritz Fischer");

            Assert.assertEquals("Fritz Fischer", fritz_fischer.getName());

            // test if it is now there
View Full Code Here

    @Test
    public void testReadInverseRDF() throws RepositoryException {

        final RepositoryConnection connection = repositoryRDF.getConnection();
        try {
            final Facading facading = FacadingFactory.createFacading(connection);

            URI u_hans_meier = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
            Person hans_meier = facading.createFacade(u_hans_meier, Person.class);
            Assume.assumeThat("Could not load test-person", hans_meier, notNullValue(Person.class));

            for (OnlineAccount account : hans_meier.getOnlineAccounts()) {
                Assert.assertNotNull(account);
                final Resource accountRSC = account.getDelegate();
                Assert.assertNotNull(accountRSC);

                final OnlineAccount oa = facading.createFacade(accountRSC, OnlineAccount.class);
                Assert.assertNotNull(oa);

                Assert.assertEquals(hans_meier, oa.getHolder());
            }
View Full Code Here

    @Test
    public void testWriteInverserRDF() throws RepositoryException {
        final RepositoryConnection connection = repositoryRDF.getConnection();
        try {
            final Facading facading = FacadingFactory.createFacading(connection);

            URI p = connection.getValueFactory().createURI("http://localhost/person");
            Person person = facading.createFacade(p, Person.class);

            URI a = connection.getValueFactory().createURI("http://localhost/account");
            OnlineAccount account = facading.createFacade(a, OnlineAccount.class);

            account.setHolder(person);

            connection.commit();
View Full Code Here

    @Test
    public void testAdd() throws RepositoryException {
        final RepositoryConnection connection = repositoryRDF.getConnection();
        try {
            final Facading facading = FacadingFactory.createFacading(connection);

            URI a = connection.getValueFactory().createURI("http://localhost/account");
            OnlineAccount account = facading.createFacade(a, OnlineAccount.class);

            account.addChatId("foo");
            Assert.assertThat(account.getChatId(), hasItem("foo"));
            account.addChatId("bar");
            Assert.assertThat(account.getChatId(), hasItems("foo", "bar"));
View Full Code Here

        subject = repositoryRDF.getValueFactory().createURI("urn:", UUID.randomUUID().toString());
        random = new Random();

        facadingConnection = repositoryRDF.getConnection();
        facadingConnection.begin();
        final Facading factory = FacadingFactory.createFacading(facadingConnection);
        boxed = factory.createFacade(subject, Boxed.class);
    }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.commons.sesame.facading.api.Facading

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.