[java-opensaml] 03/16: Add unit test for new handler. Adjust existing test for symmetry.

Brent Putman putmanb at georgetown.edu
Sun Dec 17 00:08:13 EST 2017


This is an automated email from the git hooks/post-receive script.

putmanb pushed a commit to branch master
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=49c41d687819f464d734af4b47c1774d5ccca670

commit 49c41d687819f464d734af4b47c1774d5ccca670
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Fri Sep 1 17:46:16 2017 -0400

    Add unit test for new handler. Adjust existing test for symmetry.
---
 .../PopulateSignatureSigningParametersTest.java    | 79 +++++++++++-----------
 .../PopulateSignatureSigningParametersTest.java    | 15 ++--
 2 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/PopulateSignatureSigningParametersTest.java
similarity index 66%
copy from opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
copy to opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/PopulateSignatureSigningParametersTest.java
index 79f8ab1..a85d527 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/binding/impl/PopulateSignatureSigningParametersTest.java
@@ -15,22 +15,17 @@
  * limitations under the License.
  */
 
-package org.opensaml.saml.common.profile.impl;
+package org.opensaml.saml.common.binding.impl;
 
 import java.util.Collections;
 
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
-import net.shibboleth.utilities.java.support.logic.Constraint;
-import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
-import net.shibboleth.utilities.java.support.resolver.ResolverException;
-
 import org.opensaml.core.OpenSAMLInitBaseTestCase;
+import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
+import org.opensaml.messaging.handler.MessageHandlerException;
 import org.opensaml.profile.RequestContextBuilder;
-import org.opensaml.profile.action.ActionTestingSupport;
-import org.opensaml.profile.action.EventIds;
 import org.opensaml.profile.context.ProfileRequestContext;
-import org.opensaml.profile.context.navigate.OutboundMessageContextLookup;
+import org.opensaml.profile.context.navigate.ParentProfileRequestContextLookup;
 import org.opensaml.xmlsec.SignatureSigningParameters;
 import org.opensaml.xmlsec.SignatureSigningParametersResolver;
 import org.opensaml.xmlsec.context.SecurityParametersContext;
@@ -41,67 +36,71 @@ import org.testng.annotations.Test;
 
 import com.google.common.base.Functions;
 
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.logic.ConstraintViolationException;
+import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
+import net.shibboleth.utilities.java.support.resolver.ResolverException;
+
 /** Unit test for {@link PopulateSignatureSigningParameters}. */
 public class PopulateSignatureSigningParametersTest extends OpenSAMLInitBaseTestCase {
 
     private ProfileRequestContext prc;
     
-    private PopulateSignatureSigningParameters action;
+    private PopulateSignatureSigningParameters handler;
     
     @BeforeMethod public void setUp() {
         prc = new RequestContextBuilder().buildProfileRequestContext();
-        action = new PopulateSignatureSigningParameters();
+        handler = new PopulateSignatureSigningParameters();
     }
     
     @Test(expectedExceptions=ComponentInitializationException.class)
     public void testConfig() throws ComponentInitializationException {
-        action.initialize();
+        handler.initialize();
     }
     
-    @Test public void testNoContext() throws Exception {
-        action.setSignatureSigningParametersResolver(new MockResolver(false));
-        action.initialize();
+    @Test(expectedExceptions=ConstraintViolationException.class)
+    public void testNoContext() throws Exception {
+        handler.setSignatureSigningParametersResolver(new MockResolver(false));
+        handler.initialize();
         
         prc.setOutboundMessageContext(null);
         
-        action.execute(prc);
-        ActionTestingSupport.assertEvent(prc, EventIds.INVALID_MSG_CTX);
+        handler.invoke(prc.getOutboundMessageContext());
     }
     
-    @Test public void testResolverError() throws Exception {
-        action.setSignatureSigningParametersResolver(new MockResolver(true));
-        action.initialize();
+    @Test(expectedExceptions=MessageHandlerException.class)
+    public void testResolverError() throws Exception {
+        handler.setSignatureSigningParametersResolver(new MockResolver(true));
+        handler.initialize();
         
-        action.execute(prc);
-        ActionTestingSupport.assertEvent(prc, EventIds.MESSAGE_PROC_ERROR);
+        handler.invoke(prc.getOutboundMessageContext());
     }    
 
-    @Test public void testSuccess() throws Exception {
-        action.setSignatureSigningParametersResolver(new MockResolver(false));
-        action.initialize();
+    @Test
+    public void testSuccess() throws Exception {
+        handler.setSignatureSigningParametersResolver(new MockResolver(false));
+        handler.initialize();
         
-        action.execute(prc);
-        ActionTestingSupport.assertProceedEvent(prc);
+        handler.invoke(prc.getOutboundMessageContext());
         Assert.assertNotNull(prc.getOutboundMessageContext().getSubcontext(
                 SecurityParametersContext.class).getSignatureSigningParameters());
     }    
 
-    @Test public void testCopy() throws Exception {
-        action.setSignatureSigningParametersResolver(new MockResolver(true));
-        action.setExistingParametersContextLookupStrategy(
+    @Test
+    public void testCopy() throws Exception {
+        // Test copy from PRC to MessageContext
+        handler.setSignatureSigningParametersResolver(new MockResolver(true));
+        handler.setExistingParametersContextLookupStrategy(
                 Functions.compose(new ChildContextLookup(SecurityParametersContext.class),
-                        new OutboundMessageContextLookup()));
-        action.setSecurityParametersContextLookupStrategy(
-                new ChildContextLookup<ProfileRequestContext,SecurityParametersContext>(
-                        SecurityParametersContext.class, true));
-        action.initialize();
+                        new ParentProfileRequestContextLookup()));
+        handler.setSecurityParametersContextLookupStrategy(
+                new ChildContextLookup<MessageContext,SecurityParametersContext>(SecurityParametersContext.class, true));
+        handler.initialize();
         
-        prc.getOutboundMessageContext().getSubcontext(
-                SecurityParametersContext.class, true).setSignatureSigningParameters(
-                        new SignatureSigningParameters());
+        prc.getSubcontext(SecurityParametersContext.class, true).setSignatureSigningParameters(new SignatureSigningParameters());
         
-        action.execute(prc);
-        ActionTestingSupport.assertProceedEvent(prc);
+        handler.invoke(prc.getOutboundMessageContext());
         Assert.assertSame(prc.getSubcontext(SecurityParametersContext.class).getSignatureSigningParameters(),
                 prc.getOutboundMessageContext().getSubcontext(SecurityParametersContext.class).getSignatureSigningParameters());
     }    
diff --git a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
index 79f8ab1..b08b4be 100644
--- a/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
+++ b/opensaml-saml-impl/src/test/java/org/opensaml/saml/common/profile/impl/PopulateSignatureSigningParametersTest.java
@@ -25,6 +25,7 @@ import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
 import net.shibboleth.utilities.java.support.resolver.ResolverException;
 
 import org.opensaml.core.OpenSAMLInitBaseTestCase;
+import org.opensaml.messaging.context.MessageContext;
 import org.opensaml.messaging.context.navigate.ChildContextLookup;
 import org.opensaml.profile.RequestContextBuilder;
 import org.opensaml.profile.action.ActionTestingSupport;
@@ -87,18 +88,16 @@ public class PopulateSignatureSigningParametersTest extends OpenSAMLInitBaseTest
     }    
 
     @Test public void testCopy() throws Exception {
+        // Test copy from PRC to MessageContext
         action.setSignatureSigningParametersResolver(new MockResolver(true));
-        action.setExistingParametersContextLookupStrategy(
-                Functions.compose(new ChildContextLookup(SecurityParametersContext.class),
-                        new OutboundMessageContextLookup()));
+        action.setExistingParametersContextLookupStrategy(new ChildContextLookup(SecurityParametersContext.class));
         action.setSecurityParametersContextLookupStrategy(
-                new ChildContextLookup<ProfileRequestContext,SecurityParametersContext>(
-                        SecurityParametersContext.class, true));
+                Functions.compose(
+                        new ChildContextLookup<MessageContext,SecurityParametersContext>(SecurityParametersContext.class, true),
+                        new OutboundMessageContextLookup()));
         action.initialize();
         
-        prc.getOutboundMessageContext().getSubcontext(
-                SecurityParametersContext.class, true).setSignatureSigningParameters(
-                        new SignatureSigningParameters());
+        prc.getSubcontext(SecurityParametersContext.class, true).setSignatureSigningParameters(new SignatureSigningParameters());
         
         action.execute(prc);
         ActionTestingSupport.assertProceedEvent(prc);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list