public void testDataSourceCatalogIngestQueryAndDelete()
throws CatalogServiceException, ParseException, TokenMgrError {
// test ingest
Metadata m = new Metadata();
m.addMetadata("testkey1", "testval1");
TransactionReceipt tr = cs.ingest(m);
Vector<TransactionReceipt> receipts = new Vector<TransactionReceipt>();
receipts.add(tr);
List<TransactionalMetadata> metadatas = cs.getMetadata(receipts);
assertEquals(metadatas.size(), 1);
Metadata ingestedMetadata = metadatas.get(0).getMetadata();
assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);
// test ingest update
m.replaceMetadata(
CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY
.toString(), tr.getTransactionId().toString());
m.replaceMetadata(CatalogServiceLocal.ENABLE_UPDATE_MET_KEY, "true");
tr = cs.ingest(m);
receipts = new Vector<TransactionReceipt>();
receipts.add(tr);
metadatas = cs.getMetadata(receipts);
assertEquals(metadatas.size(), 1);
ingestedMetadata = metadatas.get(0).getMetadata();
assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);
// test query using querypager
QueryExpression qe = QueryParser
.parseQueryExpression("testkey1 == 'testval1'");
QueryPager pager = cs.query(qe);
metadatas = cs.getNextPage(pager);
assertEquals(metadatas.size(), 1);
ingestedMetadata = metadatas.get(0).getMetadata();
assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);
// test query using std paging
qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'");
Page page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe);
metadatas = cs.getMetadata(page);
assertEquals(metadatas.size(), 1);
ingestedMetadata = metadatas.get(0).getMetadata();
assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2);
// test query using std paging with catalog restriction
qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'");
page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe,
Collections.singleton("TestCatalog1"));
metadatas = cs.getMetadata(page);
assertEquals(metadatas.size(), 1);
ingestedMetadata = metadatas.get(0).getMetadata();
assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1");
assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 1);
// test delete
m = new Metadata();
m.addMetadata(
CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY
.toString(), tr.getTransactionId().toString());
cs.delete(m);
assertEquals(cs.getMetadata(Collections.singletonList(tr)).size(), 0);
}