diff --git a/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/Capture.java b/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/Capture.java new file mode 100644 index 0000000..27975fd --- /dev/null +++ b/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/Capture.java @@ -0,0 +1,60 @@ +/* + * Copyright 2006, Queensland University of Technology + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + * + * Author: Bradley Beddoes + * Creation Date: 11/10/2006 + * + * Purpose: Allows mock objects to capture and store objects which are created in private space inside the class being tested, + * this in turn allows our testing framework to interrogate objects for correctness which it could otherwise never achieve. This implementation + * allows for multiple objects to be captured and referenced. + * + */ + +package com.qut.middleware.esoe.authn.plugins.usernamepassword; + +import static org.easymock.EasyMock.reportMatcher; + +import java.util.Vector; + +import org.easymock.IArgumentMatcher; + +public class Capture implements IArgumentMatcher +{ + private Vector captured = new Vector(); + + public void appendTo(StringBuffer buffer) + { + buffer.append("capture()"); + } + + public boolean matches(Object parameter) + { + captured.add( (T) parameter ); + + return true; + } + + public Vector getCaptured() + { + return captured; + } + + public static T capture(Capture capture) + { + reportMatcher(capture); + + return null; + } + +} diff --git a/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/UsernamePasswordHandlerTest.java b/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/UsernamePasswordHandlerTest.java index fe39b06..cad9d7c 100644 --- a/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/UsernamePasswordHandlerTest.java +++ b/esoeauthnplugins/usernamepassword/tests/regression/com/qut/middleware/esoe/authn/plugins/usernamepassword/UsernamePasswordHandlerTest.java @@ -1,27 +1,32 @@ -/* +/* * Copyright 2006, Queensland University of Technology - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under * the License. - * + * * Author: Bradley Beddoes * Creation Date: 10/10/2006 - * + * * Purpose: Executes all paths of UsernamePasswordHandler to verify logic - * + * * Built using easymock objects http://www.easymock.org */ package com.qut.middleware.esoe.authn.plugins.usernamepassword; -import static org.easymock.EasyMock.*; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -47,12 +52,9 @@ import com.qut.middleware.esoe.authn.plugins.usernamepassword.handler.UsernamePasswordHandler; import com.qut.middleware.esoe.sessions.Create; import com.qut.middleware.esoe.sessions.SessionsProcessor; -import com.qut.middleware.esoe.sessions.exception.DataSourceException; -import com.qut.middleware.esoe.sessions.exception.DuplicateSessionException; import com.qut.middleware.esoe.sessions.exception.SessionCacheUpdateException; import com.qut.middleware.saml2.AuthenticationContextConstants; import com.qut.middleware.saml2.identifier.IdentifierGenerator; -import com.qut.middleware.test.Capture; @SuppressWarnings(value = { "unqualified-field-access", "nls" }) public class UsernamePasswordHandlerTest @@ -74,7 +76,7 @@ public class UsernamePasswordHandlerTest List ident; Capture captured; - + private String usernamePasswordURL = "https://esoe.url/usernamePass.html"; private String failNameVal = "rc=authn"; @@ -128,7 +130,7 @@ private void setupHandler() this.redirectTarget = "http://esoe.qut.edu.au/logon/index.do"; this.failURL = "http://esoe.qut.edu.au/logon/difficulties.do"; - + this.handler = new UsernamePasswordHandler(this.authenticator, this.sessionsProcessor, this.identifierGenerator, this.ident, usernamePasswordURL, failNameVal, this.redirectTarget, this.failURL); } @@ -416,7 +418,7 @@ public void testExecute5() .anyTimes(); expect(data.getHttpRequest().getParameter(this.FORM_RESPONSE_IDENTIFIER)).andReturn(null).anyTimes(); expect(sessionsProcessor.getCreate()).andReturn(create).anyTimes(); - + try { create.createLocalSession(data.getSessionID(), "beddoes", AuthenticationContextConstants.passwordProtectedTransport, this.ident); @@ -425,7 +427,7 @@ public void testExecute5() { fail("Unable to create local session"); } - + setUpMock(data.getHttpRequest(), data.getHttpResponse()); setupHandler(); @@ -437,9 +439,9 @@ public void testExecute5() result = handler.execute(data); assertEquals("Asserts this handler returns correctly when authentication is completed as expected", Handler.result.Successful, result); - + assertTrue("Asserts the session identifier is set", data.getSessionID().matches(".*-.*")); - + tearDownMock(data.getHttpRequest(), data.getHttpResponse()); } catch (SessionCreationException sce) @@ -470,14 +472,14 @@ public void testExecute6() expect(sessionsProcessor.getCreate()).andReturn(create).anyTimes(); try { - create.createLocalSession((String)anyObject(), (String)anyObject(), (String)anyObject(), (List)anyObject()); + create.createLocalSession((String)anyObject(), (String)anyObject(), (String)anyObject(), (List)anyObject()); expectLastCall().andThrow(new SessionCacheUpdateException("Error adding session to cache dude")); } catch (SessionCacheUpdateException dse) { // we are expecting one of these, and expecting the handler to deal with it } - + setUpMock(data.getHttpRequest(), data.getHttpResponse()); setupHandler();