You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2015/10/13 17:39:07 UTC
[7/9] oodt git commit: OODT-889 update file manager tests
OODT-889 update file manager tests
Project: http://git-wip-us.apache.org/repos/asf/oodt/repo
Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/d757222b
Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/d757222b
Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/d757222b
Branch: refs/heads/master
Commit: d757222b8847e839fb3326bec6cd08e96cea0fad
Parents: 4286c92
Author: Tom Barber <to...@analytical-labs.com>
Authored: Tue Oct 13 15:01:32 2015 +0100
Committer: Tom Barber <to...@analytical-labs.com>
Committed: Tue Oct 13 15:01:32 2015 +0100
----------------------------------------------------------------------
.../catalog/query/FreeTextQueryExpression.java | 4 +-
.../cas/catalog/query/QueryLogicalGroup.java | 4 +-
.../oodt/cas/filemgr/catalog/LuceneCatalog.java | 53 +-
.../oodt/cas/filemgr/catalog/TestAppender.java | 29 ++
.../filemgr/catalog/TestDataSourceCatalog.java | 159 ++++--
.../cas/filemgr/catalog/TestLuceneCatalog.java | 520 ++++++++++++++++++-
.../catalog/TestMappedDataSourceCatalog.java | 1 -
.../catalog/TestOrderedDataSourceCatalog.java | 7 +-
8 files changed, 675 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/FreeTextQueryExpression.java
----------------------------------------------------------------------
diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/FreeTextQueryExpression.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/FreeTextQueryExpression.java
index 12af21c..c5268a9 100644
--- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/FreeTextQueryExpression.java
+++ b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/FreeTextQueryExpression.java
@@ -82,9 +82,9 @@ public class FreeTextQueryExpression extends TermQueryExpression {
*/
public String toString() {
StringBuilder serial = new StringBuilder();
- serial.append("({" + this.bucketNames + "} " + this.term.getName() + " :|");
+ serial.append("({").append(this.bucketNames).append("} ").append(this.term.getName()).append(" :|");
for (String value : this.term.getValues()) {
- serial.append("+" + value);
+ serial.append("+").append(value);
serial.append("|: )");
}
return serial.toString();
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/QueryLogicalGroup.java
----------------------------------------------------------------------
diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/QueryLogicalGroup.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/QueryLogicalGroup.java
index c6b764b..df16b6b 100644
--- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/QueryLogicalGroup.java
+++ b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/QueryLogicalGroup.java
@@ -97,9 +97,9 @@ public class QueryLogicalGroup extends QueryExpression {
@Override
public String toString() {
StringBuilder query = new StringBuilder();
- query.append("({" + this.bucketNames + "} " + this.operator + " : ");
+ query.append("({").append(this.bucketNames).append("} ").append(this.operator).append(" : ");
for (QueryExpression queryExpression : this.queryExpressions) {
- query.append(queryExpression.toString() + ",");
+ query.append(queryExpression.toString()).append(",");
}
return query.substring(0, query.length() - 1) + ")";
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
index 5e375c4..98e0eb5 100644
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
@@ -18,55 +18,33 @@
package org.apache.oodt.cas.filemgr.catalog;
//JDK imports
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-//Lucene imports
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
-import org.apache.lucene.search.BooleanClause;
-import org.apache.lucene.search.BooleanQuery;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.RangeQuery;
-import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortField;
-import org.apache.lucene.search.TermQuery;
-import org.apache.lucene.search.WildcardQuery;
-
-//OODT imports
-import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.Element;
-import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.filemgr.structs.ProductPage;
-import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.lucene.search.*;
+import org.apache.oodt.cas.filemgr.structs.*;
import org.apache.oodt.cas.filemgr.structs.Query;
-import org.apache.oodt.cas.filemgr.structs.QueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.Reference;
-import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
import org.apache.oodt.cas.filemgr.structs.exceptions.ValidationLayerException;
import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
import org.apache.oodt.cas.metadata.Metadata;
import org.apache.oodt.commons.pagination.PaginationUtils;
-
-//JUG imports
import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+//Lucene imports
+//OODT imports
+//JUG imports
+
/**
* @author mattmann
* @author bfoster
@@ -846,6 +824,9 @@ public class LuceneCatalog implements Catalog {
* org.apache.oodt.cas.filemgr.structs.ProductPage)
*/
public ProductPage getNextPage(ProductType type, ProductPage currentPage) {
+ if(type==null){
+ return null;
+ }
if (currentPage == null) {
return getFirstPage(type);
}
@@ -886,6 +867,10 @@ public class LuceneCatalog implements Catalog {
* org.apache.oodt.cas.filemgr.structs.ProductPage)
*/
public ProductPage getPrevPage(ProductType type, ProductPage currentPage) {
+ if(type==null){
+ return null;
+ }
+
if (currentPage == null) {
return getFirstPage(type);
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestAppender.java
----------------------------------------------------------------------
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestAppender.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestAppender.java
new file mode 100644
index 0000000..5680428
--- /dev/null
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestAppender.java
@@ -0,0 +1,29 @@
+package org.apache.oodt.cas.filemgr.catalog;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.spi.LoggingEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+class TestAppender extends AppenderSkeleton {
+ private final List<LoggingEvent> log = new ArrayList<LoggingEvent>();
+
+ @Override
+ public boolean requiresLayout() {
+ return false;
+ }
+
+ @Override
+ protected void append(final LoggingEvent loggingEvent) {
+ log.add(loggingEvent);
+ }
+
+ @Override
+ public void close() {
+ }
+
+ public List<LoggingEvent> getLog() {
+ return new ArrayList<LoggingEvent>(log);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestDataSourceCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestDataSourceCatalog.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestDataSourceCatalog.java
index eb3ef32..a108853 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestDataSourceCatalog.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestDataSourceCatalog.java
@@ -19,28 +19,28 @@
package org.apache.oodt.cas.filemgr.catalog;
//JDK imports
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.*;
+import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
+import org.apache.oodt.cas.filemgr.util.SqlParser;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
+import org.apache.oodt.commons.database.SqlScript;
+
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import javax.sql.DataSource;
-//OODT imports
-import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
-import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.filemgr.structs.ProductPage;
-import org.apache.oodt.cas.filemgr.structs.ProductType;
-import org.apache.oodt.cas.filemgr.structs.Query;
-import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
-import org.apache.oodt.commons.database.DatabaseConnectionBuilder;
-import org.apache.oodt.commons.database.SqlScript;
-import org.apache.oodt.cas.filemgr.util.SqlParser;
-import org.apache.oodt.cas.metadata.Metadata;
+import javax.sql.DataSource;
-//Junit imports
import junit.framework.TestCase;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
+
/**
* @author mattmann
* @version $Revision$
@@ -71,7 +71,7 @@ public class TestDataSourceCatalog extends TestCase {
properties.setProperty("java.util.logging.config.file", new File(
loggingPropertiesUrl.getFile()).getAbsolutePath());
- if(properties.getProperty("overrideProperties") == null){
+ if(properties.getProperty("overrideProperties") == null) {
try {
URL filemgrPropertiesUrl = this.getClass().getResource(
@@ -83,42 +83,45 @@ public class TestDataSourceCatalog extends TestCase {
}
- // first load the example configuration
+ // first load the example configuration
- // get a temp directory
- File tempDir = null;
- File tempFile = null;
+ // get a temp directory
+ File tempDir = null;
+ File tempFile = null;
- try {
- tempFile = File.createTempFile("foo", "bar");
- tempFile.deleteOnExit();
- tempDir = tempFile.getParentFile();
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ try {
+ tempFile = File.createTempFile("foo", "bar");
+ tempFile.deleteOnExit();
+ tempDir = tempFile.getParentFile();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
- tmpDirPath = tempDir.getAbsolutePath();
- if (!tmpDirPath.endsWith("/")) {
- tmpDirPath += "/";
- }
+ tmpDirPath = tempDir.getAbsolutePath();
+ if (!tmpDirPath.endsWith("/")) {
+ tmpDirPath += "/";
+ }
- tmpDirPath += "testCat";
+ tmpDirPath += "testCat";
- // now override the catalog ones
- properties.setProperty(
+ // now override the catalog ones
+ properties.setProperty(
"org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.url",
"jdbc:hsqldb:file:" + tmpDirPath + "/testCat;shutdown=true");
- properties.setProperty(
+ properties.setProperty(
"org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.user",
"sa");
- properties.setProperty(
+ properties.setProperty(
"org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.pass",
"");
- properties.setProperty(
+ properties.setProperty(
"org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.driver",
"org.hsqldb.jdbcDriver");
+ properties.setProperty(
+ "org.apache.oodt.cas.filemgr.catalog.datasource.lenientFields",
+ "false");
}
else{
try {
@@ -392,6 +395,37 @@ public class TestDataSourceCatalog extends TestCase {
}
}
+ public void testAddProductReferences() {
+
+ Product testProduct = getTestProduct();
+ testProduct.setProductId("1"); // need to link reference to prod
+
+ Reference ref = new Reference();
+
+ ref.setMimeType("text/plain");
+ ref.setFileSize(12345);
+ List<Reference> refs = new ArrayList<Reference>();
+ refs.add(ref);
+ testProduct.setProductReferences(refs);
+ try {
+ myCat.addProductReferences(testProduct);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ try {
+ List<Reference> productReferences = myCat.getProductReferences(testProduct);
+ assertNotNull(productReferences);
+ assertFalse(productReferences.isEmpty());
+ assertEquals(productReferences.get(0).getMimeType().getName(), "text/plain");
+ assertEquals(productReferences.get(0).getFileSize(), 12345);
+ } catch (CatalogException e) {
+ fail(e.getMessage());
+ }
+
+ }
+
public void testQuery() throws Exception {
// ingest first file
Product testProduct = getTestProduct();
@@ -453,6 +487,59 @@ public class TestDataSourceCatalog extends TestCase {
assertEquals("[24, 23]", productIds.toString());
}
+ public void testNullValidationLayer(){
+
+ setUpProperties();
+ System.setProperty(
+ "org.apache.oodt.cas.filemgr.catalog.datasource.lenientFields",
+ "true");
+ myCat = getCatalog();
+ // now create the basic schema for the DB
+ createSchema();
+
+ assertThat(myCat, instanceOf(LenientDataSourceCatalog.class));
+
+ }
+
+ public void testPassDatasource(){
+ String url = System
+ .getProperty("org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.url");
+ String user = System
+ .getProperty("org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.user");
+ String pass = System
+ .getProperty("org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.pass");
+ String driver = System.getProperty("org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.driver");
+
+ DataSource ds = DatabaseConnectionBuilder.buildDataSource(user,pass,driver,url);
+
+ myCat = new DataSourceCatalogFactory(ds).createCatalog();
+
+ Product testProduct = getTestProduct();
+ try {
+ myCat.addProduct(testProduct);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ Product retProduct;
+ try {
+ retProduct = myCat.getProductByName("test");
+ assertNotNull(retProduct);
+ assertEquals("test", retProduct.getProductName());
+ assertEquals(Product.STRUCTURE_FLAT, retProduct
+ .getProductStructure());
+ assertNotNull(retProduct.getProductType());
+ assertEquals("urn:oodt:GenericFile", retProduct.getProductType()
+ .getProductTypeId());
+ assertEquals(Product.STATUS_TRANSFER, retProduct
+ .getTransferStatus());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+
+ }
protected String getSchemaPath() {
URL url = this.getClass().getResource(
"/testcat.sql");
@@ -492,7 +579,7 @@ public class TestDataSourceCatalog extends TestCase {
}
- private static Product getTestProduct() {
+ protected static Product getTestProduct() {
Product testProduct = Product.getDefaultFlatProduct("test",
"urn:oodt:GenericFile");
testProduct.getProductType().setName("GenericFile");
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
index 7079115..3115d10 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
@@ -18,29 +18,22 @@
package org.apache.oodt.cas.filemgr.catalog;
-//JDK imports
+import com.google.common.collect.Lists;
+
+import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.*;
+import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
+import org.apache.oodt.cas.metadata.Metadata;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
+import java.util.List;
import java.util.Properties;
import java.util.Vector;
-//OODT imports
-import org.apache.oodt.cas.filemgr.catalog.LuceneCatalog;
-import org.apache.oodt.cas.filemgr.catalog.LuceneCatalogFactory;
-import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
-import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.filemgr.structs.ProductPage;
-import org.apache.oodt.cas.filemgr.structs.ProductType;
-import org.apache.oodt.cas.filemgr.structs.Query;
-import org.apache.oodt.cas.filemgr.structs.Reference;
-import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
-import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
-import org.apache.oodt.cas.metadata.Metadata;
-import com.google.common.collect.Lists;
-
-//Junit imports
import junit.framework.TestCase;
/**
@@ -87,7 +80,7 @@ public class TestLuceneCatalog extends TestCase {
// get a temp directory
File tempDir = null;
- File tempFile = null;
+ File tempFile;
try {
tempFile = File.createTempFile("foo", "bar");
@@ -124,6 +117,9 @@ public class TestLuceneCatalog extends TestCase {
"org.apache.oodt.cas.filemgr.catalog.lucene.mergeFactor",
"20");
+ properties.setProperty(
+ "org.apache.oodt.cas.filemgr.catalog.datasource.lenientFields",
+ "false");
// now override the val layer ones
URL examplesCoreUrl = this.getClass().getResource(
"/examples/core");
@@ -156,8 +152,8 @@ public class TestLuceneCatalog extends TestCase {
File[] tmpFiles = tmpDir.listFiles();
if (tmpFiles != null && tmpFiles.length > 0) {
- for (int i = 0; i < tmpFiles.length; i++) {
- tmpFiles[i].delete();
+ for (File tmpFile : tmpFiles) {
+ tmpFile.delete();
}
tmpDir.delete();
@@ -315,7 +311,7 @@ public class TestLuceneCatalog extends TestCase {
Product testProd = getTestProduct();
Metadata met = getTestMetadata("test");
- for (int i = 0; i < this.catPageSize; i++) {
+ for (int i = 0; i < catPageSize; i++) {
try {
myCat.addProduct(testProd);
myCat.addMetadata(met, testProd);
@@ -354,10 +350,470 @@ public class TestLuceneCatalog extends TestCase {
assertEquals(1, page.getPageProducts().size());
assertEquals(2, page.getTotalPages());
assertNotNull(page.getPageProducts().get(0));
- Product retProd = ((Product) page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
assertEquals("ShouldBeFirstForPage.txt", retProd.getProductName());
}
-
+
+ public void testGetLastProductOnLastPage() {
+ // 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 < 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.getLastProductPage(type));
+ assertNotNull(myCat.getLastProductPage(type).getPageProducts());
+ assertEquals(1, myCat.getLastProductPage(type).getPageProducts()
+ .size());
+ ProductPage page = myCat.getLastProductPage(type);
+ assertNotNull(page);
+ assertNotNull(page.getPageProducts());
+ assertEquals(1, page.getPageProducts().size());
+ assertEquals(2, page.getTotalPages());
+ List<Product> prods = page.getPageProducts();
+ assertNotNull(page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
+ assertEquals("ShouldBeFirstForPage.txt", retProd.getProductName());
+ }
+
+ public void testGetTopNProducts() {
+ // 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 < 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());
+ }
+
+ try {
+ assertNotNull(myCat.getTopNProducts(5));
+ assertEquals(5, myCat.getTopNProducts(5).size());
+ Product retProd = myCat.getTopNProducts(5).get(0);
+ assertEquals("test", retProd.getProductName());
+ } catch (CatalogException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void testGetNextPageNullType(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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(null, myCat.getFirstPage(type));
+
+
+ assertNull(page);
+ }
+
+ public void testGetNextPageNullCurrentPage(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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, null);
+ assertNotNull(page);
+ assertNotNull(page.getPageProducts());
+ assertEquals(20, page.getPageProducts().size());
+ assertEquals(2, page.getTotalPages());
+ assertNotNull(page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
+ assertEquals("test", retProd.getProductName());
+ }
+
+ public void testGetNextPageCurrentPageIsLastPage(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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.getLastProductPage(type));
+ assertNotNull(page);
+ assertNotNull(page.getPageProducts());
+ assertEquals(1, page.getPageProducts().size());
+ assertEquals(2, page.getTotalPages());
+ assertNotNull(page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
+ assertEquals("ShouldBeFirstForPage.txt", retProd.getProductName());
+ }
+
+ public void testGetPrevPage(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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 page2 = myCat.getNextPage(type, myCat.getFirstPage(type));
+ ProductPage page = myCat.getPrevPage(type, page2);
+ assertEquals(2, page2.getPageNum());
+ assertEquals(1, page.getPageNum());
+ }
+
+ public void testGetPrevPageNullCurrentPage(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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.getPrevPage(type, null);
+ assertNotNull(page);
+ assertNotNull(page.getPageProducts());
+ assertEquals(20, page.getPageProducts().size());
+ assertEquals(2, page.getTotalPages());
+ assertNotNull(page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
+ assertEquals("test", retProd.getProductName());
+ }
+
+ public void testGetPrevPageCurrentPageIsFirstPage(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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.getPrevPage(type, myCat.getFirstPage(type));
+ assertNotNull(page);
+ assertNotNull(page.getPageProducts());
+ assertEquals(20, page.getPageProducts().size());
+ assertEquals(2, page.getTotalPages());
+ assertNotNull(page.getPageProducts().get(0));
+ Product retProd = page.getPageProducts().get(0);
+ assertEquals("test", retProd.getProductName());
+ }
+
+ public void testGetPrevPageNullProductType(){
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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 page2 = myCat.getNextPage(type, myCat.getFirstPage(type));
+ ProductPage page = myCat.getPrevPage(null, page2);
+ assertNull(page);
+
+ }
+
+ public void testGetTopNProductsByType() {
+
+ Product testProd = getTestProduct();
+ Metadata met = getTestMetadata("test");
+
+ for (int i = 0; i < 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");
+ try {
+ assertNotNull(myCat.getTopNProducts(5, type));
+ assertEquals(5, myCat.getTopNProducts(5, type).size());
+ Product retProd = myCat.getTopNProducts(5, type).get(0);
+ assertEquals("test", retProd.getProductName());
+ } catch (CatalogException e) {
+ e.printStackTrace();
+ }
+
+ }
+
/**
* @since OODT-141
*/
@@ -524,7 +980,23 @@ public class TestLuceneCatalog extends TestCase {
assertEquals(page.getPageNum(), 1);
assertEquals(page.getTotalPages(), 1);
}
-
+
+ public void testNullIndexPath(){
+ System.clearProperty("org.apache.oodt.cas.filemgr.catalog.lucene.idxPath");
+ try{
+ LuceneCatalogFactory fact = new LuceneCatalogFactory();
+ fail( "Missing exception" );
+
+ } catch( IllegalArgumentException e ) {
+ Assert.assertThat(e.getMessage(), CoreMatchers.containsString("error initializing lucene catalog: "));
+ }
+ }
+
+ public void testCreateCatalogException(){
+
+ //TODO Use the TestAppender to make sure that an exception thrown is caught and logged.
+ }
+
private static Product getTestProduct() {
Product testProduct = Product.getDefaultFlatProduct("test",
"urn:oodt:GenericFile");
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestMappedDataSourceCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestMappedDataSourceCatalog.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestMappedDataSourceCatalog.java
index b6efdb2..fa16e2a 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestMappedDataSourceCatalog.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestMappedDataSourceCatalog.java
@@ -71,5 +71,4 @@ public class TestMappedDataSourceCatalog extends TestDataSourceCatalog {
return new File(url.getFile()).getAbsolutePath();
}
-
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/d757222b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestOrderedDataSourceCatalog.java
----------------------------------------------------------------------
diff --git a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestOrderedDataSourceCatalog.java b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestOrderedDataSourceCatalog.java
index a06ed5e..5e87ddc 100644
--- a/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestOrderedDataSourceCatalog.java
+++ b/filemgr/src/test/java/org/apache/oodt/cas/filemgr/catalog/TestOrderedDataSourceCatalog.java
@@ -17,11 +17,12 @@
package org.apache.oodt.cas.filemgr.catalog;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.metadata.Metadata;
+
import java.io.File;
import java.net.URL;
import java.util.Properties;
-import org.apache.oodt.cas.filemgr.structs.Product;
-import org.apache.oodt.cas.metadata.Metadata;
/**
* @author mattmann
@@ -98,7 +99,7 @@ public class TestOrderedDataSourceCatalog extends TestDataSourceCatalog {
}
- private static Product getTestProduct() {
+ protected static Product getTestProduct() {
Product testProduct = Product.getDefaultFlatProduct("test",
"urn:oodt:GenericFile");
testProduct.getProductType().setName("GenericFile");