cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject git commit: Adding more unit tests
Date Tue, 29 Jul 2014 10:35:47 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master 1cb119ea7 -> abd1fe2c6


Adding more unit tests


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/abd1fe2c
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/abd1fe2c
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/abd1fe2c

Branch: refs/heads/master
Commit: abd1fe2c617ba276ca061d52d72a85f7143d5a90
Parents: 1cb119e
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Tue Jul 29 11:13:43 2014 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Tue Jul 29 11:13:43 2014 +0100

----------------------------------------------------------------------
 .../fediz/core/config/CallbackHandlerTest.java  | 196 ++++++++++++-------
 .../core/config/FedizConfigurationTest.java     | 149 +++++++++++---
 .../config/FedizConfigurationWriterTest.java    | 139 ++++++++++---
 3 files changed, 363 insertions(+), 121 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/abd1fe2c/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
index 382c953..23b565b 100644
--- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
+++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/CallbackHandlerTest.java
@@ -40,6 +40,8 @@ import org.apache.cxf.fediz.core.config.jaxb.ContextConfig;
 import org.apache.cxf.fediz.core.config.jaxb.FederationProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.FedizConfig;
 import org.apache.cxf.fediz.core.config.jaxb.KeyStoreType;
+import org.apache.cxf.fediz.core.config.jaxb.ProtocolType;
+import org.apache.cxf.fediz.core.config.jaxb.SamlProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustManagersType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuerType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuers;
@@ -78,7 +80,7 @@ public class CallbackHandlerTest {
         SecurityTestUtil.cleanup();
     }
     
-    private FedizConfig createConfiguration() throws JAXBException {
+    private FedizConfig createConfiguration(boolean federation) throws JAXBException {
 
         FedizConfig rootConfig = new FedizConfig();
         ContextConfig config = new ContextConfig();
@@ -105,14 +107,31 @@ public class CallbackHandlerTest {
         ti0.setSubject(SUBJECT_VALUE);
         trustedIssuers.getIssuer().add(ti0);
         config.setTrustedIssuers(trustedIssuers);
-
-        FederationProtocolType protocol = new FederationProtocolType();
-        config.setProtocol(protocol);
-
+        
         AudienceUris audienceUris = new AudienceUris();
         audienceUris.getAudienceItem().add(AUDIENCE_URI);
         config.setAudienceUris(audienceUris);
 
+        ProtocolType protocol = null;
+        
+        if (federation) {
+            protocol = new FederationProtocolType();
+            
+            CallbackType freshness = new CallbackType();
+            freshness.setValue(FRESHNESS_VALUE);
+            ((FederationProtocolType)protocol).setFreshness(freshness);
+            
+            CallbackType realm = new CallbackType();
+            realm.setValue(TARGET_REALM);
+            protocol.setRealm(freshness);
+            
+            ((FederationProtocolType)protocol).setReply(REPLY);
+            ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION);
+        } else {
+            protocol = new SamlProtocolType();
+        }
+        config.setProtocol(protocol);
+        
         protocol.setRoleDelimiter(ROLE_DELIMITER);
         protocol.setRoleURI(ROLE_URI);
 
@@ -123,96 +142,89 @@ public class CallbackHandlerTest {
         claimTypeReq.getClaimType().add(claimType);
         protocol.setClaimTypesRequested(claimTypeReq);
         
-        CallbackType freshness = new CallbackType();
-        freshness.setValue(FRESHNESS_VALUE);
-        protocol.setFreshness(freshness);
-        
-        CallbackType realm = new CallbackType();
-        realm.setValue(TARGET_REALM);
-        protocol.setRealm(freshness);
-        
-        protocol.setReply(REPLY);
-        protocol.setVersion(PROTOCOL_VERSION);
-
         return rootConfig;
     }
     
-    private FedizConfig createConfigWithoutCB() throws JAXBException {
-        
-        FedizConfig config = createConfiguration();
-        FederationProtocolType protocol = (FederationProtocolType)config.getContextConfig().get(0).getProtocol();
+    private FedizConfig createConfigWithoutCB(boolean federation) throws JAXBException {
         
-        CallbackType homeRealm = new CallbackType();
-        homeRealm.setType(ArgumentType.STRING);
-        homeRealm.setValue(TestCallbackHandler.TEST_HOME_REALM);
-        protocol.setHomeRealm(homeRealm);
+        FedizConfig config = createConfiguration(federation);
+        ProtocolType protocol = config.getContextConfig().get(0).getProtocol();
         
         CallbackType issuer = new CallbackType();
         issuer.setType(ArgumentType.STRING);
         issuer.setValue(TestCallbackHandler.TEST_IDP);
         protocol.setIssuer(issuer);
         
-        CallbackType authType = new CallbackType();
-        authType.setType(ArgumentType.STRING);
-        authType.setValue(TestCallbackHandler.TEST_WAUTH);
-        protocol.setAuthenticationType(authType);
-        
-        CallbackType tokenRequest = new CallbackType();
-        tokenRequest.setType(ArgumentType.STRING);
-        tokenRequest.setValue(TestCallbackHandler.TEST_WREQ);
-        protocol.setRequest(tokenRequest);
-        
-        CallbackType signInQueryType = new CallbackType();
-        signInQueryType.setType(ArgumentType.STRING);
-        signInQueryType.setValue(TEST_SIGNIN_QUERY);
-        protocol.setSignInQuery(signInQueryType);
+        if (protocol instanceof FederationProtocolType) {
+            CallbackType homeRealm = new CallbackType();
+            homeRealm.setType(ArgumentType.STRING);
+            homeRealm.setValue(TestCallbackHandler.TEST_HOME_REALM);
+            ((FederationProtocolType)protocol).setHomeRealm(homeRealm);
+            
+            CallbackType authType = new CallbackType();
+            authType.setType(ArgumentType.STRING);
+            authType.setValue(TestCallbackHandler.TEST_WAUTH);
+            ((FederationProtocolType)protocol).setAuthenticationType(authType);
+            
+            CallbackType tokenRequest = new CallbackType();
+            tokenRequest.setType(ArgumentType.STRING);
+            tokenRequest.setValue(TestCallbackHandler.TEST_WREQ);
+            ((FederationProtocolType)protocol).setRequest(tokenRequest);
+            
+            CallbackType signInQueryType = new CallbackType();
+            signInQueryType.setType(ArgumentType.STRING);
+            signInQueryType.setValue(TEST_SIGNIN_QUERY);
+            ((FederationProtocolType)protocol).setSignInQuery(signInQueryType);
+        }
         
         return config;
     }
     
-    private FedizConfig createConfigCB() throws JAXBException {
+    private FedizConfig createConfigCB(boolean federation) throws JAXBException {
         
-        FedizConfig config = createConfiguration();
-        FederationProtocolType protocol = (FederationProtocolType)config.getContextConfig().get(0).getProtocol();
+        FedizConfig config = createConfiguration(federation);
+        ProtocolType protocol = config.getContextConfig().get(0).getProtocol();
         
-        CallbackType homeRealm = new CallbackType();
-        homeRealm.setType(ArgumentType.CLASS);
-        homeRealm.setValue(CALLBACKHANDLER_CLASS);
-        protocol.setHomeRealm(homeRealm);
+        CallbackType realmType = new CallbackType();
+        realmType.setType(ArgumentType.CLASS);
+        realmType.setValue(CALLBACKHANDLER_CLASS);
+        protocol.setRealm(realmType);
         
         CallbackType issuer = new CallbackType();
         issuer.setType(ArgumentType.CLASS);
         issuer.setValue(CALLBACKHANDLER_CLASS);
         protocol.setIssuer(issuer);
         
-        CallbackType authType = new CallbackType();
-        authType.setType(ArgumentType.CLASS);
-        authType.setValue(CALLBACKHANDLER_CLASS);
-        protocol.setAuthenticationType(authType);
-        
-        CallbackType tokenRequest = new CallbackType();
-        tokenRequest.setType(ArgumentType.CLASS);
-        tokenRequest.setValue(CALLBACKHANDLER_CLASS);
-        protocol.setRequest(tokenRequest);
-        
-        CallbackType signInQueryType = new CallbackType();
-        signInQueryType.setType(ArgumentType.CLASS);
-        signInQueryType.setValue(CALLBACKHANDLER_CLASS);
-        protocol.setSignInQuery(signInQueryType);
-        
-        CallbackType realmType = new CallbackType();
-        realmType.setType(ArgumentType.CLASS);
-        realmType.setValue(CALLBACKHANDLER_CLASS);
-        protocol.setRealm(realmType);
+        if (protocol instanceof FederationProtocolType) {
+            CallbackType homeRealm = new CallbackType();
+            homeRealm.setType(ArgumentType.CLASS);
+            homeRealm.setValue(CALLBACKHANDLER_CLASS);
+            ((FederationProtocolType)protocol).setHomeRealm(homeRealm);
+            
+            CallbackType authType = new CallbackType();
+            authType.setType(ArgumentType.CLASS);
+            authType.setValue(CALLBACKHANDLER_CLASS);
+            ((FederationProtocolType)protocol).setAuthenticationType(authType);
+            
+            CallbackType tokenRequest = new CallbackType();
+            tokenRequest.setType(ArgumentType.CLASS);
+            tokenRequest.setValue(CALLBACKHANDLER_CLASS);
+            ((FederationProtocolType)protocol).setRequest(tokenRequest);
+            
+            CallbackType signInQueryType = new CallbackType();
+            signInQueryType.setType(ArgumentType.CLASS);
+            signInQueryType.setValue(CALLBACKHANDLER_CLASS);
+            ((FederationProtocolType)protocol).setSignInQuery(signInQueryType);
+        }
         
         return config;
     }
     
     @org.junit.Test
-    public void testParamsWithCallbackHandler() throws Exception {
+    public void testParamsWithCallbackHandlerFederation() throws Exception {
         
         final JAXBContext jaxbContext = JAXBContext.newInstance(FedizConfig.class);
-        FedizConfig configOut = createConfigCB();
+        FedizConfig configOut = createConfigCB(true);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -277,10 +289,35 @@ public class CallbackHandlerTest {
     }
     
     @org.junit.Test
-    public void testParamsWithoutCallbackHandler() throws Exception {
+    public void testParamsWithCallbackHandlerSAML() throws Exception {
         
         final JAXBContext jaxbContext = JAXBContext.newInstance(FedizConfig.class);
-        FedizConfig configOut = createConfigWithoutCB();
+        FedizConfig configOut = createConfigCB(false);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        
+        FedizConfigurator configurator = new FedizConfigurator();
+        configurator.loadConfig(reader);
+        
+        FedizContext ctx = configurator.getFedizContext(CONFIG_NAME);
+        
+        SAMLProtocol protocol = (SAMLProtocol)ctx.getProtocol();
+        
+        Object issuerObj = protocol.getIssuer();
+        Assert.assertTrue(issuerObj instanceof CallbackHandler);
+        CallbackHandler issuerCB = (CallbackHandler)issuerObj;
+        IDPCallback callbackIDP = new IDPCallback(null);
+        issuerCB.handle(new Callback[] {callbackIDP});
+        String issuerURL = callbackIDP.getIssuerUrl().toString();
+        Assert.assertEquals(TestCallbackHandler.TEST_IDP, issuerURL);
+    }
+    
+    @org.junit.Test
+    public void testParamsWithoutCallbackHandlerFederation() throws Exception {
+        
+        final JAXBContext jaxbContext = JAXBContext.newInstance(FedizConfig.class);
+        FedizConfig configOut = createConfigWithoutCB(true);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -318,4 +355,27 @@ public class CallbackHandlerTest {
         Assert.assertEquals(TestCallbackHandler.TEST_SIGNIN_QUERY, signInQuery);
     }
     
+    @org.junit.Test
+    public void testParamsWithoutCallbackHandlerSAML() throws Exception {
+        
+        final JAXBContext jaxbContext = JAXBContext.newInstance(FedizConfig.class);
+        FedizConfig configOut = createConfigWithoutCB(false);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        
+        FedizConfigurator configurator = new FedizConfigurator();
+        configurator.loadConfig(reader);
+        
+        FedizContext ctx = configurator.getFedizContext(CONFIG_NAME);
+        
+        Protocol protocol = ctx.getProtocol();
+        
+        Object issuerObj = protocol.getIssuer();
+        Assert.assertTrue(issuerObj instanceof String);
+        String issuerURL = (String)issuerObj;
+        Assert.assertEquals(TestCallbackHandler.TEST_IDP, issuerURL);
+    }
+    
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/abd1fe2c/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
index 6e4fc61..8c379d6 100644
--- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
+++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationTest.java
@@ -39,6 +39,8 @@ import org.apache.cxf.fediz.core.config.jaxb.ContextConfig;
 import org.apache.cxf.fediz.core.config.jaxb.FederationProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.FedizConfig;
 import org.apache.cxf.fediz.core.config.jaxb.KeyStoreType;
+import org.apache.cxf.fediz.core.config.jaxb.ProtocolType;
+import org.apache.cxf.fediz.core.config.jaxb.SamlProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustManagersType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuerType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuers;
@@ -91,7 +93,7 @@ public class FedizConfigurationTest {
     }
 
     //CHECKSTYLE:OFF
-    private FedizConfig createConfiguration() throws JAXBException {
+    private FedizConfig createConfiguration(boolean federation) throws JAXBException {
 
         FedizConfig rootConfig = new FedizConfig();
         ContextConfig config = new ContextConfig();
@@ -152,21 +154,39 @@ public class FedizConfigurationTest {
         trustedIssuers.getIssuer().add(ti2);
         
         config.setTrustedIssuers(trustedIssuers);
-
-        FederationProtocolType protocol = new FederationProtocolType();
+        
+        ProtocolType protocol = null;
+        
+        if (federation) {
+            protocol = new FederationProtocolType();
+            
+            CallbackType authType = new CallbackType();
+            authType.setType(ArgumentType.STRING);
+            authType.setValue(AUTH_TYPE_VALUE);
+            ((FederationProtocolType)protocol).setAuthenticationType(authType);
+            
+            CallbackType freshness = new CallbackType();
+            freshness.setValue(FRESHNESS_VALUE);
+            ((FederationProtocolType)protocol).setFreshness(freshness);
+
+            CallbackType homeRealm = new CallbackType();
+            homeRealm.setType(ArgumentType.CLASS);
+            homeRealm.setValue(HOME_REALM_CLASS);
+            ((FederationProtocolType)protocol).setHomeRealm(homeRealm);
+            
+            ((FederationProtocolType)protocol).setReply(REPLY);
+            ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION);
+        } else {
+            protocol = new SamlProtocolType();
+        }
         config.setProtocol(protocol);
-
-        CallbackType authType = new CallbackType();
-        authType.setType(ArgumentType.STRING);
-        authType.setValue(AUTH_TYPE_VALUE);
-
+        
         AudienceUris audienceUris = new AudienceUris();
         audienceUris.getAudienceItem().add(AUDIENCE_URI_1);
         audienceUris.getAudienceItem().add(AUDIENCE_URI_2);
         audienceUris.getAudienceItem().add(AUDIENCE_URI_3);
         config.setAudienceUris(audienceUris);
 
-        protocol.setAuthenticationType(authType);
         protocol.setRoleDelimiter(ROLE_DELIMITER);
         protocol.setRoleURI(ROLE_URI);
 
@@ -183,22 +203,10 @@ public class FedizConfigurationTest {
 
         protocol.setClaimTypesRequested(claimTypeReq);
 
-        CallbackType freshness = new CallbackType();
-        freshness.setValue(FRESHNESS_VALUE);
-        protocol.setFreshness(freshness);
-
-        CallbackType homeRealm = new CallbackType();
-        homeRealm.setType(ArgumentType.CLASS);
-        homeRealm.setValue(HOME_REALM_CLASS);
-        protocol.setHomeRealm(homeRealm);
-
         CallbackType realm = new CallbackType();
         realm.setValue(TARGET_REALM);
         protocol.setRealm(realm);
         
-        protocol.setReply(REPLY);
-        protocol.setVersion(PROTOCOL_VERSION);
-        
         CallbackType issuer = new CallbackType();
         issuer.setValue(ISSUER);
         protocol.setIssuer(issuer);
@@ -208,11 +216,25 @@ public class FedizConfigurationTest {
     }
 
     @org.junit.Test
-    public void readWriteConfig() throws JAXBException {
+    public void readWriteConfigFederation() throws JAXBException {
+
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+        FedizConfig configOut = createConfiguration(true);
+
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        
+        StringReader reader = new StringReader(writer.toString());
+        jaxbContext.createUnmarshaller().unmarshal(reader);
+    }
+    
+    @org.junit.Test
+    public void readWriteConfigSAML() throws JAXBException {
 
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(false);
 
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
@@ -222,11 +244,34 @@ public class FedizConfigurationTest {
     }
 
     @org.junit.Test
-    public void testSaveAndLoadConfig() throws JAXBException, IOException {
+    public void testSaveAndLoadConfigFederation() throws JAXBException, IOException {
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+
+        FedizConfig configOut = createConfiguration(true);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        
+        FedizConfigurator configurator = new FedizConfigurator();
+        configurator.loadConfig(reader);
+
+        File f = new File(CONFIG_FILE);
+        f.createNewFile();
+
+        configurator.saveConfiguration(f);
+        
+        configurator = new FedizConfigurator();
+        f = new File(CONFIG_FILE);
+        configurator.loadConfig(f);
+    }
+    
+    @org.junit.Test
+    public void testSaveAndLoadConfigSAML() throws JAXBException, IOException {
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
 
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(false);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -245,13 +290,13 @@ public class FedizConfigurationTest {
     }
 
     @org.junit.Test
-    public void verifyConfig() throws JAXBException {
+    public void verifyConfigFederation() throws JAXBException {
 
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
 
         FedizConfigurator configurator = new FedizConfigurator();
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(true);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -270,8 +315,54 @@ public class FedizConfigurationTest {
     }
     
     @org.junit.Test
-    public void testTokenReplayCache() throws JAXBException, IOException {
-        FedizConfig config = createConfiguration();
+    public void verifyConfigSAML() throws JAXBException {
+
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+
+        FedizConfigurator configurator = new FedizConfigurator();
+        FedizConfig configOut = createConfiguration(false);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        configurator.loadConfig(reader);
+
+        ContextConfig config = configurator.getContextConfig(CONFIG_NAME);
+        Assert.assertNotNull(config);
+        AudienceUris audience = config.getAudienceUris();
+        Assert.assertEquals(3, audience.getAudienceItem().size());
+        Assert.assertTrue(config.getProtocol() instanceof SamlProtocolType);
+
+    }
+    
+    @org.junit.Test
+    public void testTokenReplayCacheFederation() throws JAXBException, IOException {
+        FedizConfig config = createConfiguration(true);
+        
+        // Test the default TokenReplayCache
+        ReplayCache defaultReplayCache = parseConfigAndReturnTokenReplayCache(config);
+        Assert.assertNotNull(defaultReplayCache);
+        Assert.assertTrue(defaultReplayCache instanceof EHCacheReplayCache);
+        
+        // Now test setting another TokenReplayCache
+        ContextConfig contextConfig = config.getContextConfig().get(0);
+        contextConfig.setTokenReplayCache("org.apache.wss4j.common.cache.MemoryReplayCache");
+        
+        ReplayCache newReplayCache = parseConfigAndReturnTokenReplayCache(config);
+        Assert.assertNotNull(newReplayCache);
+        Assert.assertTrue(newReplayCache instanceof MemoryReplayCache);
+        
+        // Now test setting another TokenReplayCache
+        contextConfig.setTokenReplayCache("org.apache.wss4j.common.cache.EHCacheReplayCache");
+        
+        newReplayCache = parseConfigAndReturnTokenReplayCache(config);
+        Assert.assertNotNull(newReplayCache);
+        Assert.assertTrue(newReplayCache instanceof EHCacheReplayCache);
+    }
+    
+    @org.junit.Test
+    public void testTokenReplayCacheSAML() throws JAXBException, IOException {
+        FedizConfig config = createConfiguration(false);
         
         // Test the default TokenReplayCache
         ReplayCache defaultReplayCache = parseConfigAndReturnTokenReplayCache(config);

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/abd1fe2c/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
----------------------------------------------------------------------
diff --git a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
index 7a7f604..e396398 100644
--- a/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
+++ b/plugins/core/src/test/java/org/apache/cxf/fediz/core/config/FedizConfigurationWriterTest.java
@@ -41,6 +41,8 @@ import org.apache.cxf.fediz.core.config.jaxb.FederationProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.FedizConfig;
 import org.apache.cxf.fediz.core.config.jaxb.KeyManagersType;
 import org.apache.cxf.fediz.core.config.jaxb.KeyStoreType;
+import org.apache.cxf.fediz.core.config.jaxb.ProtocolType;
+import org.apache.cxf.fediz.core.config.jaxb.SamlProtocolType;
 import org.apache.cxf.fediz.core.config.jaxb.TokenValidators;
 import org.apache.cxf.fediz.core.config.jaxb.TrustManagersType;
 import org.apache.cxf.fediz.core.config.jaxb.TrustedIssuerType;
@@ -95,7 +97,7 @@ public class FedizConfigurationWriterTest {
     }
 
     //CHECKSTYLE:OFF
-    private FedizConfig createConfiguration() throws JAXBException {
+    private FedizConfig createConfiguration(boolean federation) throws JAXBException {
 
         FedizConfig rootConfig = new FedizConfig();
         ContextConfig config = new ContextConfig();
@@ -104,9 +106,6 @@ public class FedizConfigurationWriterTest {
         config.setName(CONFIG_NAME);
         config.setMaximumClockSkew(new BigInteger(CLOCK_SKEW));
 
-        FederationProtocolType protocol = new FederationProtocolType();
-        config.setProtocol(protocol);
-
         KeyManagersType sigManager = new KeyManagersType();
         sigManager.setKeyPassword(KEY_PASSWORD);
         sigManager.setKeyAlias(KEY_ALIAS);
@@ -150,9 +149,31 @@ public class FedizConfigurationWriterTest {
         AudienceUris audienceUris = new AudienceUris();
         audienceUris.getAudienceItem().add(AUDIENCE_URI_1);
         config.setAudienceUris(audienceUris);
+        
+        ProtocolType protocol = null;
+        
+        if (federation) {
+            protocol = new FederationProtocolType();
+            
+            ((FederationProtocolType)protocol).setAuthenticationType(authType);
+            ((FederationProtocolType)protocol).setRequest(tokenRequest);
+            
+            CallbackType freshness = new CallbackType();
+            freshness.setValue(FRESHNESS_VALUE);
+            ((FederationProtocolType)protocol).setFreshness(freshness);
+
+            CallbackType homeRealm = new CallbackType();
+            homeRealm.setType(ArgumentType.CLASS);
+            homeRealm.setValue(HOME_REALM_CLASS);
+            ((FederationProtocolType)protocol).setHomeRealm(homeRealm);
+            
+            ((FederationProtocolType)protocol).setReply(REPLY);
+            ((FederationProtocolType)protocol).setVersion(PROTOCOL_VERSION);
+        } else {
+            protocol = new SamlProtocolType();
+        }
+        config.setProtocol(protocol);
 
-        protocol.setAuthenticationType(authType);
-        protocol.setRequest(tokenRequest);
         protocol.setRoleDelimiter(ROLE_DELIMITER);
         protocol.setRoleURI(ROLE_URI);
 
@@ -168,22 +189,10 @@ public class FedizConfigurationWriterTest {
 
         protocol.setClaimTypesRequested(claimTypeReq);
 
-        CallbackType freshness = new CallbackType();
-        freshness.setValue(FRESHNESS_VALUE);
-        protocol.setFreshness(freshness);
-
-        CallbackType homeRealm = new CallbackType();
-        homeRealm.setType(ArgumentType.CLASS);
-        homeRealm.setValue(HOME_REALM_CLASS);
-        protocol.setHomeRealm(homeRealm);
-        
         CallbackType realm = new CallbackType();
         realm.setValue(TARGET_REALM);
         protocol.setRealm(realm);
         
-        protocol.setReply(REPLY);
-        protocol.setVersion(PROTOCOL_VERSION);
-        
         CallbackType issuer = new CallbackType();
         issuer.setValue(ISSUER);
         protocol.setIssuer(issuer);
@@ -198,11 +207,25 @@ public class FedizConfigurationWriterTest {
     }
 
     @org.junit.Test
-    public void readWriteConfig() throws JAXBException {
+    public void readWriteConfigFederation() throws JAXBException {
+
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+        FedizConfig configOut = createConfiguration(true);
+
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+
+        StringReader reader = new StringReader(writer.toString());
+        jaxbContext.createUnmarshaller().unmarshal(reader);
+    }
+    
+    @org.junit.Test
+    public void readWriteConfigSAML() throws JAXBException {
 
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(false);
 
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
@@ -212,12 +235,34 @@ public class FedizConfigurationWriterTest {
     }
 
     @org.junit.Test
-    public void testSaveAndLoadConfig() throws JAXBException, IOException {
+    public void testSaveAndLoadConfigFederation() throws JAXBException, IOException {
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+
+        FedizConfigurator configurator = new FedizConfigurator();
+        FedizConfig configOut = createConfiguration(true);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        configurator.loadConfig(reader);
+
+        File f = new File(CONFIG_FILE);
+        f.createNewFile();
+
+        configurator.saveConfiguration(f);
+        
+        configurator = new FedizConfigurator();
+        f = new File(CONFIG_FILE);
+        configurator.loadConfig(f);
+    }
+    
+    @org.junit.Test
+    public void testSaveAndLoadConfigSAML() throws JAXBException, IOException {
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
 
         FedizConfigurator configurator = new FedizConfigurator();
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(false);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -234,7 +279,7 @@ public class FedizConfigurationWriterTest {
     }
 
     @org.junit.Test
-    public void verifyConfig() throws JAXBException {
+    public void verifyConfigFederation() throws JAXBException {
 
         final JAXBContext jaxbContext = JAXBContext
                 .newInstance(FedizConfig.class);
@@ -244,7 +289,7 @@ public class FedizConfigurationWriterTest {
          */
 
         FedizConfigurator configurator = new FedizConfigurator();
-        FedizConfig configOut = createConfiguration();
+        FedizConfig configOut = createConfiguration(true);
         StringWriter writer = new StringWriter();
         jaxbContext.createMarshaller().marshal(configOut, writer);
         StringReader reader = new StringReader(writer.toString());
@@ -291,5 +336,51 @@ public class FedizConfigurationWriterTest {
         Assert.assertEquals(1, trustManagers.size());
 
     }
+    
+    @org.junit.Test
+    public void verifyConfigSAML() throws JAXBException {
+
+        final JAXBContext jaxbContext = JAXBContext
+                .newInstance(FedizConfig.class);
+        
+        /**
+         * Test JAXB part
+         */
+
+        FedizConfigurator configurator = new FedizConfigurator();
+        FedizConfig configOut = createConfiguration(false);
+        StringWriter writer = new StringWriter();
+        jaxbContext.createMarshaller().marshal(configOut, writer);
+        StringReader reader = new StringReader(writer.toString());
+        configurator.loadConfig(reader);
+
+        ContextConfig config = configurator.getContextConfig(CONFIG_NAME);
+        Assert.assertNotNull(config);
+        AudienceUris audience = config.getAudienceUris();
+        Assert.assertEquals(1, audience.getAudienceItem().size());
+        Assert.assertTrue(config.getProtocol() instanceof SamlProtocolType);
+
+        /**
+         * Check Runtime configuration
+         */
+        FedizContext fedContext = configurator.getFedizContext(CONFIG_NAME);
+        Protocol protocol = fedContext.getProtocol();
+        Assert.assertTrue(protocol instanceof SAMLProtocol);
+        SAMLProtocol samlProtocol = (SAMLProtocol) protocol;
+        Assert.assertEquals(TARGET_REALM, samlProtocol.getRealm());
+        
+        List<String> audienceUris = fedContext.getAudienceUris();
+        Assert.assertEquals(1, audienceUris.size());
+        List<TrustedIssuer> trustedIssuers = fedContext.getTrustedIssuers();
+        Assert.assertEquals(1, trustedIssuers.size());
+        TrustedIssuer issuer = trustedIssuers.get(0);
+        Assert.assertEquals(TRUST_ISSUER_NAME, issuer.getName());
+        Assert.assertEquals(CertificateValidationMethod.CHAIN_TRUST, issuer.getCertificateValidationMethod());
+        Assert.assertEquals(TRUST_ISSUER_CERT_CONSTRAINT, issuer.getSubject());
+        
+        List<TrustManager> trustManagers = fedContext.getCertificateStores();
+        Assert.assertEquals(1, trustManagers.size());
+
+    }
 
 }


Mime
View raw message