You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by bf...@apache.org on 2011/12/04 21:17:55 UTC

svn commit: r1210199 [5/5] - in /oodt/trunk/filemgr: ./ src/main/assembly/ src/main/bin/ src/main/java/org/apache/oodt/cas/filemgr/cli/ src/main/java/org/apache/oodt/cas/filemgr/cli/action/ src/main/java/org/apache/oodt/cas/filemgr/system/ src/main/jav...

Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestIngestProductCliAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestIngestProductCliAction.java?rev=1210199&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestIngestProductCliAction.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestIngestProductCliAction.java Sun Dec  4 20:17:53 2011
@@ -0,0 +1,329 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.cli.action;
+
+//JDK imports
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+//Apache imports
+import org.apache.commons.io.FileUtils;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction.ActionMessagePrinter;
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.filemgr.datatransfer.DataTransfer;
+import org.apache.oodt.cas.filemgr.datatransfer.InPlaceDataTransferFactory;
+import org.apache.oodt.cas.filemgr.datatransfer.InPlaceDataTransferer;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link IngestProductCliAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestIngestProductCliAction extends TestCase {
+
+   private static final String FILENAME_MET_KEY = "Filename";
+   private static final String FILENAME_MET_VAL = "data.dat";
+   private static final String NOMINAL_DATE_MET_KEY = "NominalDate";
+   private static final String NOMINAL_DATE_MET_VAL = "2011-01-20";
+
+   private static final String PRODUCT_ID = "TestProductId";
+   private static final String PRODUCT_NAME = "TestProductName";
+   private static final String PRODUCT_TYPE_NAME = "TestProductType";
+   private static final String DATA_TRANSFERER_FACTORY = InPlaceDataTransferFactory.class.getCanonicalName();
+   private static final String DATA_TRANSFERER = InPlaceDataTransferer.class.getCanonicalName();
+   private static final String FLAT_REF_NAME = "flat_ref.txt";
+   private static final String HIER_REF_NAME = "hier_ref";
+   private static final String SUB_REF_1 = "sub_ref1.txt";
+   private static final String SUB_REF_2 = "sub_ref2.txt";
+
+   private DataTransfer clientSetDataTransferer;
+   private Product clientSetProduct;
+   private Metadata clientSetMetadata;
+
+   private File tmpDir;
+   private File metadataFile;
+   private File hierRefFile;
+   private File flatRefFile;
+
+   @Override
+   public void setUp() throws Exception {
+      super.setUp();
+      clientSetDataTransferer = null;
+      clientSetProduct = null;
+      clientSetMetadata = null;
+      tmpDir = createTmpDir();
+      metadataFile = createMetadataFile();
+      hierRefFile = createHierarchicalReference();
+      flatRefFile = createFlatReference();
+   }
+
+   @Override
+   public void tearDown() throws Exception {
+      FileUtils.forceDelete(tmpDir);
+   }
+
+   public void testValidateErrors() throws CmdLineActionException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      IngestProductCliAction cliAction = new MockIngestProductCliAction();
+      try {
+         cliAction.execute(printer);
+         fail("Expected throw CmdLineActionException");
+      } catch (CmdLineActionException ignore) {
+      }
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_FLAT);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setReferences(Lists.newArrayList(flatRefFile.getAbsolutePath()));
+      cliAction.execute(printer); // Should not throw exception.
+      cliAction.setDataTransferer(DATA_TRANSFERER_FACTORY);
+      cliAction.execute(printer); // Should not throw exception.
+
+      cliAction = new NullPTIngestProductCliAction();
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_FLAT);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setReferences(Lists.newArrayList(flatRefFile.getAbsolutePath()));
+      try {
+         cliAction.execute(printer);
+         fail("Expected throw CmdLineActionException");
+      } catch (CmdLineActionException ignore) {
+      }
+   }
+   
+   public void testClientTransTrueAndFlatProduct() throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockIngestProductCliAction cliAction = new MockIngestProductCliAction();
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_FLAT);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setDataTransferer(DATA_TRANSFERER_FACTORY);
+      cliAction.setReferences(Lists.newArrayList(flatRefFile.getAbsolutePath()));
+      cliAction.execute(printer);
+      assertEquals(2, printer.getPrintedMessages().size());
+      assertEquals("ingestProduct: Result: " + PRODUCT_ID, printer.getPrintedMessages().get(0)); 
+      assertEquals("\n", printer.getPrintedMessages().get(1));
+      assertEquals(PRODUCT_NAME, clientSetProduct.getProductName());
+      assertEquals(Product.STRUCTURE_FLAT, clientSetProduct.getProductStructure());
+      assertEquals(PRODUCT_TYPE_NAME, clientSetProduct.getProductType().getName());
+      assertEquals(1, clientSetProduct.getProductReferences().size());
+      assertEquals("file:" + flatRefFile.getAbsolutePath(), clientSetProduct.getProductReferences().get(0).getOrigReference());
+      assertEquals(DATA_TRANSFERER, clientSetDataTransferer.getClass().getCanonicalName());
+      assertEquals(2, clientSetMetadata.getAllKeys().size());
+      assertEquals(FILENAME_MET_VAL, clientSetMetadata.getMetadata(FILENAME_MET_KEY));
+      assertEquals(NOMINAL_DATE_MET_VAL, clientSetMetadata.getMetadata(NOMINAL_DATE_MET_KEY));
+   }
+
+   public void testClientTransFalseAndFlatProduct() throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockIngestProductCliAction cliAction = new MockIngestProductCliAction();
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_FLAT);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setReferences(Lists.newArrayList(flatRefFile.getAbsolutePath()));
+      cliAction.execute(printer);
+      assertEquals(2, printer.getPrintedMessages().size());
+      assertEquals("ingestProduct: Result: " + PRODUCT_ID, printer.getPrintedMessages().get(0)); 
+      assertEquals("\n", printer.getPrintedMessages().get(1));
+      assertEquals(PRODUCT_NAME, clientSetProduct.getProductName());
+      assertEquals(Product.STRUCTURE_FLAT, clientSetProduct.getProductStructure());
+      assertEquals(PRODUCT_TYPE_NAME, clientSetProduct.getProductType().getName());
+      assertEquals(1, clientSetProduct.getProductReferences().size());
+      assertEquals("file:" + flatRefFile.getAbsolutePath(), clientSetProduct.getProductReferences().get(0).getOrigReference());
+      assertNull(clientSetDataTransferer);
+      assertEquals(2, clientSetMetadata.getAllKeys().size());
+      assertEquals(FILENAME_MET_VAL, clientSetMetadata.getMetadata(FILENAME_MET_KEY));
+      assertEquals(NOMINAL_DATE_MET_VAL, clientSetMetadata.getMetadata(NOMINAL_DATE_MET_KEY));
+   }
+
+   public void testClientTransTrueAndHierProduct() throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockIngestProductCliAction cliAction = new MockIngestProductCliAction();
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setDataTransferer(DATA_TRANSFERER_FACTORY);
+      cliAction.setReferences(Lists.newArrayList(hierRefFile.getAbsolutePath()));
+      cliAction.execute(printer);
+      assertEquals(2, printer.getPrintedMessages().size());
+      assertEquals("ingestProduct: Result: " + PRODUCT_ID, printer.getPrintedMessages().get(0)); 
+      assertEquals("\n", printer.getPrintedMessages().get(1));
+      assertEquals(PRODUCT_NAME, clientSetProduct.getProductName());
+      assertEquals(Product.STRUCTURE_HIERARCHICAL, clientSetProduct.getProductStructure());
+      assertEquals(PRODUCT_TYPE_NAME, clientSetProduct.getProductType().getName());
+      assertEquals(3, clientSetProduct.getProductReferences().size());
+      assertEquals("file:" + hierRefFile.getAbsolutePath() + "/", clientSetProduct.getProductReferences().get(0).getOrigReference());
+      assertEquals("file:" + new File(hierRefFile, SUB_REF_1).getAbsolutePath(), clientSetProduct.getProductReferences().get(1).getOrigReference());
+      assertEquals("file:" + new File(hierRefFile, SUB_REF_2).getAbsolutePath(), clientSetProduct.getProductReferences().get(2).getOrigReference());
+      assertEquals(DATA_TRANSFERER, clientSetDataTransferer.getClass().getCanonicalName());
+      assertEquals(2, clientSetMetadata.getAllKeys().size());
+      assertEquals(FILENAME_MET_VAL, clientSetMetadata.getMetadata(FILENAME_MET_KEY));
+      assertEquals(NOMINAL_DATE_MET_VAL, clientSetMetadata.getMetadata(NOMINAL_DATE_MET_KEY));
+   }
+
+   public void testClientTransFalseAndHierProduct() throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockIngestProductCliAction cliAction = new MockIngestProductCliAction();
+      cliAction.setProductName(PRODUCT_NAME);
+      cliAction.setProductStructure(Product.STRUCTURE_HIERARCHICAL);
+      cliAction.setProductTypeName(PRODUCT_TYPE_NAME);
+      cliAction.setMetadataFile(metadataFile.getAbsolutePath());
+      cliAction.setReferences(Lists.newArrayList(hierRefFile.getAbsolutePath()));
+      cliAction.execute(printer);
+      assertEquals(2, printer.getPrintedMessages().size());
+      assertEquals("ingestProduct: Result: " + PRODUCT_ID, printer.getPrintedMessages().get(0)); 
+      assertEquals("\n", printer.getPrintedMessages().get(1));
+      assertEquals(PRODUCT_NAME, clientSetProduct.getProductName());
+      assertEquals(Product.STRUCTURE_HIERARCHICAL, clientSetProduct.getProductStructure());
+      assertEquals(PRODUCT_TYPE_NAME, clientSetProduct.getProductType().getName());
+      assertEquals(3, clientSetProduct.getProductReferences().size());
+      assertEquals("file:" + hierRefFile.getAbsolutePath() + "/", clientSetProduct.getProductReferences().get(0).getOrigReference());
+      assertEquals("file:" + new File(hierRefFile, SUB_REF_1).getAbsolutePath(), clientSetProduct.getProductReferences().get(1).getOrigReference());
+      assertEquals("file:" + new File(hierRefFile, SUB_REF_2).getAbsolutePath(), clientSetProduct.getProductReferences().get(2).getOrigReference());
+      assertNull(clientSetDataTransferer);
+      assertEquals(2, clientSetMetadata.getAllKeys().size());
+      assertEquals(FILENAME_MET_VAL, clientSetMetadata.getMetadata(FILENAME_MET_KEY));
+      assertEquals(NOMINAL_DATE_MET_VAL, clientSetMetadata.getMetadata(NOMINAL_DATE_MET_KEY));
+   }
+
+   private File createTmpDir() throws IOException {
+      File bogusDir = File.createTempFile("bogus", "bogus");
+      File tmpDir = bogusDir.getParentFile();
+      bogusDir.delete();
+      tmpDir = new File(tmpDir, "Metadata");
+      tmpDir.mkdirs();
+      return tmpDir;
+   }
+
+   private File createMetadataFile() throws IOException {
+      File metadataFile = new File(tmpDir, "test.met");
+      metadataFile.deleteOnExit();
+      PrintStream ps = null;
+      try {
+         ps = new PrintStream(new FileOutputStream(metadataFile));
+         ps.println("<cas:metadata xmlns:cas=\"http://oodt.jpl.nasa.gov/1.0/cas\">");
+         ps.println("  <keyval type=\"scalar\">");
+         ps.println("    <key>" + FILENAME_MET_KEY + "</key>");
+         ps.println("    <val>" + FILENAME_MET_VAL + "</val>");
+         ps.println("  </keyval>");
+         ps.println("  <keyval type=\"scalar\">");
+         ps.println("    <key>" +  NOMINAL_DATE_MET_KEY +"</key>");
+         ps.println("    <val>" +  NOMINAL_DATE_MET_VAL + "</val>");
+         ps.println("  </keyval>");
+         ps.println("</cas:metadata>");
+      } catch (IOException e) {
+         throw e;
+      } finally {
+         ps.close();
+      }
+      return metadataFile;
+   }
+
+   private File createHierarchicalReference() throws IOException {
+      File reference = new File(tmpDir, HIER_REF_NAME);
+      reference.mkdirs();
+      PrintStream ps = null;
+      for (String subRef :  Lists.newArrayList(SUB_REF_1, SUB_REF_2)) {
+         try {
+            ps = new PrintStream(new FileOutputStream(new File(reference, subRef)));
+            ps.println("This is a test sub-reference file");
+         } catch (IOException e) {
+            throw e;
+         } finally {
+            ps.close();
+         }
+      }
+      return reference;
+   }
+
+
+   private File createFlatReference() throws IOException {
+      File reference = new File(tmpDir, FLAT_REF_NAME);
+      PrintStream ps = null;
+      try {
+         ps = new PrintStream(new FileOutputStream(reference));
+         ps.println("This is a test sub-reference file");
+      } catch (IOException e) {
+         throw e;
+      } finally {
+         ps.close();
+      }
+      return reference;
+   }
+
+   public class MockIngestProductCliAction extends IngestProductCliAction {
+      @Override
+      public XmlRpcFileManagerClient getClient() throws MalformedURLException,
+            ConnectionException {
+         return new XmlRpcFileManagerClient(new URL("http://localhost:9000"),
+               false) {
+            @Override
+            public ProductType getProductTypeByName(String typeName) {
+               ProductType pt = new ProductType();
+               pt.setName(typeName);
+               return pt;
+            }
+            @Override
+            public void setDataTransfer(DataTransfer dataTransferer) {
+               clientSetDataTransferer = dataTransferer;
+            }
+            @Override
+            public String ingestProduct(Product product, Metadata metadata,
+                  boolean useClientTransfer) {
+               clientSetProduct = product;
+               clientSetMetadata = metadata;
+               return PRODUCT_ID;
+            }
+         };
+      }
+   }
+
+   public class NullPTIngestProductCliAction extends MockIngestProductCliAction {
+      @Override
+      public XmlRpcFileManagerClient getClient() throws MalformedURLException,
+            ConnectionException {
+         return new XmlRpcFileManagerClient(new URL("http://localhost:9000"),
+               false) {
+            @Override
+            public ProductType getProductTypeByName(String typeName) {
+               return null;
+            }
+         };
+      }
+   }
+}

Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestIngestProductCliAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java?rev=1210199&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java Sun Dec  4 20:17:53 2011
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.cli.action;
+
+//JDK imports
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction.ActionMessagePrinter;
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.RangeQueryCriteria;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.structs.Query;
+import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link LuceneQueryCliAction}.
+ * 
+ * @author bfoster (Brian Foster)
+ */
+public class TestLuceneQueryCliAction extends TestCase {
+
+   private Query clientSetQuery;
+
+   public void testValidation() {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockLuceneQueryCliAction cliAction = new MockLuceneQueryCliAction();
+      cliAction.setQuery("ProductId=TestProductId");
+      try {
+         cliAction.execute(printer);
+         fail("Should have throw exception");
+      } catch (Exception ignore) {
+      }
+      cliAction.setQuery("");
+      try {
+         cliAction.execute(printer);
+         fail("Should have throw exception");
+      } catch (Exception ignore) {
+      }
+   }
+
+   public void testClientTransTrueAndFlatProduct()
+         throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockLuceneQueryCliAction cliAction = new MockLuceneQueryCliAction();
+
+      cliAction.setQuery("ProductId:TestProductId");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      assertEquals("ProductId", ((TermQueryCriteria) clientSetQuery
+            .getCriteria().get(0)).getElementName());
+      assertEquals("TestProductId", ((TermQueryCriteria) clientSetQuery
+            .getCriteria().get(0)).getValue());
+
+      cliAction.setQuery("ProductId:TestProductId ProductName:TestProductName");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      BooleanQueryCriteria bqc = (BooleanQueryCriteria) clientSetQuery
+            .getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
+      assertEquals("ProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
+      assertEquals("ProductName",
+            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
+            .get(1)).getValue());
+
+      cliAction
+            .setQuery("ProductId:TestProductId NominalDate:[20020101 TO 20030101]");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
+      assertEquals("ProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
+      assertEquals("NominalDate",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("20020101",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getStartValue());
+      assertEquals("20030101",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getEndValue());
+      assertTrue(((RangeQueryCriteria) bqc.getTerms().get(1)).getInclusive());
+
+      cliAction
+            .setQuery("ProductId:TestProductId NominalDate:{20020101 TO 20030101}");
+      cliAction.execute(printer);
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
+      assertEquals("ProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
+      assertEquals("NominalDate",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("20020101",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getStartValue());
+      assertEquals("20030101",
+            ((RangeQueryCriteria) bqc.getTerms().get(1)).getEndValue());
+      assertFalse(((RangeQueryCriteria) bqc.getTerms().get(1)).getInclusive());
+
+      cliAction
+            .setQuery("ProductId:TestProductId AND ProductName:TestProductName");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.AND, bqc.getOperator());
+      assertEquals("ProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
+      assertEquals("ProductName",
+            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
+            .get(1)).getValue());
+
+      cliAction
+            .setQuery("ProductId:TestProductId OR ProductName:TestProductName");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.OR, bqc.getOperator());
+      assertEquals("ProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) bqc.getTerms().get(0)).getValue());
+      assertEquals("ProductName",
+            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("TestProductName", ((TermQueryCriteria) bqc.getTerms()
+            .get(1)).getValue());
+
+      cliAction
+            .setQuery("(ProductId:TestProductId OR ProductName:TestProductName) AND NominalDate:20110120");
+      cliAction.execute(printer);
+      assertEquals(1, clientSetQuery.getCriteria().size());
+      bqc = (BooleanQueryCriteria) clientSetQuery.getCriteria().get(0);
+      assertEquals(2, bqc.getTerms().size());
+      assertEquals(BooleanQueryCriteria.AND, bqc.getOperator());
+      BooleanQueryCriteria subBqc = (BooleanQueryCriteria) bqc.getTerms()
+            .get(0);
+      assertEquals("ProductId",
+            ((TermQueryCriteria) subBqc.getTerms().get(0)).getElementName());
+      assertEquals("TestProductId",
+            ((TermQueryCriteria) subBqc.getTerms().get(0)).getValue());
+      assertEquals("ProductName",
+            ((TermQueryCriteria) subBqc.getTerms().get(1)).getElementName());
+      assertEquals("TestProductName", ((TermQueryCriteria) subBqc.getTerms()
+            .get(1)).getValue());
+      assertEquals("NominalDate",
+            ((TermQueryCriteria) bqc.getTerms().get(1)).getElementName());
+      assertEquals("20110120",
+            ((TermQueryCriteria) bqc.getTerms().get(1)).getValue());
+   }
+
+   public class MockLuceneQueryCliAction extends LuceneQueryCliAction {
+      @Override
+      public XmlRpcFileManagerClient getClient() throws MalformedURLException,
+            ConnectionException {
+         return new XmlRpcFileManagerClient(new URL("http://localhost:9000"),
+               false) {
+            @Override
+            public List<Product> query(Query query, ProductType pt) {
+               clientSetQuery = query;
+               Product p = new Product();
+               p.setProductId("TestProductId");
+               p.setProductType(pt);
+               return Lists.newArrayList(p);
+            }
+
+            @Override
+            public List<ProductType> getProductTypes() {
+               ProductType pt = new ProductType();
+               pt.setName("TestProductType");
+               return Lists.newArrayList(pt);
+            }
+         };
+      }
+   }
+}

Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestLuceneQueryCliAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java?rev=1210199&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java Sun Dec  4 20:17:53 2011
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.cli.action;
+
+//JDK imports
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction.ActionMessagePrinter;
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+import org.apache.oodt.cas.filemgr.structs.Product;
+import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
+import org.apache.oodt.cas.filemgr.structs.query.ComplexQuery;
+import org.apache.oodt.cas.filemgr.structs.query.QueryResult;
+import org.apache.oodt.cas.filemgr.structs.query.conv.VersionConverter;
+import org.apache.oodt.cas.filemgr.structs.query.filter.FilterAlgor;
+import org.apache.oodt.cas.filemgr.structs.query.filter.TimeEvent;
+import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link SqlQueryCliAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestSqlQueryCliAction extends TestCase {
+
+   private static final String QUERY = "SELECT * FROM *";
+   private static final String SORT_BY = "Filename";
+   private static final String OUTPUT_FORMAT = "Filename = $Filename";
+   private static final String DELIMITER = ",";
+   private static final List<String> REDUCED_PRODUCT_TYPES = Lists.newArrayList("TestProductType");
+   private static final List<String> REDUCED_METADATA_KEYS = Lists.newArrayList("Filename");
+   private static final FilterAlgor FILTER_ALGOR = new MockFilterAlgor();
+   private static final String START_DATE_TIME_MET_KEY = "StartDateTime";
+   private static final String END_DATE_TIME_MET_KEY = "EndDateTime";
+   private static final String PRIORITY_DATE_TIME_MET_KEY = "PriorityDateTime";
+   private static final VersionConverter VERSION_CONV = new MockVersionConverter();
+
+   private static final String TEST_FILENAME = "data.dat";
+
+   private ComplexQuery clientSetComplexQuery;
+
+   public void testValidateErrors() throws CmdLineActionException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockSqlQueryCliAction cliAction = new MockSqlQueryCliAction();
+      try {
+         cliAction.execute(printer);
+         fail("Expected throw CmdLineActionException");
+      } catch (CmdLineActionException ignore) {
+      }
+      cliAction.setQuery(QUERY);
+      cliAction.execute(printer); // Should not throw exception.
+      cliAction.setFilterAlgor(FILTER_ALGOR);
+      try {
+         cliAction.execute(printer);
+         fail("Expected throw CmdLineActionException");
+      } catch (CmdLineActionException ignore) {
+      }
+      cliAction.setStartDateTimeMetKey(START_DATE_TIME_MET_KEY);
+      cliAction.setEndDateTimeMetKey(END_DATE_TIME_MET_KEY);
+      cliAction.setPriorityMetKey(PRIORITY_DATE_TIME_MET_KEY);
+      cliAction.execute(printer); // Should not throw exception.
+      cliAction.setConverter(VERSION_CONV);
+      cliAction.execute(printer); // Should not throw exception.
+   }
+
+   public void testClientTransTrueAndFlatProduct() throws CmdLineActionException, IOException {
+      ActionMessagePrinter printer = new ActionMessagePrinter();
+      MockSqlQueryCliAction cliAction = new MockSqlQueryCliAction();
+      cliAction.setQuery(QUERY);
+      cliAction.setSortBy(SORT_BY);
+      cliAction.setOutputFormat(OUTPUT_FORMAT);
+      cliAction.setDelimiter(DELIMITER);
+      cliAction.setReducedProductTypes(REDUCED_PRODUCT_TYPES);
+      cliAction.setReducedMetadataKeys(REDUCED_METADATA_KEYS);
+      cliAction.setFilterAlgor(FILTER_ALGOR);
+      cliAction.setStartDateTimeMetKey(START_DATE_TIME_MET_KEY);
+      cliAction.setEndDateTimeMetKey(END_DATE_TIME_MET_KEY);
+      cliAction.setPriorityMetKey(PRIORITY_DATE_TIME_MET_KEY);
+      cliAction.setConverter(VERSION_CONV);
+      cliAction.execute(printer);
+      assertEquals(2, printer.getPrintedMessages().size());
+      assertEquals("Filename = data.dat", printer.getPrintedMessages().get(0));
+      assertEquals("\n", printer.getPrintedMessages().get(1));
+      assertEquals(SORT_BY, clientSetComplexQuery.getSortByMetKey());
+      assertEquals(OUTPUT_FORMAT, clientSetComplexQuery.getToStringResultFormat());
+      assertEquals(REDUCED_PRODUCT_TYPES, clientSetComplexQuery.getReducedProductTypeNames());
+      assertEquals(REDUCED_METADATA_KEYS, clientSetComplexQuery.getReducedMetadata());
+      assertEquals(FILTER_ALGOR, clientSetComplexQuery.getQueryFilter().getFilterAlgor());
+      assertEquals(START_DATE_TIME_MET_KEY, clientSetComplexQuery.getQueryFilter().getStartDateTimeMetKey());
+      assertEquals(END_DATE_TIME_MET_KEY, clientSetComplexQuery.getQueryFilter().getEndDateTimeMetKey());
+      assertEquals(PRIORITY_DATE_TIME_MET_KEY, clientSetComplexQuery.getQueryFilter().getPriorityMetKey());
+      assertEquals(VERSION_CONV, clientSetComplexQuery.getQueryFilter().getConverter());
+   }
+
+   public class MockSqlQueryCliAction extends SqlQueryCliAction {
+      @Override
+      public XmlRpcFileManagerClient getClient() throws MalformedURLException,
+            ConnectionException {
+         return new XmlRpcFileManagerClient(new URL("http://localhost:9000"),
+               false) {
+            @Override
+            public List<QueryResult> complexQuery(ComplexQuery complexQuery) {
+               clientSetComplexQuery = complexQuery;
+               Product p = new Product();
+               p.setProductId("TestProductId");
+               Metadata m = new Metadata();
+               m.addMetadata("Filename", TEST_FILENAME);
+               QueryResult qr = new QueryResult(p, m);
+               qr.setToStringFormat(complexQuery.getToStringResultFormat());
+               return Lists.newArrayList(qr);
+            }
+         };
+      }
+   }
+
+   public static class MockFilterAlgor extends FilterAlgor {
+      @Override
+      public List<TimeEvent> filterEvents(List<TimeEvent> events) {
+         return events;
+      }
+   }
+
+   public static class MockVersionConverter implements VersionConverter {
+      @Override
+      public double convertToPriority(String version) throws Exception {
+         return 0;
+      }
+   }
+}

Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/cli/action/TestSqlQueryCliAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java?rev=1210199&view=auto
==============================================================================
--- oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java (added)
+++ oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java Sun Dec  4 20:17:53 2011
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.filemgr.system;
+
+//JDK imports
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.filemgr.structs.FileTransferStatus;
+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.exceptions.ConnectionException;
+import org.apache.oodt.cas.metadata.Metadata;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+/**
+ * A Mock {@link XmlRpcFileManagerClient}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockXmlRpcFileManagerClient extends XmlRpcFileManagerClient {
+
+   private MethodCallDetails lastMethodCallDetails;
+
+   public MockXmlRpcFileManagerClient() throws ConnectionException,
+         MalformedURLException {
+      super(new URL("http://localhost:9000"), false);
+   }
+
+   public MethodCallDetails getLastMethodCallDetails() {
+      return lastMethodCallDetails;
+   }
+
+   @Override
+   public String addProductType(ProductType productType) {
+      lastMethodCallDetails = new MethodCallDetails("addProductType",
+            Lists.newArrayList((Object) productType));
+      return "ProductTypeId";
+   }
+
+   @Override
+   public Product getProductById(String productId) {
+      lastMethodCallDetails = new MethodCallDetails("getProductById",
+            Lists.newArrayList((Object) productId));
+      Product p = new Product();
+      p.setProductId(productId);
+      p.setProductName("TestProductName");
+      p.setProductReferences(Lists.newArrayList(
+            new Reference("file:/orig/file", "file:/ds/file", 3)));
+      p.setProductStructure(Product.STRUCTURE_FLAT);
+      p.setTransferStatus(Product.STATUS_RECEIVED);
+      ProductType pt = new ProductType();
+      pt.setName("TestProductType");
+      p.setProductType(pt);
+      return p;
+   }
+
+   @Override
+   public Product getProductByName(String productName) {
+      lastMethodCallDetails = new MethodCallDetails("getProductByName",
+            Lists.newArrayList((Object) productName));
+      Product p = new Product();
+      p.setProductId("TestProductId");
+      p.setProductName(productName);
+      p.setProductReferences(Lists.newArrayList(
+            new Reference("file:/orig/file", "file:/ds/file", 3)));
+      p.setProductStructure(Product.STRUCTURE_FLAT);
+      p.setTransferStatus(Product.STATUS_RECEIVED);
+      ProductType pt = new ProductType();
+      pt.setName("TestProductType");
+      p.setProductType(pt);
+      return p;
+   }
+
+   @Override
+   public List<Reference> getProductReferences(Product product) {
+      lastMethodCallDetails = new MethodCallDetails("getProductReferences",
+            Lists.newArrayList((Object) product));
+      return Lists.newArrayList();
+   }
+
+   @Override
+   public boolean removeProduct(Product product) {
+      lastMethodCallDetails = new MethodCallDetails("removeProduct",
+            Lists.newArrayList((Object) product));
+      return true;
+   }
+
+   @Override
+   public boolean removeFile(String file) {
+      lastMethodCallDetails = new MethodCallDetails("removeFile",
+            Lists.newArrayList((Object) file));
+      return true;
+   }
+
+   @Override
+   public FileTransferStatus getCurrentFileTransfer() {
+      lastMethodCallDetails = new MethodCallDetails("getCurrentFileTransfer",
+            Lists.newArrayList());
+      FileTransferStatus status = new FileTransferStatus();
+      status.setBytesTransferred(10);
+      status.setFileRef(new Reference("file:/orig/file", "file:/ds/file", 4));
+      Product p = new Product();
+      p.setProductId("TestProductId");
+      status.setParentProduct(p);
+      return status;
+   }
+
+   @Override
+   public List<FileTransferStatus> getCurrentFileTransfers() {
+      lastMethodCallDetails = new MethodCallDetails("getCurrentFileTransfers",
+            Lists.newArrayList());
+      FileTransferStatus status = new FileTransferStatus();
+      status.setBytesTransferred(10);
+      status.setFileRef(new Reference("file:/orig/file", "file:/ds/file", 4));
+      Product p = new Product();
+      p.setProductId("TestProductId");
+      status.setParentProduct(p);
+      return Lists.newArrayList(status);
+   }
+
+   @Override
+   public double getRefPctTransferred(Reference ref) {
+      lastMethodCallDetails = new MethodCallDetails("getRefPctTransferred",
+            Lists.newArrayList((Object) ref));
+      return 0.6;
+   }
+
+   @Override
+   public ProductType getProductTypeByName(String productTypeName) {
+      lastMethodCallDetails = new MethodCallDetails("getProductTypeByName",
+            Lists.newArrayList((Object) productTypeName));
+      ProductType pt = new ProductType();
+      pt.setName(productTypeName);
+      return pt;
+   }
+
+   @Override
+   public ProductPage getFirstPage(ProductType type) {
+      lastMethodCallDetails = new MethodCallDetails("getFirstPage",
+            Lists.newArrayList((Object) type));
+      ProductPage pp = new ProductPage();
+      pp.setNumOfHits(0);
+      pp.setPageProducts(new ArrayList<Product>());
+      pp.setPageSize(10);
+      pp.setTotalPages(0);
+      pp.setPageNum(1);
+      return pp;
+   }
+
+   @Override
+   public ProductPage getLastPage(ProductType type) {
+      lastMethodCallDetails = new MethodCallDetails("getLastPage",
+            Lists.newArrayList((Object) type));
+      ProductPage pp = new ProductPage();
+      pp.setNumOfHits(0);
+      pp.setPageProducts(new ArrayList<Product>());
+      pp.setPageSize(10);
+      pp.setTotalPages(0);
+      pp.setPageNum(1);
+      return pp;
+   }
+
+   @Override
+   public ProductPage getNextPage(ProductType type, ProductPage curPage) {
+      lastMethodCallDetails = new MethodCallDetails("getNextPage",
+            Lists.newArrayList((Object) type, curPage));
+      ProductPage pp = new ProductPage();
+      pp.setNumOfHits(0);
+      pp.setPageProducts(new ArrayList<Product>());
+      pp.setPageSize(10);
+      pp.setTotalPages(0);
+      pp.setPageNum(curPage.getPageNum() + 1);
+      return pp;
+   }
+
+   @Override
+   public ProductPage getPrevPage(ProductType type, ProductPage curPage) {
+      lastMethodCallDetails = new MethodCallDetails("getPrevPage",
+            Lists.newArrayList((Object) type, curPage));
+      ProductPage pp = new ProductPage();
+      pp.setNumOfHits(0);
+      pp.setPageProducts(new ArrayList<Product>());
+      pp.setPageSize(10);
+      pp.setTotalPages(0);
+      pp.setPageNum(curPage.getPageNum() - 1);
+      return pp;
+   }
+
+   @Override
+   public int getNumProducts(ProductType type) {
+      lastMethodCallDetails = new MethodCallDetails("getNumProducts",
+            Lists.newArrayList((Object) type));
+      return 0;
+   }
+
+   @Override
+   public double getProductPctTransferred(Product product) {
+      lastMethodCallDetails = new MethodCallDetails("getProductPctTransferred",
+            Lists.newArrayList((Object) product));
+      return 0.6;
+   }
+
+   @Override
+   public boolean hasProduct(String productName) {
+      lastMethodCallDetails = new MethodCallDetails("hasProduct",
+            Lists.newArrayList((Object) productName));
+      return true;
+   }
+
+   @Override
+   public String ingestProduct(Product p, Metadata m, boolean clientTransfer) {
+      lastMethodCallDetails = new MethodCallDetails("ingestProduct",
+            Lists.newArrayList((Object) p, m, clientTransfer));
+      return "TestProductId";
+   }
+
+   @Override
+   public List<ProductType> getProductTypes() {
+      lastMethodCallDetails = new MethodCallDetails("getProductTypes",
+            Lists.newArrayList());
+      ProductType pt = new ProductType();
+      pt.setName("TestProductType");
+      return Lists.newArrayList(pt);
+   }
+
+   @Override
+   public List<Product> query(Query query, ProductType type) {
+      lastMethodCallDetails = new MethodCallDetails("query",
+            Lists.newArrayList((Object) query, type));
+      return Lists.newArrayList();
+   }
+
+   @Override
+   public Metadata getMetadata(Product p) {
+      lastMethodCallDetails = new MethodCallDetails("getMetadata",
+            Lists.newArrayList((Object) p));
+      return new Metadata();
+   }
+
+   public class MethodCallDetails {
+      private String methodName;
+      private List<Object> args;
+
+      public MethodCallDetails(String methodName, List<Object> args) {
+         this.methodName = methodName;
+         this.args = args;
+      }
+
+      public String getMethodName() {
+         return methodName;
+      }
+
+      public List<Object> getArgs() {
+         return args;
+      }
+   }
+}

Propchange: oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/system/MockXmlRpcFileManagerClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain