/
SelectiveHarvestTest.java
225 lines (205 loc) · 11.6 KB
/
SelectiveHarvestTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* #%L
* NetarchiveSuite System test
* %%
* Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
* the National Library of France and the Austrian National Library.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package dk.netarkivet.systemtest.functional;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.RandomStringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import dk.netarkivet.systemtest.AbstractSystemTest;
import dk.netarkivet.systemtest.HarvestUtils;
import dk.netarkivet.systemtest.NASAssert;
import dk.netarkivet.systemtest.SeleniumTest;
import dk.netarkivet.systemtest.page.DomainConfigurationPageHelper;
import dk.netarkivet.systemtest.page.DomainWebTestHelper;
import dk.netarkivet.systemtest.page.PageHelper;
import dk.netarkivet.systemtest.page.SelectiveHarvestPageHelper;
/**
* Test specification: http://netarchive.dk/suite/TEST1 .
*/
public class SelectiveHarvestTest extends AbstractSystemTest {
private String harvestIDForTest;
private int harvestCounter = 0;
private DateFormat dateFomatter = new SimpleDateFormat("HHmmss");
@BeforeMethod(alwaysRun = true)
public void setup(Method method) {
Date startTime = new Date();
harvestIDForTest = getClass().getSimpleName() + "-" + method.getName() + "-" + dateFomatter.format(startTime);
harvestCounter = 1;
}
/**
* Test specification: http://netarchive.dk/suite/It23JMXMailCheck .
*/
@Test(groups = {"guitest", "functest"})
public void selectiveHarvestListingTest() throws Exception {
addDescription("Verify the functionality of the harvest listings.");
addReference("http://netarchive.dk/suite/TEST1");
addStep("Create a selective harvest", "The harvest should be created successfully a be listed in the HD list");
String harvest1ID = createHarverstID();
SelectiveHarvestPageHelper.createSelectiveHarvest(harvest1ID);
assertTrue(driver.getPageSource().contains(harvest1ID), harvest1ID
+ " not found in harvest list after creation");
addStep("Create a second harvest and active it", "The second harvest also be listed in the HD list");
String harvest2ID = createHarverstID();
SelectiveHarvestPageHelper.createSelectiveHarvest(harvest2ID);
SelectiveHarvestPageHelper.activateHarvest(harvest2ID);
assertTrue(driver.getPageSource().contains(harvest2ID), harvest2ID
+ " not found in harvest list after creation");
addStep("Hide inactive harvests", "The harvest first harvest should disappear from the HD list, "
+ "the second should remain");
driver.findElement(By.linkText("Hide inactive harvest definitions")).click();
NASAssert.assertFalse(driver.getPageSource().contains(harvest1ID), "Inactive harvest " + harvest1ID
+ " show in harvest list after 'hide inactive harvests' was clicked");
assertTrue(driver.getPageSource().contains(harvest2ID), harvest2ID
+ " not found in harvest list after creation");
addStep("Show inactive harvests", "The harvest first harvest should reappear from the HD list, "
+ "the second should remain");
driver.findElement(By.linkText("Show inactive harvest definitions")).click();
assertTrue(driver.getPageSource().contains(harvest1ID), "Inactive harvest " + harvest1ID
+ " show in harvest list after 'hide inactive harvests' was clicked");
assertTrue(driver.getPageSource().contains(harvest2ID), harvest2ID
+ " not found in harvest list after creation");
}
private String createHarverstID() {
return harvestIDForTest + "-" + harvestCounter++;
}
/**
* Test creates 8 distinct harvest configurations corresponding to two different values for each of 3
* parameters defined in the EAV model (2³=8). In addition, there are created 3 configurations using the
* same cxml and attribute values as 3 of the previous 8 jobs. So there should be
* eight jobs created.
*/
@Test(groups = {"guitest", "functest"})
public void jobSplittingTest() {
final String domainRandomString = RandomStringUtils.random(6, true, true);
final String configRandomString = RandomStringUtils.random(6, true, true);
final String configName = "newconf_" + configRandomString;
List<String> domainList = new ArrayList<String>();
for (int i=0; i<=10; i++ ) {
domainList.add("d"+i+"-"+domainRandomString+".dk");
}
createDomainAndConfiguration(domainList.get(0), configName, 10, false, false);
createDomainAndConfiguration(domainList.get(1), configName, 10, false, true);
createDomainAndConfiguration(domainList.get(2), configName, 10, true, false);
createDomainAndConfiguration(domainList.get(3), configName, 10, true, true);
createDomainAndConfiguration(domainList.get(4), configName, 20, false, false);
createDomainAndConfiguration(domainList.get(5), configName, 20, false, true);
createDomainAndConfiguration(domainList.get(6), configName, 20, true, false);
createDomainAndConfiguration(domainList.get(7), configName, 20, true, true);
//The next three configs are identical to three of the above so they should
//not generate new jobs - so only 8 jobs expected.
createDomainAndConfiguration(domainList.get(8), configName, 20, true, true);
createDomainAndConfiguration(domainList.get(9), configName, 20, true, false);
createDomainAndConfiguration(domainList.get(10), configName, 20, false, true);
final String harvestName = "splitharvest_" + RandomStringUtils.random(6, true, true);
SelectiveHarvestPageHelper.createSelectiveHarvest(harvestName, "",
(String[]) domainList.toArray(new String[] {}));
SelectiveHarvestPageHelper.editHarvest(harvestName);
WebElement table = PageHelper.getWebDriver().findElement(By.className("selection_table"));
List<WebElement> selects = table.findElements(By.tagName("select"));
for (WebElement select: selects) {
Select dropdown = new Select(select);
dropdown.selectByVisibleText(configName);
}
PageHelper.getWebDriver().findElement(By.name("save")).click();
SelectiveHarvestPageHelper.activateHarvest(harvestName);
HarvestUtils.waitForJobGeneration(harvestName);
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
}
List<WebElement> links = PageHelper.getWebDriver().findElements(By.partialLinkText(harvestName));
assertEquals(links.size(), 8, "Expected to generate one job per distinct configuration for " + harvestName + ".");
}
/**
* In this test we first set the cfg for every known domain to be identical. Then we make changes in
* a number of them and check that the right number of jobs is generated.
*/
@Test(groups = {"guitest", "functest"})
public void snapshotTest() {
List<String> editDomainLinks = DomainWebTestHelper.getAllEditDomainLinks();
for (String link: editDomainLinks) {
driver.get(link);
WebElement editAnchor = driver.findElement(By.id("configuration")).findElement(By.linkText("Edit"));
driver.get(editAnchor.getAttribute("href"));
Select order_xml = new Select(driver.findElement(By.name("order_xml")));
order_xml.selectByVisibleText("default_orderxml");
driver.findElement(By.name("maxObjects")).clear();
driver.findElement(By.name("maxObjects")).sendKeys("10");
driver.findElement(By.name("maxBytes")).clear();
driver.findElement(By.name("maxBytes")).sendKeys("100000");
DomainConfigurationPageHelper.setMaxHops(10);
DomainConfigurationPageHelper.setHonorRobots(true);
DomainConfigurationPageHelper.setExtractJavascript(true);
DomainConfigurationPageHelper.submitChanges();
}
driver.get(editDomainLinks.get(0));
WebElement editAnchor = driver.findElement(By.id("configuration")).findElement(By.linkText("Edit"));
driver.get(editAnchor.getAttribute("href"));
DomainConfigurationPageHelper.setMaxHops(20);
DomainConfigurationPageHelper.submitChanges();
driver.get(editDomainLinks.get(1));
editAnchor = driver.findElement(By.id("configuration")).findElement(By.linkText("Edit"));
driver.get(editAnchor.getAttribute("href"));
DomainConfigurationPageHelper.setHonorRobots(false);
DomainConfigurationPageHelper.submitChanges();
driver.get(editDomainLinks.get(2));
editAnchor = driver.findElement(By.id("configuration")).findElement(By.linkText("Edit"));
driver.get(editAnchor.getAttribute("href"));
DomainConfigurationPageHelper.setExtractJavascript(false);
DomainConfigurationPageHelper.submitChanges();
//So now a snapshot harvest should create four jobs
PageHelper.gotoPage(PageHelper.MenuPages.SnapshotHarvests);
final String harvestName = "snapshot_" + RandomStringUtils.random(3, true, true);
driver.findElement(By.partialLinkText("Create new snapshot harvest definition")).click();
driver.findElement(By.name("harvestname")).sendKeys(harvestName);
driver.findElement(By.name("snapshot_byte_limit")).clear();
driver.findElement(By.name("snapshot_byte_limit")).sendKeys("1000000");
driver.findElement(By.name("snapshot_byte_limit")).submit();
driver.findElement(By.cssSelector("input[value=\""+harvestName+"\"]")).submit();
HarvestUtils.waitForJobGeneration(harvestName);
List<WebElement> links = PageHelper.getWebDriver().findElements(By.partialLinkText(harvestName));
assertEquals(links.size(), 4, "Expected to generate one job per distinct configuration.");
}
private static void createDomainAndConfiguration(String domainName, String configurationName, int maxHops,
boolean obeyRobots, boolean extractJavascript) {
DomainWebTestHelper.createDomain(new String[] {domainName});
DomainConfigurationPageHelper.createConfiguration(domainName, configurationName);
DomainConfigurationPageHelper.gotoConfigurationPage(domainName, configurationName);
DomainConfigurationPageHelper.setMaxHops(maxHops);
DomainConfigurationPageHelper.setHonorRobots(obeyRobots);
DomainConfigurationPageHelper.setExtractJavascript(extractJavascript);
DomainConfigurationPageHelper.submitChanges();
}
}