Create JUnit tests
authorgilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 23 Jun 2005 19:22:19 +0000 (19:22 +0000)
committergilbert <gilbert@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Thu, 23 Jun 2005 19:22:19 +0000 (19:22 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@1664 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

tests/edu/internet2/middleware/shibboleth/serviceprovider/SPTestCase.java [new file with mode: 0644]
tests/edu/internet2/middleware/shibboleth/serviceprovider/TestContextInitializer.java [new file with mode: 0644]

diff --git a/tests/edu/internet2/middleware/shibboleth/serviceprovider/SPTestCase.java b/tests/edu/internet2/middleware/shibboleth/serviceprovider/SPTestCase.java
new file mode 100644 (file)
index 0000000..d08f5cc
--- /dev/null
@@ -0,0 +1,24 @@
+package edu.internet2.middleware.shibboleth.serviceprovider;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Layout;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PatternLayout;
+
+import junit.framework.TestCase;
+
+/**
+ * A base class that sets up Log4J. Real tests extend it.
+ */
+public class SPTestCase extends TestCase {
+    
+    public SPTestCase() {
+        Logger root = Logger.getRootLogger();
+        Layout initLayout = new PatternLayout("%d{HH:mm} %-5p %m%n");
+        ConsoleAppender consoleAppender= new ConsoleAppender(initLayout,ConsoleAppender.SYSTEM_OUT);
+        root.addAppender(consoleAppender);
+        root.setLevel(Level.ERROR);
+    }
+
+}
diff --git a/tests/edu/internet2/middleware/shibboleth/serviceprovider/TestContextInitializer.java b/tests/edu/internet2/middleware/shibboleth/serviceprovider/TestContextInitializer.java
new file mode 100644 (file)
index 0000000..b52b4d5
--- /dev/null
@@ -0,0 +1,39 @@
+package edu.internet2.middleware.shibboleth.serviceprovider;
+
+import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
+
+public class TestContextInitializer extends SPTestCase {
+       private static ServiceProviderContext context   = ServiceProviderContext.getInstance();
+    
+    /**
+     * Load an SP configuration file.
+     * @param configFileName URL format string pointing to configuration file
+     * @throws ShibbolethConfigurationException
+     */
+       public void initServiceProvider(String configFileName) throws ShibbolethConfigurationException{
+                       ServiceProviderConfig config = new ServiceProviderConfig();
+                       context.setServiceProviderConfig(config);
+                       config.loadConfigObjects(configFileName);
+       }
+       
+    /**
+     * Load the typical sample configuration file from the usual place.
+     */
+       public void testStandardConfiguration() throws ShibbolethConfigurationException {
+               String configFileName = "file:///usr/local/shibboleth-sp/etc/sp.xml";
+               initServiceProvider(configFileName);
+       }
+    
+    /**
+     * Try to load a URL that doesn't point to a file.
+     */
+       public void testBadConfigurationName() {
+               String configFileName = "file:///usr/local/shibboleth-sp/etc/spp.xml";
+               try {
+            initServiceProvider(configFileName);
+            fail();
+        } catch (ShibbolethConfigurationException e) {
+            // Expected result
+        }
+       }
+}