View Javadoc

1   /**
2    * Copyright (c) 2002-2015, JWebUnit team.
3    *
4    * This file is part of JWebUnit.
5    *
6    * JWebUnit is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * JWebUnit is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with JWebUnit.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package net.sourceforge.jwebunit.tests;
20  
21  import static net.sourceforge.jwebunit.junit.JWebUnit.assertTitleEquals;
22  import static net.sourceforge.jwebunit.junit.JWebUnit.beginAt;
23  import static net.sourceforge.jwebunit.junit.JWebUnit.clickLinkWithText;
24  import static net.sourceforge.jwebunit.junit.JWebUnit.getTestContext;
25  import static net.sourceforge.jwebunit.junit.JWebUnit.setBaseUrl;
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.fail;
28  
29  import com.google.code.tempusfugit.concurrency.annotations.Repeating;
30  
31  import com.google.code.tempusfugit.concurrency.annotations.Concurrent;
32  
33  import com.google.code.tempusfugit.concurrency.ConcurrentRule;
34  
35  import com.google.code.tempusfugit.concurrency.RepeatingRule;
36  
37  import org.junit.Rule;
38  import org.junit.Test;
39  import org.junit.rules.Timeout;
40  
41  
42  /**
43   * Test parallel execution of JWebUnit.
44   * 
45   * @author Julien Henry
46   */
47  public class ConcurrentJWebUnitTest extends JWebUnitAPITestCase {
48  
49      public void setUp() throws Exception {
50      	//don't call super.setUp to avoid temporary state where baseUrl = HOST_PATH
51      	getTestContext().setAuthorization("admin", "admin");
52      	setBaseUrl(HOST_PATH + "/NavigationTest");
53      }
54  
55      @Rule public Timeout timeoutRule = new Timeout(10000);
56  
57      @Rule public ConcurrentRule concurrently = new ConcurrentRule();
58      @Rule public RepeatingRule repeatedly = new RepeatingRule();
59  
60      @Test
61      @Concurrent(count = 5)
62      @Repeating (repetition = 10)
63      public void testClickLinkWithTextN() {
64          beginAt("/pageWithLink.html");
65          assertTitleEquals("pageWithLink");
66  
67          clickLinkWithText("an active link", 0);
68          assertTitleEquals("targetPage");
69  
70          beginAt("/pageWithLink.html");
71          clickLinkWithText("an active link", 1);
72  
73          assertTitleEquals("targetPage2");
74          beginAt("/pageWithLink.html");
75          try {
76              clickLinkWithText("an active link", 2);
77              fail();
78          } catch (AssertionError expected) {
79              assertEquals("Link with text [an active link] and index [2] "
80                      + "not found in response.", expected.getMessage());
81          }
82          assertTitleEquals("pageWithLink");
83      }
84  
85  }