Cleanup Session management and timeout
[java-idp.git] / tests / edu / internet2 / middleware / shibboleth / serviceprovider / TestContextInitializer.java
1 package edu.internet2.middleware.shibboleth.serviceprovider;
2
3 import java.io.File;
4
5 import edu.internet2.middleware.shibboleth.common.Credentials;
6 import edu.internet2.middleware.shibboleth.common.ShibbolethConfigurationException;
7 import edu.internet2.middleware.shibboleth.serviceprovider.ServiceProviderConfig.ApplicationInfo;
8
9 public class TestContextInitializer extends SPTestCase {
10         private static ServiceProviderContext context   = ServiceProviderContext.getInstance();
11     
12     /**
13      * Load an SP configuration file.
14      * @param configFileName URL format string pointing to configuration file
15      * @throws ShibbolethConfigurationException
16      */
17         public void initServiceProvider(String configFileName) 
18         throws ShibbolethConfigurationException{
19             context.initialize();
20                         ServiceProviderConfig config = new ServiceProviderConfig();
21                         context.setServiceProviderConfig(config);
22                         config.loadConfigObjects(configFileName);
23         }
24         
25     /**
26      * Load the typical sample configuration file from the usual place.
27      */
28         public void testStandardConfiguration() throws ShibbolethConfigurationException {
29                 String configFileName = new File("data/spconfig.xml").toURI().toString();
30                 initServiceProvider(configFileName);
31                 ServiceProviderConfig config = context.getServiceProviderConfig();
32                 Credentials credentials = config.getCredentials();
33                 ApplicationInfo appinfo = config.getApplication("default");
34         }
35     
36         
37     /**
38      * Try to load a URL that doesn't point to a file.
39      */
40         public void testBadConfigurationName() {
41                 String configFileName = new File("data/spconfig-bogus.xml").toURI().toString();;
42                 try {
43             initServiceProvider(configFileName);
44             fail();
45         } catch (ShibbolethConfigurationException e) {
46             // Expected result
47         }
48         }
49 }