Create JUnit tests
[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) throws ShibbolethConfigurationException{
18                         ServiceProviderConfig config = new ServiceProviderConfig();
19                         context.setServiceProviderConfig(config);
20                         config.loadConfigObjects(configFileName);
21         }
22         
23     /**
24      * Load the typical sample configuration file from the usual place.
25      */
26         public void testStandardConfiguration() throws ShibbolethConfigurationException {
27                 String configFileName = new File("data/spconfig.xml").toURI().toString();
28                 initServiceProvider(configFileName);
29                 ServiceProviderConfig config = context.getServiceProviderConfig();
30                 Credentials credentials = config.getCredentials();
31                 ApplicationInfo appinfo = config.getApplication("default");
32         }
33     
34         
35     /**
36      * Try to load a URL that doesn't point to a file.
37      */
38         public void testBadConfigurationName() {
39                 String configFileName = new File("data/spconfig-bogus.xml").toURI().toString();;
40                 try {
41             initServiceProvider(configFileName);
42             fail();
43         } catch (ShibbolethConfigurationException e) {
44             // Expected result
45         }
46         }
47 }