1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.test;
20
21 import com.gargoylesoftware.htmlunit.ElementNotFoundException;
22 import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
23 import com.gargoylesoftware.htmlunit.WebAssert;
24 import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
25 import com.gargoylesoftware.htmlunit.html.HtmlForm;
26 import com.gargoylesoftware.htmlunit.html.HtmlInput;
27 import com.gargoylesoftware.htmlunit.html.HtmlPage;
28 import org.junit.Before;
29 import org.junit.Ignore;
30 import org.junit.Test;
31
32 import java.io.IOException;
33 import java.net.MalformedURLException;
34
35 @Ignore
36 public class ContainerIntegrationTest extends AbstractContainerTest {
37
38 @Before
39 public void logOut() throws IOException {
40
41 final HtmlPage homePage = webClient.getPage(getBaseUri());
42 try {
43 homePage.getAnchorByHref("/logout").click();
44 }
45 catch (ElementNotFoundException e) {
46
47 }
48 }
49
50 @Test
51 public void logIn() throws FailingHttpStatusCodeException, MalformedURLException, IOException, InterruptedException {
52
53 HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
54 HtmlForm form = page.getFormByName("loginform");
55 form.<HtmlInput>getInputByName("username").setValueAttribute("root");
56 form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
57 page = form.<HtmlInput>getInputByName("submit").click();
58
59 page.getAnchorByHref("/logout");
60 }
61
62 @Test
63 public void logInAndRememberMe() throws Exception {
64 HtmlPage page = webClient.getPage(getBaseUri() + "login.jsp");
65 HtmlForm form = page.getFormByName("loginform");
66 form.<HtmlInput>getInputByName("username").setValueAttribute("root");
67 form.<HtmlInput>getInputByName("password").setValueAttribute("secret");
68 HtmlCheckBoxInput checkbox = form.getInputByName("rememberMe");
69 checkbox.setChecked(true);
70 page = form.<HtmlInput>getInputByName("submit").click();
71 server.stop();
72 server.start();
73 page = webClient.getPage(getBaseUri());
74
75 WebAssert.assertLinkPresentWithText(page, "Log out");
76 page = page.getAnchorByHref("/account").click();
77
78 WebAssert.assertFormPresent(page, "loginform");
79 }
80
81 }