}
}
public void testPagedQuery(){
// Add a couple of Products and associated Metadata
Product testProduct = null;
for(int i = 0; i < catPageSize + 1; i++){
testProduct = Product.getDefaultFlatProduct("test" + i,
"urn:oodt:GenericFile");
testProduct.getProductType().setName("GenericFile");
Reference ref = new Reference("file:///foo.txt", "file:///bar.txt", 100);
Vector<Reference> references = new Vector<Reference>();
references.add(ref);
testProduct.setProductReferences(references);
Metadata met = new Metadata();
met.addMetadata("Filename", "tempProduct" + i);
met.addMetadata("ProductStructure", "Flat");
try {
myCat.addProduct(testProduct);
myCat.addMetadata(met, testProduct);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
// Formulate a test query
Query query = new Query();
BooleanQueryCriteria bqc = new BooleanQueryCriteria();
try{
bqc.setOperator(BooleanQueryCriteria.AND);
}catch (Exception e){
e.printStackTrace();
fail(e.getMessage());
}
TermQueryCriteria tqc = new TermQueryCriteria();
tqc.setElementName("ProductStructure");
tqc.setValue("Flat");
try{
bqc.addTerm(tqc);
}catch (Exception e){
e.printStackTrace();
fail(e.getMessage());
}
tqc = new TermQueryCriteria();
tqc.setElementName("Filename");
tqc.setValue("tempProduct1");
try{
bqc.addTerm(tqc);
}catch (Exception e){
e.printStackTrace();
fail(e.getMessage());
}
query.addCriterion(bqc);
// Perform the query and validate results
ProductPage page = null;
try{
page = myCat.pagedQuery(query, testProduct.getProductType(), 1);
}catch (Exception e){
e.printStackTrace();
fail(e.getMessage());
}
assertEquals(page.getPageProducts().size(), 1);