public void testFirstProductOnlyOnFirstPage() {
// add catPageSize of the test Product
// then add a product called "ShouldBeFirstForPage.txt"
// make sure it's the first one on the 2nd page
Product testProd = getTestProduct();
Metadata met = getTestMetadata("test");
for (int i = 0; i < this.catPageSize; i++) {
try {
myCat.addProduct(testProd);
myCat.addMetadata(met, testProd);
} catch (Exception e) {
fail(e.getMessage());
}
}
testProd.setProductName("ShouldBeFirstForPage.txt");
met.replaceMetadata("CAS.ProdutName", "ShouldBeFirstForPage.txt");
try {
myCat.addProduct(testProd);
myCat.addMetadata(met, testProd);
} catch (Exception e) {
fail(e.getMessage());
}
try {
assertNotNull(myCat.getProducts());
assertEquals(21, myCat.getProducts().size());
} catch (Exception e) {
fail(e.getMessage());
}
ProductType type = new ProductType();
type.setProductTypeId("urn:oodt:GenericFile");
type.setName("GenericFile");
assertNotNull(myCat.getFirstPage(type));
assertNotNull(myCat.getFirstPage(type).getPageProducts());
assertEquals(catPageSize, myCat.getFirstPage(type).getPageProducts()
.size());
ProductPage page = myCat.getNextPage(type, myCat.getFirstPage(type));
assertNotNull(page);
assertNotNull(page.getPageProducts());
assertEquals(1, page.getPageProducts().size());
assertEquals(2, page.getTotalPages());
assertNotNull(page.getPageProducts().get(0));
Product retProd = ((Product) page.getPageProducts().get(0));
assertEquals("ShouldBeFirstForPage.txt", retProd.getProductName());
}