b52b4d552a34eb30848d5bfb1a711500fae029d2
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / serviceprovider / TestContextInitializer.java
1 package edu.internet2.middleware.shibboleth.serviceprovider;
2
3 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
4
5 public class TestContextInitializer extends SPTestCase {
6         private static ServiceProviderContext context   = ServiceProviderContext.getInstance();
7     
8     /**
9      * Load an SP configuration file.
10      * @param configFileName URL format string pointing to configuration file
11      * @throws ShibbolethConfigurationException
12      */
13         public void initServiceProvider(String configFileName) throws ShibbolethConfigurationException{
14                         ServiceProviderConfig config = new ServiceProviderConfig();
15                         context.setServiceProviderConfig(config);
16                         config.loadConfigObjects(configFileName);
17         }
18         
19     /**
20      * Load the typical sample configuration file from the usual place.
21      */
22         public void testStandardConfiguration() throws ShibbolethConfigurationException {
23                 String configFileName = "file:///usr/local/shibboleth-sp/etc/sp.xml";
24                 initServiceProvider(configFileName);
25         }
26     
27     /**
28      * Try to load a URL that doesn't point to a file.
29      */
30         public void testBadConfigurationName() {
31                 String configFileName = "file:///usr/local/shibboleth-sp/etc/spp.xml";
32                 try {
33             initServiceProvider(configFileName);
34             fail();
35         } catch (ShibbolethConfigurationException e) {
36             // Expected result
37         }
38         }
39 }