01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
03: * Steven Grimm <koreth[remove] at midwinter dot com>
04: * Distributed under the terms of either:
05: * - the common development and distribution license (CDDL), v1.0; or
06: * - the GNU Lesser General Public License, v2.1 or later
07: * $Id: TestSessionValidatorRetriever.java 3669 2007-02-26 13:51:23Z gbevin $
08: */
09: package com.uwyn.rife.authentication.sessionvalidators;
10:
11: import com.meterware.httpunit.GetMethodWebRequest;
12: import com.meterware.httpunit.WebConversation;
13: import com.meterware.httpunit.WebRequest;
14: import com.meterware.httpunit.WebResponse;
15: import com.uwyn.rife.TestCaseServerside;
16: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.AuthenticatedElementNotFoundException;
17: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.NotAuthenticatedElementException;
18:
19: public class TestSessionValidatorRetriever extends TestCaseServerside {
20: public TestSessionValidatorRetriever(int siteType, String name) {
21: super (siteType, name);
22: }
23:
24: public void testValidAuthElement() throws Exception {
25: setupSite("site/authentication_memory_input.xml");
26:
27: WebConversation conversation = new WebConversation();
28: WebRequest request = null;
29: WebResponse response = null;
30:
31: request = new GetMethodWebRequest(
32: "http://localhost:8181/sessionvalidatorretriever/valid_auth_element");
33: response = conversation.getResponse(request);
34: assertEquals(
35: "com.uwyn.rife.authentication.sessionvalidators.BasicSessionValidator",
36: response.getText());
37: }
38:
39: public void testAuthElementNotFound() throws Exception {
40: setupSite("site/authentication_memory_input.xml");
41:
42: WebConversation conversation = new WebConversation();
43: WebRequest request = null;
44:
45: try {
46: request = new GetMethodWebRequest(
47: "http://localhost:8181/sessionvalidatorretriever/auth_element_not_found");
48: conversation.getResponse(request);
49: fail();
50: } catch (Throwable e) {
51: assertTrue(getLogSink().getInternalException() instanceof AuthenticatedElementNotFoundException);
52: assertEquals(
53: ".UNAVAILABLE_ELEMENT",
54: ((AuthenticatedElementNotFoundException) getLogSink()
55: .getInternalException()).getElementId());
56: }
57: }
58:
59: public void testElementNotAuthenticated() throws Exception {
60: setupSite("site/authentication_memory_input.xml");
61:
62: WebConversation conversation = new WebConversation();
63: WebRequest request = null;
64:
65: try {
66: request = new GetMethodWebRequest(
67: "http://localhost:8181/sessionvalidatorretriever/element_not_authenticated");
68: conversation.getResponse(request);
69: fail();
70: } catch (Throwable e) {
71: assertTrue(getLogSink().getInternalException() instanceof NotAuthenticatedElementException);
72: assertEquals(".INPUT.MEMORY_AUTHENTICATED_BASIC_TARGET",
73: ((NotAuthenticatedElementException) getLogSink()
74: .getInternalException()).getElementId());
75: }
76: }
77: }
|