Search in sources :

Example 1 with DatasetURIReporter

use of ambit2.rest.dataset.DatasetURIReporter in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testUpdateBundle.

@Test
public void testUpdateBundle() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    form.add(ISourceDataset.fields.title.name(), "title");
    // form.add(ISourceDataset.fields.source.name(), "source");
    form.add(ISourceDataset.fields.license.name(), "license");
    form.add(ISourceDataset.fields.maintainer.name(), "maintainer");
    form.add(ISourceDataset.fields.rightsHolder.name(), "rightsHolder");
    form.add(ISourceDataset.fields.seeAlso.name(), "NEW VALUE");
    form.add("description", "description");
    form.add(ISourceDataset.fields.stars.name(), "9");
    try {
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,updated from bundle where idbundle=1"));
        Assert.assertEquals(1, table.getRowCount());
        Object updated = table.getValue(0, "updated");
        SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(1);
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleCreator callable = new CallableBundleCreator(bundle, reporter, Method.PUT, form, c.getConnection(), new User("testuser"), null);
        TaskResult task = callable.call();
        table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,name,licenseURI,rightsHolder,maintainer,stars,title,url,description,updated,user_name,url,title from bundle join catalog_references using(idreference) where idbundle=1"));
        Assert.assertEquals(1, table.getRowCount());
        Assert.assertEquals("title", table.getValue(0, "name"));
        Assert.assertEquals("maintainer", table.getValue(0, "maintainer"));
        Assert.assertEquals("rightsHolder", table.getValue(0, "rightsHolder"));
        Assert.assertEquals("license", table.getValue(0, "licenseURI"));
        Assert.assertEquals("description", table.getValue(0, "description"));
        Assert.assertNotSame(updated, table.getValue(0, "updated"));
        Assert.assertEquals("guest", table.getValue(0, "user_name"));
        Assert.assertEquals("NEW VALUE", table.getValue(0, "url"));
    // Assert.assertEquals("source",table.getValue(0,"title"));
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : User(org.restlet.security.User) CallableBundleCreator(ambit2.rest.bundle.CallableBundleCreator) Form(org.restlet.data.Form) Reference(org.restlet.data.Reference) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 2 with DatasetURIReporter

use of ambit2.rest.dataset.DatasetURIReporter in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testCreateBundle.

@Test
public void testCreateBundle() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    form.add(ISourceDataset.fields.title.name(), "title");
    form.add(ISourceDataset.fields.source.name(), "source");
    form.add(ISourceDataset.fields.license.name(), "license");
    form.add(ISourceDataset.fields.seeAlso.name(), "seeAlso");
    form.add(ISourceDataset.fields.maintainer.name(), "maintainer");
    form.add(ISourceDataset.fields.rightsHolder.name(), "rightsHolder");
    form.add("description", "description");
    form.add(ISourceDataset.fields.stars.name(), "9");
    try {
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleCreator callable = new CallableBundleCreator(null, reporter, Method.POST, form, c.getConnection(), new User("testuser"), null);
        TaskResult task = callable.call();
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,description,user_name,title,url from bundle join catalog_references using(idreference) where name='title'"));
        Assert.assertEquals(1, table.getRowCount());
        Assert.assertEquals("description", table.getValue(0, "description"));
        Assert.assertEquals("testuser", table.getValue(0, "user_name"));
        Assert.assertEquals("source", table.getValue(0, "title"));
        Assert.assertEquals("seeAlso", table.getValue(0, "url"));
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : User(org.restlet.security.User) CallableBundleCreator(ambit2.rest.bundle.CallableBundleCreator) Form(org.restlet.data.Form) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) Reference(org.restlet.data.Reference) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 3 with DatasetURIReporter

use of ambit2.rest.dataset.DatasetURIReporter in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testCreateBundleCopy.

@Test
public void testCreateBundleCopy() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    form.add("bundle_uri", "http://localhost/bundle/1");
    try {
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleCreator callable = new CallableBundleCreator(null, reporter, Method.POST, form, c.getConnection(), new User("testuser"), null);
        TaskResult task = callable.call();
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,licenseURI,user_name from bundle where name='Assessment' order by idbundle asc"));
        Assert.assertEquals(2, table.getRowCount());
        Assert.assertEquals(table.getValue(1, "licenseURI"), table.getValue(0, "licenseURI"));
        Assert.assertEquals("testuser", table.getValue(1, "user_name"));
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : User(org.restlet.security.User) CallableBundleCreator(ambit2.rest.bundle.CallableBundleCreator) Form(org.restlet.data.Form) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) Reference(org.restlet.data.Reference) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 4 with DatasetURIReporter

use of ambit2.rest.dataset.DatasetURIReporter in project ambit-mirror by ideaconsult.

the class CallableBundleCreatorTest method testCreateBundleVersion.

@Test
public void testCreateBundleVersion() throws Exception {
    setUpDatabase(dbFile);
    IDatabaseConnection c = getConnection();
    IDatabaseConnection c1 = getConnection();
    Form form = new Form();
    try {
        SubstanceEndpointsBundle bundle = new SubstanceEndpointsBundle(1);
        DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle> reporter = new DatasetURIReporter<IQueryRetrieval<SubstanceEndpointsBundle>, SubstanceEndpointsBundle>(new Reference("http://localhost"));
        CallableBundleVersionCreator callable = new CallableBundleVersionCreator(bundle, reporter, Method.POST, form, c.getConnection(), "");
        TaskResult task = callable.call();
        System.out.println(task);
        ITable table = c1.createQueryTable("EXPECTED", String.format("SELECT idbundle,version,hex(bundle_number) bn from bundle where bundle_number in (select bundle_number from bundle where idbundle=1) order by idbundle"));
        Assert.assertEquals(2, table.getRowCount());
    } catch (Exception x) {
        throw x;
    } finally {
        try {
            c.close();
        } catch (Exception x) {
        }
        try {
            c1.close();
        } catch (Exception x) {
        }
    }
}
Also used : CallableBundleVersionCreator(ambit2.rest.bundle.CallableBundleVersionCreator) Form(org.restlet.data.Form) SubstanceEndpointsBundle(ambit2.base.data.substance.SubstanceEndpointsBundle) Reference(org.restlet.data.Reference) TaskResult(net.idea.restnet.i.task.TaskResult) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) DbUnitTest(net.idea.restnet.db.test.DbUnitTest) Test(org.junit.Test)

Example 5 with DatasetURIReporter

use of ambit2.rest.dataset.DatasetURIReporter in project ambit-mirror by ideaconsult.

the class MetaDatasetResourceTest method testUpdateExistingEntryN3RightsHolder.

@Test
public void testUpdateExistingEntryN3RightsHolder() throws Exception {
    SourceDataset p = new SourceDataset(null);
    p.setLicenseURI(null);
    p.setrightsHolder("http://me.myself");
    OntModel model = OT.createModel();
    DatasetURIReporter uriReporter = new DatasetURIReporter(new Reference(String.format("http://localhost:%d", port)));
    MetadataRDFReporter.addToModel(model, p, uriReporter.getURI(p));
    StringWriter writer = new StringWriter();
    model.write(writer, "N3");
    System.out.println(writer.toString());
    Response response = testPut(getTestURI(), MediaType.TEXT_URI_LIST, new StringRepresentation(writer.toString(), MediaType.TEXT_RDF_N3));
    Assert.assertEquals(Status.SUCCESS_OK, response.getStatus());
    IDatabaseConnection c = getConnection();
    ITable table = c.createQueryTable("EXPECTED", String.format("SELECT * FROM src_dataset join catalog_references using(idreference) where id_srcdataset=1 and rightsHolder='%s' ", "http://me.myself"));
    Assert.assertEquals(1, table.getRowCount());
    c.close();
    Assert.assertEquals("http://localhost:8181/dataset/1/metadata", response.getLocationRef().toString());
}
Also used : Response(org.restlet.Response) StringWriter(java.io.StringWriter) StringRepresentation(org.restlet.representation.StringRepresentation) Reference(org.restlet.data.Reference) OntModel(com.hp.hpl.jena.ontology.OntModel) ISourceDataset(ambit2.base.data.ISourceDataset) SourceDataset(ambit2.base.data.SourceDataset) ITable(org.dbunit.dataset.ITable) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) DatasetURIReporter(ambit2.rest.dataset.DatasetURIReporter) Test(org.junit.Test) ResourceTest(ambit2.rest.test.ResourceTest)

Aggregations

DatasetURIReporter (ambit2.rest.dataset.DatasetURIReporter)18 Reference (org.restlet.data.Reference)14 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)11 ITable (org.dbunit.dataset.ITable)11 Test (org.junit.Test)11 SubstanceEndpointsBundle (ambit2.base.data.substance.SubstanceEndpointsBundle)10 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)9 Form (org.restlet.data.Form)9 ResourceException (org.restlet.resource.ResourceException)8 ISourceDataset (ambit2.base.data.ISourceDataset)7 DbUnitTest (net.idea.restnet.db.test.DbUnitTest)7 SourceDataset (ambit2.base.data.SourceDataset)6 TaskResult (net.idea.restnet.i.task.TaskResult)6 StringRepresentation (org.restlet.representation.StringRepresentation)6 CallableBundleCreator (ambit2.rest.bundle.CallableBundleCreator)5 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)5 User (org.restlet.security.User)5 FactoryTaskConvertor (ambit2.rest.task.FactoryTaskConvertor)4 Connection (java.sql.Connection)4 ITaskApplication (net.idea.restnet.i.task.ITaskApplication)4