Author: kelly
Date: Wed Jul 14 22:48:52 2010
New Revision: 964236

URL: http://svn.apache.org/viewvc?rev=964236&view=rev
Log:
WIP OODT-15 Additional test cases for features that will likely never be used 
again

Added:
    
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AbstractTestCase.java
    incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AppTest.java
    
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfigurationTest.java
    
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfiguredTestCaseTest.java
    
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/MultiServerTest.java
    
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/NaughtyTest.java

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AbstractTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AbstractTestCase.java?rev=964236&view=auto
==============================================================================
--- 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AbstractTestCase.java
 (added)
+++ 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AbstractTestCase.java
 Wed Jul 14 22:48:52 2010
@@ -0,0 +1,55 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Abstract base class for test cases.
+ *
+ * @author <a href="[email protected]">Jason van Zyl</a>
+ */
+public abstract class AbstractTestCase
+    extends TestCase 
+{
+    /** 
+     * Basedir for all file I/O. Important when running tests from
+     * the reactor.
+     */
+    public String basedir = System.getProperty("basedir");
+    
+    /**
+     * Constructor.
+     */
+    public AbstractTestCase(String testName)
+    {
+        super(testName);
+    }
+    
+    /**
+     * Get test input file.
+     *
+     * @param path Path to test input file.
+     */
+    public String getTestFile(String path)
+    {
+        return new File(basedir,path).getAbsolutePath();
+    }
+}
+

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AppTest.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AppTest.java?rev=964236&view=auto
==============================================================================
--- incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AppTest.java 
(added)
+++ incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/AppTest.java 
Wed Jul 14 22:48:52 2010
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ *
+ * @author <a href="mailto:[email protected]";>Jason van Zyl</a>
+ */
+public class AppTest 
+    extends AbstractTestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertEquals( "maven kicks ass", "maven kicks ass" );
+    }
+}

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfigurationTest.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfigurationTest.java?rev=964236&view=auto
==============================================================================
--- 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfigurationTest.java
 (added)
+++ 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfigurationTest.java
 Wed Jul 14 22:48:52 2010
@@ -0,0 +1,103 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.util.*;
+import junit.framework.*;
+import org.w3c.dom.*;
+import org.xml.sax.*;
+
+/** Unit test the {...@link Configuration} class.
+ *
+ * @author Kelly
+ */ 
+public class ConfigurationTest extends TestCase {
+       /** Construct the test case for the {...@link Configuration} class. */
+       public ConfigurationTest(String name) {
+               super(name);
+       }
+
+       protected void setUp() throws Exception {
+               // Create a temporary test configuration file.
+               tmpFile = File.createTempFile("conf", ".xml");
+               BufferedOutputStream out = new BufferedOutputStream(new 
FileOutputStream(tmpFile));
+               byte[] doc = TEST_DOC.getBytes();
+               out.write(doc, 0, doc.length);
+               out.close();
+               oldValue = System.getProperty(Configuration.ENTITY_DIRS_PROP);
+               System.setProperty(Configuration.ENTITY_DIRS_PROP, 
"/dir/1,/dir/2");
+       }
+
+       protected void tearDown() throws Exception {
+               // Nuke the temporary test configuration file.
+               tmpFile.delete();
+               if (oldValue == null)
+                       
System.getProperties().remove(Configuration.ENTITY_DIRS_PROP);
+               else
+                       System.setProperty(Configuration.ENTITY_DIRS_PROP, 
oldValue);
+       }
+
+       /** Test the various property methods. */
+       public void testConfiguration() throws IOException, SAXException, 
MalformedURLException {
+               Configuration c = new Configuration(tmpFile.toURL());
+               Properties props = new Properties();
+               props.setProperty("globalKey1", "preset-value");
+               c.mergeProperties(props);
+               assertEquals("preset-value", props.getProperty("globalKey1"));
+               assertEquals("globalValue2", props.getProperty("globalKey2"));
+               assertEquals("http://testhost.test.domain:12345";, 
c.getWebServerBaseURL());
+               assertEquals("http://testhost.test.domain:12345/ns.ior";, 
c.getNameServerURL());
+               assertEquals(42, c.getNameServerStateFrequency());
+               assertEquals(4, c.getEntityRefDirs().size());
+               assertTrue(c.getEntityRefDirs().contains("/dir/one"));
+               assertTrue(c.getEntityRefDirs().contains("/dir/two"));
+               assertTrue(c.getEntityRefDirs().contains("/dir/1"));
+               assertTrue(c.getEntityRefDirs().contains("/dir/2"));
+               assertEquals("/dir/1,/dir/2,/dir/one,/dir/two", 
System.getProperty(Configuration.ENTITY_DIRS_PROP));
+               Collection servers = c.getExecServerConfigs();
+               assertEquals(2, servers.size());
+               for (Iterator each = servers.iterator(); each.hasNext();) {
+                       ExecServerConfig esc = (ExecServerConfig) each.next();
+                       if (esc.getClassName().equals("test.Class1")) {
+                               assertEquals("Name1", esc.getObjectKey());
+                               assertEquals(1, esc.getProperties().size());
+                       } else if (esc.getClassName().equals("test.Class2")) {
+                               assertEquals("Name2", esc.getObjectKey());
+                               assertEquals(3, esc.getProperties().size());
+                               for (Iterator i = 
esc.getProperties().entrySet().iterator(); i.hasNext();) {
+                                       Map.Entry entry = (Map.Entry) i.next();
+                                       if (entry.getKey().equals("localKey1"))
+                                               assertEquals("localKey2", 
entry.getValue());
+                                       else if 
(entry.getKey().equals("globalKey2"))
+                                               assertEquals("local-override", 
entry.getValue());
+                                       else if 
(entry.getKey().equals("org.apache.oodt.commons.Configuration.url"))
+                                               ; // This one's OK.
+                                       else fail("Unknown local property \"" + 
entry.getKey() + "\" in exec server");
+                               }
+                       } else fail("Unknown ExecServerConfig \"" + 
esc.getClassName() + "\" in servers from Configuration");
+               }
+       }
+
+       /** The temporary test configuration file. */
+       private File tmpFile;
+
+       /** Old value of the {...@link Configuration#ENTITY_DIRS_PROP} system 
property. */
+       public String oldValue;
+
+       private static final String TEST_DOC = "<?xml 
version=\"1.0\"?>\n<!DOCTYPE configuration PUBLIC \"-//JPL//DTD EDA 
Configuration 1.0//EN\" 
\"http://enterprise.jpl.nasa.gov/dtd/configuration.dtd\";>\n<configuration><webServer><host>testhost.test.domain</host><port>12345</port></webServer><nameServer
 
stateFrequency=\"42\"><iiop><version>1.2</version><host>testhost.test.domain</host><port>12345</port><objectKey>TestService</objectKey></iiop></nameServer><xml><entityRef><dir>/dir/one</dir><dir>/dir/two</dir></entityRef></xml><properties><key>globalKey1</key><value>globalValue1</value><key>globalKey2</key><value>globalValue2</value></properties><programs><execServer><class>test.Class1</class><objectKey>Name1</objectKey></execServer><execServer><class>test.Class2</class><objectKey>Name2</objectKey><properties><key>localKey1</key><value>localKey2</value><key>globalKey2</key><value>local-override</value></properties></execServer></programs></configuration>";
+}

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfiguredTestCaseTest.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfiguredTestCaseTest.java?rev=964236&view=auto
==============================================================================
--- 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfiguredTestCaseTest.java
 (added)
+++ 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/ConfiguredTestCaseTest.java
 Wed Jul 14 22:48:52 2010
@@ -0,0 +1,66 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import junit.framework.TestCase;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Unit test the ConfiguredTestCase class.
+ *
+ * @author Kelly
+ */ 
+public class ConfiguredTestCaseTest extends TestCase {
+       /** Construct the test case for the ConfiguredTestCaseTest class.
+        *
+        * @param name Case name
+        */
+       public ConfiguredTestCaseTest(String name) {
+               super(name);
+       }
+
+       public void testIt() throws Exception {
+               Case c = new Case();
+               try {
+                       c.setUp();
+                       assertNotNull(Configuration.configuration);
+               } finally {
+                       c.tearDown();
+               }                       
+       }
+
+       public void testItAgain() throws Exception {
+               Case c = new Case();
+               try {
+                       c.setUp();
+                       assertNotNull(Configuration.configuration);
+               } finally {
+                       c.tearDown();
+               }                       
+       }
+
+       private static class Case extends ConfiguredTestCase {
+               Case() {
+                       super("test");
+               }
+               public void setUp() throws Exception {
+                       super.setUp();
+               }
+               public void tearDown() throws Exception {
+                       super.tearDown();
+               }
+       }               
+}

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/MultiServerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/MultiServerTest.java?rev=964236&view=auto
==============================================================================
--- 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/MultiServerTest.java
 (added)
+++ 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/MultiServerTest.java
 Wed Jul 14 22:48:52 2010
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import junit.framework.TestCase;
+import java.io.InputStream;
+import java.io.IOException;
+import org.xml.sax.InputSource;
+import java.rmi.server.RemoteObject;
+import javax.xml.parsers.ParserConfigurationException;
+import java.lang.reflect.InvocationTargetException;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit test the MultiServer class.
+ *
+ * @author Kelly
+ */ 
+public class MultiServerTest extends TestCase {
+       /**
+        * Construct the test case for the MultiServer class.
+        *
+        * @param name Case name
+        */
+       public MultiServerTest(String name) {
+               super(name);
+       }
+
+       protected void setUp() throws Exception {
+               super.setUp();
+               testConfig = 
getClass().getResourceAsStream("test-multiserver.xml");
+               if (testConfig == null) throw new IOException("Cannot find 
`test-multiserver.xml'");
+               System.setProperty("my.other.setting", "Don't override");
+       }
+
+       public void testParsing() throws ParserConfigurationException, 
SAXException, IOException, ClassNotFoundException,
+               NoSuchMethodException, InstantiationException, 
IllegalAccessException, InvocationTargetException {
+               InputSource is = new InputSource(testConfig);
+               MultiServer.parseConfig(is);
+               assertEquals("test.app", MultiServer.getAppName());
+               assertEquals(4, MultiServer.getServers().size());
+
+               MultiServer.Server server = (MultiServer.Server) 
MultiServer.getServers().get("urn:eda:rmi:Test1");
+               assertEquals("org.apache.oodt.commons.MultiServerTest$Svr1", 
server.getClassName());
+               assertEquals(MultiServer.BINDING, server.getBindingBehavior());
+
+               server = (MultiServer.Server) 
MultiServer.getServers().get("urn:eda:rmi:Test2");
+               assertEquals("org.apache.oodt.commons.MultiServerTest$Svr2", 
server.getClassName());
+               assertEquals(MultiServer.NONBINDING, 
server.getBindingBehavior());
+
+               server = (MultiServer.Server) 
MultiServer.getServers().get("urn:eda:rmi:Test3");
+               assertEquals("org.apache.oodt.commons.MultiServerTest$Svr3", 
server.getClassName());
+               assertEquals(MultiServer.REBINDING, 
server.getBindingBehavior());
+
+               MultiServer.AutobindingServer s = 
(MultiServer.AutobindingServer) 
MultiServer.getServers().get("urn:eda:rmi:Test4");
+               assertEquals("org.apache.oodt.commons.MultiServerTest$Svr4", 
s.getClassName());
+               assertEquals(MultiServer.AUTO, s.getBindingBehavior());
+               assertEquals(360000L, s.getPeriod());
+
+               assertEquals("My Value", System.getProperty("my.setting"));
+               assertEquals("Don't override", 
System.getProperty("my.other.setting"));
+       }
+
+       public void tearDown() throws Exception {
+               if (testConfig != null) try {
+                       testConfig.close();
+               } catch (IOException ignore) {}
+               System.getProperties().remove("my.setting");
+               System.getProperties().remove("my.other.setting");
+               super.tearDown();
+       }
+
+       private InputStream testConfig;
+
+       public static class Svr1 extends RemoteObject {
+               public Svr1(ExecServer e) {}
+       }
+       public static class Svr2 extends RemoteObject {
+               public Svr2(ExecServer e) {}
+       }
+       public static class Svr3 extends RemoteObject {
+               public Svr3(ExecServer e) {}
+       }
+       public static class Svr4 extends RemoteObject {
+               public Svr4(ExecServer e) {}
+       }
+}

Added: 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/NaughtyTest.java
URL: 
http://svn.apache.org/viewvc/incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/NaughtyTest.java?rev=964236&view=auto
==============================================================================
--- 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/NaughtyTest.java 
(added)
+++ 
incubator/oodt/trunk/commons/src/test/org/apache/oodt/commons/NaughtyTest.java 
Wed Jul 14 22:48:52 2010
@@ -0,0 +1,55 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+// license agreements.  See the NOTICE.txt 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.commons;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ *
+ * @author <a href="mailto:[email protected]";>Jason van Zyl</a>
+ */
+public class NaughtyTest
+    extends AbstractTestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public NaughtyTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( NaughtyTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        // Crash and burn!
+    }
+}


Reply via email to