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