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) {
}
}
}
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) {
}
}
}
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) {
}
}
}
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) {
}
}
}
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());
}
Aggregations