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 2010/07/18 22:00:54 UTC
svn commit: r965278 - in /incubator/oodt/trunk/metadata: ./
src/test/org/apache/oodt/cas/metadata/extractors/ src/testdata/
Author: mattmann
Date: Sun Jul 18 20:00:54 2010
New Revision: 965278
URL: http://svn.apache.org/viewvc?rev=965278&view=rev
Log:
- OODT-15 WIP: 3/4 metadata tests passing using SK's new test harness
Modified:
incubator/oodt/trunk/metadata/pom.xml
incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestCopyAndRewriteExtractor.java
incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestExternMetExtractor.java
incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestMetReader.java
incubator/oodt/trunk/metadata/src/testdata/copyandrewrite.test.conf
incubator/oodt/trunk/metadata/src/testdata/extern-config.xml
incubator/oodt/trunk/metadata/src/testdata/samplemet.xml
incubator/oodt/trunk/metadata/src/testdata/testExtractor
incubator/oodt/trunk/metadata/src/testdata/testfile2.txt.met
Modified: incubator/oodt/trunk/metadata/pom.xml
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/pom.xml?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/pom.xml (original)
+++ incubator/oodt/trunk/metadata/pom.xml Sun Jul 18 20:00:54 2010
@@ -63,32 +63,17 @@ the License.
<directory>${basedir}/src/testdata</directory>
<includes>
<include>extern-config.xml</include>
+ <include>copyandrewrite.test.conf</include>
+ <include>extern-config.xml</include>
<include>met_extr_preconditions.xml</include>
<include>samplemet.xml</include>
+ <include>testExtractor</include>
<include>testfile.txt</include>
<include>testfile2.txt.met</include>
<include>testfile2.txt</include>
<include>tika-mimetypes.xml</include>
</includes>
</testResource>
- <testResource>
- <targetPath>org/apache/oodt/cas/metadata/extractors</targetPath>
- <directory>${basedir}/src/testdata</directory>
- <includes>
- <include>copyandrewrite.test.conf</include>
- <include>samplemet.xml</include>
- <include>testfile.txt</include>
- <include>testfile2.txt</include>
- <include>testfile2.txt.met</include>
- </includes>
- </testResource>
- <testResource>
- <targetPath>org/apache/oodt/cas/metadata/extractors</targetPath>
- <directory>${basedir}/src/testdata</directory>
- <includes>
- <include>extern-config.xml</include>
- </includes>
- </testResource>
</testResources>
<plugins>
<plugin>
@@ -97,7 +82,7 @@ the License.
<systemProperties>
<property>
<name>java.util.logging.config.file</name>
- <value>${basedir}/src/main/resources/examples/logging.properties</value>
+ <value>${basedir}/src/main/resources/logging.properties</value>
</property>
</systemProperties>
<forkMode>never</forkMode>
Modified: incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestCopyAndRewriteExtractor.java
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestCopyAndRewriteExtractor.java?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestCopyAndRewriteExtractor.java (original)
+++ incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestCopyAndRewriteExtractor.java Sun Jul 18 20:00:54 2010
@@ -19,17 +19,18 @@ package org.apache.oodt.cas.metadata.ext
//OODT imports
import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.MetadataTestCase;
//JDK imports
import java.io.File;
-
-//Junit imports
-import junit.framework.TestCase;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Properties;
/**
* Tests the CopyAndRewriteExtractor.
*/
-public class TestCopyAndRewriteExtractor extends TestCase {
+public class TestCopyAndRewriteExtractor extends MetadataTestCase {
private CopyAndRewriteExtractor extractor;
@@ -39,43 +40,29 @@ public class TestCopyAndRewriteExtractor
private static final String PRODUCT_TYPE = "ProductType";
- private static final String confFilePath = "copyandrewrite.test.conf";
-
- private static final String extractFilePath = "testfile.txt";
-
- private static final String expectedFilename = "testfile.txt";
-
private static final String expectedProductType = "NewProductTypeGenericFile";
+
+ private static final String expectedFilename = "testfile.txt";
- private static String expectedFileLocation = null;
-
- static {
- try {
- expectedFileLocation = "/new/loc/"
- + new File(TestCopyAndRewriteExtractor.class.getResource(
- extractFilePath).getFile()).getParentFile().getCanonicalPath();
- } catch (Exception ignore) {
- }
- }
-
- public TestCopyAndRewriteExtractor() {
- CopyAndRewriteConfig config = new CopyAndRewriteConfig();
- try {
- config.load(getClass().getResourceAsStream(confFilePath));
- } catch (Exception e) {
- fail(e.getMessage());
- }
-
- extractor = new CopyAndRewriteExtractor();
- extractor.setConfigFile(config);
+ private String expectedFileLocation;
+
+ private File confFile;
+
+ private File sampleMetFile;
+
+ private File extractFile;
+
+ public TestCopyAndRewriteExtractor(String name) {
+ super(name);
}
+
+
public void testExtractMetadata() {
Metadata met = null;
try {
- met = extractor.extractMetadata(getClass().getResource(extractFilePath)
- .getFile());
+ met = extractor.extractMetadata(this.extractFile.getCanonicalPath());
} catch (Exception e) {
fail(e.getMessage());
}
@@ -99,12 +86,74 @@ public class TestCopyAndRewriteExtractor
Metadata met = null;
try {
- met = extractor.extractMetadata(getClass().getResource(extractFilePath)
- .getFile());
+ met = extractor.extractMetadata(this.extractFile.getCanonicalPath());
} catch (Exception e) {
fail(e.getMessage());
}
assertNotNull(met);
}
+
+
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ String confFilename = "copyandrewrite.test.conf";
+ String sampleMetFilename = "samplemet.xml";
+ String extractFilename = "testfile.txt";
+ String origMetFilePath = "orig.met.file.path";
+
+ // get all the needed files staged
+ this.sampleMetFile = super.getTestDataFile(sampleMetFilename);
+ this.extractFile = super.getTestDataFile(extractFilename);
+
+
+ // this is a java properties file
+ this.confFile = super.getTestDataFile(confFilename);
+
+ // we need to compute and override orig.met.file.path
+ Properties confProps = new Properties();
+ confProps.load(new FileInputStream(confFile));
+ confProps.setProperty(origMetFilePath, sampleMetFile.getAbsolutePath());
+ confProps.store(new FileOutputStream(confFile), null);
+
+
+ try {
+ this.expectedFileLocation = "/new/loc/"
+ + this.extractFile.getParentFile().getCanonicalPath();
+ } catch (Exception ignore) {
+ }
+
+
+ CopyAndRewriteConfig config = new CopyAndRewriteConfig();
+ try {
+ config.load(new FileInputStream(this.confFile));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ this.extractor = new CopyAndRewriteExtractor();
+ this.extractor.setConfigFile(config);
+
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.apache.oodt.cas.metadata.MetadataTestCase#tearDown()
+ */
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if(this.confFile != null) this.confFile = null;
+ if(this.sampleMetFile != null) this.sampleMetFile = null;
+ if(this.extractFile != null) this.extractFile = null;
+ this.expectedFileLocation = null;
+ }
+
+
}
Modified: incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestExternMetExtractor.java
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestExternMetExtractor.java?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestExternMetExtractor.java (original)
+++ incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestExternMetExtractor.java Sun Jul 18 20:00:54 2010
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -15,83 +15,142 @@
* limitations under the License.
*/
-
package org.apache.oodt.cas.metadata.extractors;
//OODT imports
+import org.apache.commons.io.FileUtils;
import org.apache.oodt.cas.metadata.Metadata;
+import org.apache.oodt.cas.metadata.MetadataTestCase;
import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
+import org.apache.oodt.cas.metadata.util.PathUtils;
+import org.apache.oodt.commons.exec.ExecUtils;
//JDK imports
import java.io.File;
-import junit.framework.TestCase;
+import java.net.URLEncoder;
/**
- * @author mattmann
- * @version $Revision$
*
- * <p>
- * Test Suite for the {@link ExternMetExtractor}
- * </p>.
+ * Test Suite for the {@link ExternMetExtractor}
+ * .
*/
-public class TestExternMetExtractor extends TestCase {
-
- private ExternMetExtractor extractor;
-
- private static final String FILENAME = "Filename";
+public class TestExternMetExtractor extends MetadataTestCase {
- private static final String FILE_LOCATION = "FileLocation";
+ private ExternMetExtractor extractor;
- private static final String PRODUCT_TYPE = "ProductType";
+ private static final String FILENAME = "Filename";
- private static final String configFilePath = "extern-config.xml";
+ private static final String FILE_LOCATION = "FileLocation";
- private static final String extractFilePath = "testfile.txt";
+ private static final String PRODUCT_TYPE = "ProductType";
- private static final String expectedFilename = "testfile.txt";
+ private static final String expectedFilename = "testfile.txt";
- private static final String expectedFileLocation = ".";
+ private static final String expectedProductType = "GenericFile";
+
+ private File extractFile;
+
+ private File confFile;
+
+ private File metFile;
+
+ private String expectedFileLocation;
+
+ public TestExternMetExtractor(String name){
+ super(name);
+ }
- private static final String expectedProductType = "GenericFile";
+ public void testExtractor() {
- public void testExtractor() {
- try {
- extractor = new ExternMetExtractor();
- } catch (InstantiationException e) {
- fail(e.getMessage());
- }
-
- Metadata met = null;
-
- try {
- met = extractor.extractMetadata(new File(getClass().getResource(extractFilePath).getFile()),
- new File(getClass().getResource(configFilePath).getFile()));
- } catch (MetExtractionException e) {
- fail(e.getMessage());
- }
-
- assertNotNull(met);
- assertTrue(new File(getClass().getResource("testfile.txt.met").getFile()).exists());
- assertTrue(met.containsKey(FILENAME));
- assertTrue(met.containsKey(FILE_LOCATION));
- assertTrue(met.containsKey(PRODUCT_TYPE));
-
- assertEquals(expectedFilename, met.getMetadata(FILENAME));
- assertEquals(expectedFileLocation, met.getMetadata(FILE_LOCATION));
- assertEquals(expectedProductType, met.getMetadata(PRODUCT_TYPE));
+ Metadata met = null;
+ try {
+ met = extractor.extractMetadata(this.extractFile, this.confFile);
+ } catch (MetExtractionException e) {
+ fail(e.getMessage());
}
- /*
- * (non-Javadoc)
- *
- * @see junit.framework.TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- File generatedMetFile = new File(getClass().getResource("testfile.txt.met").getFile());
- if (generatedMetFile.exists()) {
- generatedMetFile.delete();
- }
+ assertNotNull(met);
+ assertTrue(this.metFile.exists());
+ assertTrue(met.containsKey(FILENAME));
+ assertTrue(met.containsKey(FILE_LOCATION));
+ assertTrue(met.containsKey(PRODUCT_TYPE));
+
+ assertEquals(expectedFilename, met.getMetadata(FILENAME));
+ assertEquals("Expected: ["+this.expectedFileLocation+"]; Actual: ["+met.getMetadata(FILE_LOCATION)+"]", this.expectedFileLocation, met.getMetadata(FILE_LOCATION));
+ assertEquals(expectedProductType, met.getMetadata(PRODUCT_TYPE));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oodt.cas.metadata.MetadataTestCase#tearDown()
+ */
+ public void tearDown() throws Exception {
+ super.tearDown();
+ if (this.metFile != null && this.metFile.exists()) {
+ this.metFile.delete();
+ this.metFile = null;
+ }
+
+ if(this.confFile != null) this.confFile = null;
+ if(this.extractFile != null) this.extractFile = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.oodt.cas.metadata.MetadataTestCase#setUp()
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ String configFilename = "extern-config.xml";
+ String extractFilename = "testfile.txt";
+ String extractorFilename = "testExtractor";
+ String sampleMetFilename = "samplemet.xml";
+
+ this.confFile = super.getTestDataFile(configFilename);
+ this.extractFile = super.getTestDataFile(extractFilename);
+ this.metFile = new File(this.extractFile.getCanonicalPath()+".met");
+ this.expectedFileLocation = this.extractFile.getParent();
+
+ File extractorFile = super.getTestDataFile(extractorFilename);
+
+ // make it executable
+ // yes this is ghetto
+ String chmodCmd = "chmod +x "+extractorFile.getAbsolutePath();
+ ExecUtils.callProgram(chmodCmd, extractorFile.getParentFile());
+
+ // replace the FileLocation met field in the sample met file
+ // with the actual file location of the extractFile
+ File sampleMetFile = super.getTestDataFile(sampleMetFilename);
+ String sampleMetFileContents = FileUtils.readFileToString(sampleMetFile);
+ String extractFileLocKey = "[EXTRACT_FILE_LOC]";
+ sampleMetFileContents = sampleMetFileContents.replace(extractFileLocKey, URLEncoder.encode(extractFile.getParent(), "UTF-8"));
+ FileUtils.writeStringToFile(sampleMetFile, sampleMetFileContents, "UTF-8");
+
+ // replace the path to the sample met file inside of testExtractor
+ String extractorFileContents = FileUtils.readFileToString(extractorFile);
+ String sampleMetFilePathKey = "<TEST_SAMPLE_MET_PATH>";
+ extractorFileContents = extractorFileContents.replace(sampleMetFilePathKey, sampleMetFile.getAbsolutePath());
+ FileUtils.writeStringToFile(extractorFile, extractorFileContents);
+
+ // replace path in confFile named TEST_PATH
+ String testPathKey = "TEST_PATH";
+ String confFileContents = FileUtils.readFileToString(this.confFile);
+ Metadata replaceMet = new Metadata();
+ replaceMet.addMetadata(testPathKey, extractorFile.getParent());
+ confFileContents = PathUtils.replaceEnvVariables(confFileContents, replaceMet);
+ FileUtils.writeStringToFile(this.confFile, confFileContents);
+
+
+ try {
+ extractor = new ExternMetExtractor();
+ } catch (InstantiationException e) {
+ fail(e.getMessage());
}
+ }
}
Modified: incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestMetReader.java
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestMetReader.java?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestMetReader.java (original)
+++ incubator/oodt/trunk/metadata/src/test/org/apache/oodt/cas/metadata/extractors/TestMetReader.java Sun Jul 18 20:00:54 2010
@@ -1,4 +1,4 @@
-/*
+/**
* 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.
@@ -20,24 +20,19 @@ package org.apache.oodt.cas.metadata.ext
//JDK imports
import java.io.File;
+import java.net.URLEncoder;
//OODT imports
+import org.apache.commons.io.FileUtils;
import org.apache.oodt.cas.metadata.MetExtractor; //for javadoc
import org.apache.oodt.cas.metadata.Metadata;
-import org.apache.oodt.cas.metadata.exceptions.MetExtractionException;
-
-//Junit imports
-import junit.framework.TestCase;
+import org.apache.oodt.cas.metadata.MetadataTestCase;
/**
- * @author mattmann
- * @version $Revision$
*
- * <p>
* Test case for the {@link MetReaderExtractor} {@link MetExtractor}
- * </p>.
*/
-public class TestMetReader extends TestCase {
+public class TestMetReader extends MetadataTestCase {
private MetReaderExtractor extractor;
@@ -45,26 +40,26 @@ public class TestMetReader extends TestC
private static final String expectedFilename = "testfile.txt";
- private static final String expectedFileLocation = ".";
-
- private static final String testFile = "testfile2.txt";
-
private static final String FILENAME = "Filename";
private static final String FILE_LOCATION = "FileLocation";
private static final String PRODUCT_TYPE = "ProductType";
-
- public TestMetReader() {
- extractor = new MetReaderExtractor();
+
+ private String expectedFileLocation;
+
+ private File extractFile;
+
+ public TestMetReader(String name) {
+ super(name);
}
public void testExtractMetadata() {
Metadata met = null;
try {
- met = extractor.extractMetadata(getClass().getResource(testFile).getFile());
- } catch (MetExtractionException e) {
+ met = extractor.extractMetadata(this.extractFile.getCanonicalPath());
+ } catch (Exception e) {
fail(e.getMessage());
}
@@ -81,4 +76,35 @@ public class TestMetReader extends TestC
}
+ /* (non-Javadoc)
+ * @see org.apache.oodt.cas.metadata.MetadataTestCase#setUp()
+ */
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ String extractFilename = "testfile2.txt";
+ String sampleMetFilename = "testfile2.txt.met";
+ this.extractFile = super.getTestDataFile(extractFilename);
+ this.expectedFileLocation = this.extractFile.getParent();
+
+ // replace the FileLocation met field in the sample met file
+ // with the actual file location of the extractFile
+ File sampleMetFile = super.getTestDataFile(sampleMetFilename);
+ String sampleMetFileContents = FileUtils.readFileToString(sampleMetFile);
+ String extractFileLocKey = "[EXTRACT_FILE_LOC]";
+ sampleMetFileContents = sampleMetFileContents.replace(extractFileLocKey, URLEncoder.encode(extractFile.getParent(), "UTF-8"));
+ FileUtils.writeStringToFile(sampleMetFile, sampleMetFileContents, "UTF-8");
+
+ this.extractor = new MetReaderExtractor();
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.oodt.cas.metadata.MetadataTestCase#tearDown()
+ */
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ }
+
}
Modified: incubator/oodt/trunk/metadata/src/testdata/copyandrewrite.test.conf
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/testdata/copyandrewrite.test.conf?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/testdata/copyandrewrite.test.conf (original)
+++ incubator/oodt/trunk/metadata/src/testdata/copyandrewrite.test.conf Sun Jul 18 20:00:54 2010
@@ -1,6 +1,5 @@
numRewriteFields=2
rewriteField1=ProductType
rewriteField2=FileLocation
-orig.met.file.path=[PWD]/target/test-classes/org/apache/oodt/cas/metadata/extractors/samplemet.xml
ProductType.pattern=NewProductType[ProductType]
FileLocation.pattern=/new/loc/[FileLocation]
Modified: incubator/oodt/trunk/metadata/src/testdata/extern-config.xml
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/testdata/extern-config.xml?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/testdata/extern-config.xml (original)
+++ incubator/oodt/trunk/metadata/src/testdata/extern-config.xml Sun Jul 18 20:00:54 2010
@@ -33,7 +33,7 @@ the License.
<!-- you can optionally specify envReplace tag (=true)
to turn on environment variable replacement
-->
- <extractorBinPath envReplace="true">[PWD]/src/testdata/testExtractor</extractorBinPath>
+ <extractorBinPath>[TEST_PATH]/testExtractor</extractorBinPath>
<!-- make sure to use character entities if there are any weird
parameters here that would screw up the XML.
Modified: incubator/oodt/trunk/metadata/src/testdata/samplemet.xml
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/testdata/samplemet.xml?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/testdata/samplemet.xml (original)
+++ incubator/oodt/trunk/metadata/src/testdata/samplemet.xml Sun Jul 18 20:00:54 2010
@@ -7,7 +7,7 @@
</keyval>
<keyval>
<key>FileLocation</key>
- <val>.</val>
+ <val>[EXTRACT_FILE_LOC]</val>
</keyval>
<keyval>
<key>ProductType</key>
Modified: incubator/oodt/trunk/metadata/src/testdata/testExtractor
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/testdata/testExtractor?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/testdata/testExtractor (original)
+++ incubator/oodt/trunk/metadata/src/testdata/testExtractor Sun Jul 18 20:00:54 2010
@@ -17,5 +17,5 @@ set PROD_DIR
if [ $PROD_DIR = $MET_DIR ]; then
# just copy the sample metadata
- cp samplemet.xml $MET_FILE
+ cp <TEST_SAMPLE_MET_PATH> $MET_FILE
fi
Modified: incubator/oodt/trunk/metadata/src/testdata/testfile2.txt.met
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/metadata/src/testdata/testfile2.txt.met?rev=965278&r1=965277&r2=965278&view=diff
==============================================================================
--- incubator/oodt/trunk/metadata/src/testdata/testfile2.txt.met (original)
+++ incubator/oodt/trunk/metadata/src/testdata/testfile2.txt.met Sun Jul 18 20:00:54 2010
@@ -7,7 +7,7 @@
</keyval>
<keyval>
<key>FileLocation</key>
- <val>.</val>
+ <val>[EXTRACT_FILE_LOC]</val>
</keyval>
<keyval>
<key>ProductType</key>