}
}
public void testQuery() throws Exception {
// ingest first file
Product testProduct = getTestProduct();
testProduct.setProductId("23");
Metadata prodMet = new Metadata();
URL ingestUrl = this.getClass().getResource(
"/ingest");
prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
ingestUrl.getFile()).getCanonicalPath());
prodMet.addMetadata(CoreMetKeys.FILENAME, "test-file-1.txt");
prodMet.addMetadata("CAS.ProductName", "TestFile1");
prodMet.addMetadata(CoreMetKeys.PRODUCT_TYPE, "GenericFile");
prodMet.addMetadata("NominalDate", "2008-01-20");
prodMet.addMetadata("DataVersion", "3.6");
myCat.addMetadata(prodMet, testProduct);
// ingest second file
testProduct.setProductId("24");
prodMet.replaceMetadata(CoreMetKeys.FILENAME, "test-file-2.txt");
prodMet.replaceMetadata("CAS.ProductName", "TestFile2");
myCat.addMetadata(prodMet, testProduct);
// ingest thrid file
testProduct.setProductId("25");
prodMet.replaceMetadata(CoreMetKeys.FILENAME, "test-file-2.txt");
prodMet.replaceMetadata("CAS.ProductName", "TestFile3");
prodMet.replaceMetadata("DataVersion", "4.6");
myCat.addMetadata(prodMet, testProduct);
// perform first query
Query query = new Query();
query
.addCriterion(SqlParser
.parseSqlWhereClause("CAS.ProductName != 'TestFile3' AND (Filename == 'test-file-1.txt' OR Filename == 'test-file-2.txt') AND CAS.ProductName != 'TestFile2'"));
System.out.println(query);
List<String> productIds = myCat.query(query, testProduct
.getProductType());
System.out.println(productIds);
assertEquals("[23]", productIds.toString());
// perform second query
query = new Query();
query
.addCriterion(SqlParser
.parseSqlWhereClause("Filename == 'test-file-1.txt' OR (Filename == 'test-file-2.txt' AND CAS.ProductName != 'TestFile2')"));
System.out.println(query);
productIds = myCat.query(query, testProduct.getProductType());
System.out.println(productIds);
assertEquals("[25, 23]", productIds.toString());
// perform second query
query = new Query();
query
.addCriterion(SqlParser
.parseSqlWhereClause("NominalDate == '2008-01-20' AND DataVersion >= '3.6' AND DataVersion <= '4.0'"));
System.out.println(query);
productIds = myCat.query(query, testProduct.getProductType());
System.out.println(productIds);
assertEquals("[24, 23]", productIds.toString());
}