Compare View

switch
from
...
to
 
Commits (2)
TestNGResources/Lrharvester/testng-lrharvester.xml
... ... @@ -11,12 +11,14 @@
11 11 <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
12 12 <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
13 13 <class name="testng.lrharvester.TestAddOaiLrharvester"/>
14   - -->
15   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
16   - <!--
17   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
  14 +
  15 + <class name="testng.lrharvester.TestHarvestFullLrharvester"/>
  16 + <class name="testng.lrharvester.TestTransformValidateFullLrharvester"/>
  17 +
18 18 <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
  19 +
19 20 <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
  21 +
20 22 <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
21 23 -->
22 24 </classes>
... ...
TestNGResources/Lrharvester/testng-portal-beanshell.xml
... ... @@ -1,85 +0,0 @@
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!-- Threading count to execute paralel tests and parallel set to tests (classes see documentation) -->
3   -<!-- I think if We have 2 classes they will run in parallel -->
4   -<suite name="LrHarvester" >
5   -
6   - <test name="LrharvesterChrome">
7   - <!-- These are defined in the maven and in the Test Files -->
8   - <!-- groups are overlaped -->
9   - <method-selectors>
10   - <method-selector>
11   - <script language="beanshell"><![CDATA[
12   - String grps = System.getProperty("browserToRun");
13   - return grps.contains("chrome") || grps.contains("all");
14   - ]]></script>
15   - </method-selector>
16   -</method-selectors>
17   - <parameter name="browser" value="chrome" />
18   - <classes>
19   - <class name="testng.lrharvester.TestLoginLrharvester"/>
20   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
21   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
22   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
23   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
24   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
25   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
26   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
27   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
28   - </classes>
29   - </test>
30   -
31   - <test name="LrharvesterFirefox">
32   - <!-- These are defined in the maven and in the Test Files -->
33   - <!-- groups are overlaped -->
34   - <method-selectors>
35   - <method-selector>
36   - <script language="beanshell"><![CDATA[
37   - String grps = System.getProperty("browserToRun");
38   - return grps.contains("firefox") || grps.contains("all");
39   - ]]></script>
40   - </method-selector>
41   -</method-selectors>
42   - <parameter name="browser" value="firefox" />
43   - <classes>
44   - <class name="testng.lrharvester.TestLoginLrharvester"/>
45   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
46   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
47   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
48   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
49   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
50   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
51   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
52   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
53   - </classes>
54   - </test>
55   -
56   - <test name="LrhatvesterHeadless">
57   - <!-- These are defined in the maven and in the Test Files -->
58   - <!-- groups are overlaped -->
59   - <method-selectors>
60   - <method-selector>
61   - <script language="beanshell"><![CDATA[
62   - String grps = System.getProperty("browserToRun");
63   - return grps.contains("headless") || grps.contains("all");
64   - ]]></script>
65   - </method-selector>
66   -</method-selectors>
67   - <parameter name="browser" value="headless" />
68   - <classes>
69   - <class name="testng.lrharvester.TestLoginLrharvester"/>
70   - <class name="testng.lrharvester.TestAddValidatorLrharvester"/>
71   - <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
72   - <class name="testng.lrharvester.TestAddOaiLrharvester"/>
73   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
74   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
75   - <class name="testng.lrharvester.TestAddDescargadeODLrharvester"/>
76   - <class name="testng.lrharvester.TestIndexVufindLrharvester"/>
77   - <class name="testng.lrharvester.TestIndexHistoricLrharvester"/>
78   - </classes>
79   - </test>
80   -
81   - <listeners>
82   - <listener class-name="org.uncommons.reportng.HTMLReporter"/>
83   - <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
84   - </listeners>
85   -</suite>
86 0 \ No newline at end of file
driver/linux/geckodriver
No preview for this file type
src/test/java/dataproviders/DataProviderLaReferencia.java
... ... @@ -0,0 +1,27 @@
  1 +package dataproviders;
  2 +
  3 +import org.testng.annotations.DataProvider;
  4 +
  5 +import java.util.Arrays;
  6 +import java.util.Iterator;
  7 +
  8 +/*
  9 + * Inject this values with Spring??????
  10 + */
  11 +
  12 +public class DataProviderLaReferencia {
  13 +
  14 + //Should be in the super class
  15 + //Added this to use multiple urls -> Called in test functions with @Test and the dataprovider
  16 + //We can have multiple data providers
  17 + @DataProvider(name = "development")
  18 + public static Iterator<Object[]> urls() {
  19 + String[] urls = {
  20 + "http://dev6.rcaap.pt/backend"
  21 + };
  22 + return Arrays.stream(urls)
  23 + .map(s -> new Object[]{s})
  24 + .iterator();
  25 + }
  26 +
  27 +}
... ...
src/test/java/testng/lrharvester/TestAddDescargadeODLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import com.google.gson.JsonElement;
  4 +import com.google.gson.JsonObject;
  5 +import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
3 7 import org.openqa.selenium.By;
  8 +import org.openqa.selenium.support.ui.FluentWait;
  9 +import org.openqa.selenium.support.ui.Wait;
4 10 import org.testng.annotations.Test;
5 11 import testng.rcaap.TestBase;
6 12  
  13 +import java.io.IOException;
  14 +import java.io.InputStream;
  15 +import java.io.InputStreamReader;
  16 +import java.net.URL;
  17 +import java.net.URLConnection;
  18 +import java.util.concurrent.TimeUnit;
  19 +
7 20 import static org.testng.Assert.assertTrue;
8 21  
9 22 public class TestAddDescargadeODLrharvester extends TestBase {
  23 + String sURL = baseUrl + "/public/getRunningStatus";
10 24  
11 25  
12 26  
13   - @Test
14   - public void testAddValidator() throws Exception {
15   - driver.get("http://dev6.rcaap.pt/backend/home#");
  27 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  28 + public void testAddValidator(String baseUrl) throws Exception {
  29 + driver.get(baseUrl);
16 30 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
17 31 acceptNextAlert = true;
18 32 driver.findElement(By.xpath("(//a[contains(text(),'Descarga de OD (full)')])[2]")).click();
19 33 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Descarga de OD \\(full\\) [\\s\\S]$"));
  34 + Wait wait = new FluentWait(driver)
  35 + .withTimeout(3600, TimeUnit.SECONDS)
  36 + .pollingEvery(20, TimeUnit.SECONDS)
  37 + .ignoring(IOException.class);
  38 + TimeUnit.SECONDS.sleep(10);
  39 +
  40 +
  41 + wait.until(o -> {
  42 + try {
  43 + return !isRunning();
  44 + } catch (IOException e) {
  45 + e.printStackTrace();
  46 + }
  47 + return false;
  48 + }
  49 + );
  50 +
  51 + assertTrue(!isRunning());
  52 + //TODO check BD alteration
20 53 }
21 54  
22   -
23   -
  55 + private boolean isRunning() throws IOException {
  56 +
  57 + URL url = new URL(sURL);
  58 + URLConnection request = url.openConnection();
  59 + request.connect();
  60 +
  61 + // Convert to a JSON object to print data
  62 + JsonParser jp = new JsonParser(); //from gson
  63 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  64 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  65 + JsonObject running = rootobj.getAsJsonObject("running");
  66 +
  67 + System.out.println("json object: "+ running);
  68 + return running.size() > 0;
  69 + }
24 70  
25 71 }
... ...
src/test/java/testng/lrharvester/TestAddNetworkLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4   -import org.openqa.selenium.WebDriver;
5   -import org.openqa.selenium.firefox.FirefoxDriver;
6 5 import org.openqa.selenium.support.ui.Select;
7   -import org.testng.annotations.BeforeClass;
8 6 import org.testng.annotations.Test;
9 7 import testng.rcaap.TestBase;
10 8  
11   -import java.util.concurrent.TimeUnit;
12   -
13 9 import static org.testng.Assert.assertEquals;
14 10  
15 11 public class TestAddNetworkLrharvester extends TestBase {
16 12  
17 13  
18   - @Test
19   - public void testAddNewNetwork() throws Exception {
20   - driver.get("http://dev6.rcaap.pt/backend/home#");
  14 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  15 + public void testAddNewNetwork(String baseUrl) throws Exception {
  16 + driver.get(baseUrl);
21 17 driver.findElement(By.linkText("Nuevo repositorio")).click();
22 18 driver.findElement(By.id("acronym")).click();
23 19 driver.findElement(By.id("acronym")).clear();
... ...
src/test/java/testng/lrharvester/TestAddOaiLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
  4 +import org.openqa.selenium.By;
  5 +import org.openqa.selenium.support.ui.Select;
3 6 import org.testng.annotations.Test;
4 7 import testng.rcaap.TestBase;
5 8  
6   -import static org.testng.Assert.assertTrue;
7   -
8 9 public class TestAddOaiLrharvester extends TestBase {
9 10  
10 11  
11   - @Test
12   - public void testAddOai() throws Exception {
13   - driver.get("http://dev6.rcaap.pt/backend/home#");
14   - assertTrue(false);
  12 +
  13 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  14 + public void testAddOai(String baseUrl) throws Exception {
  15 + driver.get(baseUrl);
  16 + driver.findElement(By.xpath("//button[2]")).click();
  17 + driver.findElement(By.linkText("Nuevo origen")).click();
  18 + driver.findElement(By.id("uri")).click();
  19 + driver.findElement(By.id("uri")).click();
  20 + driver.findElement(By.id("uri")).clear();
  21 + driver.findElement(By.id("uri")).sendKeys("http://arca.igc.gulbenkian.pt/oaiextended/request");
  22 + driver.findElement(By.name("metadataPrefix")).click();
  23 + new Select(driver.findElement(By.name("metadataPrefix"))).selectByVisibleText("xoai");
  24 + driver.findElement(By.xpath("//option[@value='string:xoai']")).click();
  25 + driver.findElement(By.xpath("//input[@value='Guardar']")).click();
  26 + driver.findElement(By.xpath("//div[2]/div/button")).click();
15 27 }
16 28  
17 29  
... ...
src/test/java/testng/lrharvester/TestAddValidatorLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4 5 import org.testng.annotations.Test;
5 6 import testng.rcaap.TestBase;
... ... @@ -7,10 +8,10 @@ import testng.rcaap.TestBase;
7 8 public class TestAddValidatorLrharvester extends TestBase {
8 9  
9 10  
10   - @Test
11   - public void testAddValidator() throws Exception {
  11 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  12 + public void testAddValidator(String baseUrl) throws Exception {
12 13  
13   - driver.get("http://dev6.rcaap.pt/backend/home#");
  14 + driver.get(baseUrl);
14 15 driver.findElement(By.linkText("Editar Validadores")).click();
15 16 driver.findElement(By.xpath("//a/span")).click();
16 17 driver.findElement(By.id("name")).click();
... ...
src/test/java/testng/lrharvester/TestHarvestFullLrharvester.java
... ... @@ -0,0 +1,90 @@
  1 +package testng.lrharvester;
  2 +
  3 +import com.google.gson.JsonArray;
  4 +import com.google.gson.JsonElement;
  5 +import com.google.gson.JsonObject;
  6 +import com.google.gson.JsonParser;
  7 +import dataproviders.DataProviderLaReferencia;
  8 +import org.openqa.selenium.By;
  9 +import org.openqa.selenium.support.ui.FluentWait;
  10 +import org.openqa.selenium.support.ui.Wait;
  11 +import org.testng.annotations.Test;
  12 +import testng.rcaap.TestBase;
  13 +
  14 +import java.io.IOException;
  15 +import java.io.InputStream;
  16 +import java.io.InputStreamReader;
  17 +import java.net.URL;
  18 +import java.net.URLConnection;
  19 +import java.util.concurrent.TimeUnit;
  20 +
  21 +import static org.testng.Assert.assertTrue;
  22 +
  23 +public class TestHarvestFullLrharvester extends TestBase {
  24 + String sURL = baseUrl + "/public/getRunningStatus";
  25 + URL url;
  26 + URLConnection request;
  27 +
  28 +
  29 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  30 + public void testHarvestFull(String baseUrl) throws Exception {
  31 + driver.get(baseUrl);
  32 + driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
  33 + acceptNextAlert = true;
  34 + driver.findElement(By.xpath("(//a[contains(text(),'Cosecha (full)')])[2]")).click();
  35 + assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Cosecha \\(full\\) [\\s\\S]$"));
  36 +
  37 +
  38 + Wait wait = new FluentWait(driver)
  39 + .withTimeout(3600, TimeUnit.SECONDS)
  40 + .pollingEvery(20, TimeUnit.SECONDS)
  41 + .ignoring(IOException.class);
  42 + TimeUnit.SECONDS.sleep(10);
  43 +
  44 +
  45 + wait.until(o -> {
  46 + try {
  47 + return !isRunning();
  48 + } catch (IOException e) {
  49 + e.printStackTrace();
  50 + }
  51 + return false;
  52 + }
  53 + );
  54 +
  55 +
  56 + assertTrue(isHarvested());
  57 + }
  58 +
  59 + private boolean isRunning() throws IOException {
  60 +
  61 + url = new URL(sURL);
  62 + request = url.openConnection();
  63 + request.connect();
  64 + JsonParser jp = new JsonParser();
  65 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  66 + JsonObject rootobj = root.getAsJsonObject();
  67 + JsonObject running = rootobj.getAsJsonObject("running");
  68 +
  69 + return running.size() > 0;
  70 + }
  71 +
  72 + private boolean isHarvested() throws IOException {
  73 +
  74 + url = new URL(baseUrl + "/public/listSnapshotsByNetworkAcronym/teste");
  75 + request = url.openConnection();
  76 + request.connect();
  77 +
  78 + JsonParser jp = new JsonParser();
  79 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  80 + JsonArray rootobj = root.getAsJsonArray();
  81 + JsonObject snapshotInfo = rootobj.get(rootobj.size() - 1).getAsJsonObject();
  82 +
  83 + int size = snapshotInfo.get("size").getAsInt();
  84 + int validSize = snapshotInfo.get("validSize").getAsInt();
  85 +
  86 + return size > 0 && validSize == 0;
  87 + }
  88 +
  89 +
  90 +}
... ...
src/test/java/testng/lrharvester/TestIndexHistoricLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import com.google.gson.JsonElement;
  4 +import com.google.gson.JsonObject;
  5 +import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
3 7 import org.openqa.selenium.By;
  8 +import org.openqa.selenium.support.ui.FluentWait;
  9 +import org.openqa.selenium.support.ui.Wait;
4 10 import org.testng.annotations.Test;
5 11 import testng.rcaap.TestBase;
6 12  
  13 +import java.io.IOException;
  14 +import java.io.InputStream;
  15 +import java.io.InputStreamReader;
  16 +import java.net.URL;
  17 +import java.net.URLConnection;
  18 +import java.util.concurrent.TimeUnit;
  19 +
7 20 import static org.testng.Assert.assertTrue;
8 21  
9 22 public class TestIndexHistoricLrharvester extends TestBase {
  23 + String sURL = baseUrl + "/public/getRunningStatus";
10 24  
11 25  
12   - @Test
13   - public void testIndexHistoric() throws Exception {
14   - driver.get("http://dev6.rcaap.pt/backend/home#");
  26 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  27 + public void testIndexHistoric(String baseUrl) throws Exception {
  28 + driver.get(baseUrl);
15 29 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
16 30 acceptNextAlert = true;
17 31 driver.findElement(By.xpath("(//a[contains(text(),'Indexar histórico no Portal')])[2]")).click();
18 32 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Indexar histórico no Portal [\\s\\S]$"));
  33 + Wait wait = new FluentWait(driver)
  34 + .withTimeout(3600, TimeUnit.SECONDS)
  35 + .pollingEvery(20, TimeUnit.SECONDS)
  36 + .ignoring(IOException.class);
  37 + TimeUnit.SECONDS.sleep(10);
  38 +
  39 +
  40 + wait.until(o -> {
  41 + try {
  42 + return !isRunning();
  43 + } catch (IOException e) {
  44 + e.printStackTrace();
  45 + }
  46 + return false;
  47 + }
  48 + );
  49 +
  50 + assertTrue(!isRunning());
  51 + //TODO check BD alteration
19 52 }
20 53  
21   -
22   -
23   -
24   -
25   -
  54 + private boolean isRunning() throws IOException {
  55 +
  56 + URL url = new URL(sURL);
  57 + URLConnection request = url.openConnection();
  58 + request.connect();
  59 +
  60 + // Convert to a JSON object to print data
  61 + JsonParser jp = new JsonParser(); //from gson
  62 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  63 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  64 + JsonObject running = rootobj.getAsJsonObject("running");
  65 +
  66 + System.out.println("json object: "+ running);
  67 + return running.size() > 0;
  68 + }
26 69 }
... ...
src/test/java/testng/lrharvester/TestIndexVufindLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import com.google.gson.JsonElement;
  4 +import com.google.gson.JsonObject;
  5 +import com.google.gson.JsonParser;
  6 +import dataproviders.DataProviderLaReferencia;
3 7 import org.openqa.selenium.By;
  8 +import org.openqa.selenium.support.ui.FluentWait;
  9 +import org.openqa.selenium.support.ui.Wait;
4 10 import org.testng.annotations.Test;
5 11 import testng.rcaap.TestBase;
6 12  
  13 +import java.io.IOException;
  14 +import java.io.InputStream;
  15 +import java.io.InputStreamReader;
  16 +import java.net.URL;
  17 +import java.net.URLConnection;
  18 +import java.util.concurrent.TimeUnit;
  19 +
7 20 import static org.testng.Assert.assertTrue;
8 21  
9 22 public class TestIndexVufindLrharvester extends TestBase {
  23 + String sURL = baseUrl + "/public/getRunningStatus";
10 24  
11 25  
12   - @Test
13   - public void testIndexVufindFull() throws Exception {
14   - driver.get("http://dev6.rcaap.pt/backend/home#");
  26 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  27 + public void testIndexVufindFull(String baseUrl) throws Exception {
  28 + driver.get(baseUrl);
15 29 driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
16 30 acceptNextAlert = true;
17 31 driver.findElement(By.xpath("(//a[contains(text(),'Indexación Vufind (full)')])[2]")).click();
18 32 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Indexación Vufind \\(full\\) [\\s\\S]$"));
  33 + Wait wait = new FluentWait(driver)
  34 + .withTimeout(3600, TimeUnit.SECONDS)
  35 + .pollingEvery(20, TimeUnit.SECONDS)
  36 + .ignoring(IOException.class);
  37 + TimeUnit.SECONDS.sleep(10);
  38 +
  39 +
  40 + wait.until(o -> {
  41 + try {
  42 + return !isRunning();
  43 + } catch (IOException e) {
  44 + e.printStackTrace();
  45 + }
  46 + return false;
  47 + }
  48 + );
  49 +
  50 + assertTrue(isIndexed());
19 51 }
20 52  
  53 + private boolean isRunning() throws IOException {
  54 +
  55 + URL url = new URL(sURL);
  56 + URLConnection request = url.openConnection();
  57 + request.connect();
  58 +
  59 + // Convert to a JSON object to print data
  60 + JsonParser jp = new JsonParser(); //from gson
  61 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  62 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  63 + JsonObject running = rootobj.getAsJsonObject("running");
  64 +
  65 + return running.size() > 0;
  66 + }
21 67  
22   -
  68 + private boolean isIndexed() throws IOException {
  69 +
  70 + URL url = new URL("http://dev6.rcaap.pt/solr/coreTest/select?ident=on&q=network_acronym_str:teste&wt=json");
  71 + URLConnection request = url.openConnection();
  72 + request.connect();
  73 +
  74 + // Convert to a JSON object to print data
  75 + JsonParser jp = new JsonParser(); //from gson
  76 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  77 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  78 +
  79 + JsonObject response= rootobj.get("response").getAsJsonObject();
  80 + int numFound = response.get("numFound").getAsInt();
  81 +
  82 + url = new URL("http://dev6.rcaap.pt/backend/private/networks?count=1&filter[teste]=CC&page=1");
  83 + request = url.openConnection();
  84 + request.connect();
  85 + jp = new JsonParser();
  86 + root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
  87 + rootobj = root.getAsJsonObject();
  88 + JsonObject network = rootobj.get("networks").getAsJsonObject();
  89 + String networkID = network.get("networkID").getAsString();
  90 +
  91 +
  92 + url = new URL("http://dev6.rcaap.pt/backend/public/lastGoodKnowSnapshotByNetworkID/"+ networkID);
  93 + request = url.openConnection();
  94 + request.connect();
  95 + jp = new JsonParser(); //from gson
  96 + root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  97 + rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  98 +
  99 + int validSize = rootobj.get("validSize").getAsInt();
  100 +
  101 +
  102 + return numFound == validSize ;
  103 + }
23 104 }
... ...
src/test/java/testng/lrharvester/TestLoginLrharvester.java
1 1 package testng.lrharvester;
2 2  
  3 +import dataproviders.DataProviderLaReferencia;
3 4 import org.openqa.selenium.By;
4 5 import org.testng.annotations.Test;
5 6 import testng.rcaap.TestBase;
6 7  
7 8 public class TestLoginLrharvester extends TestBase {
8 9  
9   - @Test
10   - public void testLogin() throws Exception {
11   - driver.get("http://dev6.rcaap.pt/backend");
  10 +
  11 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  12 + public void testLogin(String baseUrl) throws Exception {
  13 + driver.get(baseUrl);
12 14 driver.findElement(By.id("username")).click();
13 15 driver.findElement(By.id("username")).sendKeys("adminrcaap");
14 16 driver.findElement(By.id("password")).click();
... ...
src/test/java/testng/lrharvester/TestTransformValidateFullLrharvester.java
... ... @@ -0,0 +1,92 @@
  1 +package testng.lrharvester;
  2 +
  3 +import com.google.gson.JsonArray;
  4 +import com.google.gson.JsonElement;
  5 +import com.google.gson.JsonObject;
  6 +import com.google.gson.JsonParser;
  7 +import dataproviders.DataProviderLaReferencia;
  8 +import org.openqa.selenium.By;
  9 +import org.openqa.selenium.support.ui.FluentWait;
  10 +import org.openqa.selenium.support.ui.Wait;
  11 +import org.testng.annotations.Test;
  12 +import testng.rcaap.TestBase;
  13 +
  14 +import java.io.IOException;
  15 +import java.io.InputStream;
  16 +import java.io.InputStreamReader;
  17 +import java.net.URL;
  18 +import java.net.URLConnection;
  19 +import java.util.concurrent.TimeUnit;
  20 +
  21 +import static org.testng.Assert.assertTrue;
  22 +
  23 +public class TestTransformValidateFullLrharvester extends TestBase {
  24 + String sURL = baseUrl + "/public/getRunningStatus";
  25 +
  26 +
  27 +
  28 + @Test( dataProvider = "development", dataProviderClass = DataProviderLaReferencia.class)
  29 + public void testTransformValidateFull(String baseUrl) throws Exception {
  30 + driver.get(baseUrl);
  31 + driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
  32 + acceptNextAlert = true;
  33 + driver.findElement(By.xpath("(//a[contains(text(),'Validación/Transformación (full)')])[2]")).click();
  34 + assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Validación/Transformación \\(full\\) [\\s\\S]$"));
  35 + Wait wait = new FluentWait(driver)
  36 + .withTimeout(3600, TimeUnit.SECONDS)
  37 + .pollingEvery(20, TimeUnit.SECONDS)
  38 + .ignoring(IOException.class);
  39 + TimeUnit.SECONDS.sleep(10);
  40 +
  41 +
  42 + wait.until(o -> {
  43 + try {
  44 + return !isRunning();
  45 + } catch (IOException e) {
  46 + e.printStackTrace();
  47 + }
  48 + return false;
  49 + }
  50 + );
  51 +
  52 + assertTrue(isTransformed());
  53 + }
  54 +
  55 + private boolean isRunning() throws IOException {
  56 +
  57 + URL url = new URL(sURL);
  58 + URLConnection request = url.openConnection();
  59 + request.connect();
  60 +
  61 + // Convert to a JSON object to print data
  62 + JsonParser jp = new JsonParser(); //from gson
  63 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  64 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  65 + JsonObject running = rootobj.getAsJsonObject("running");
  66 +
  67 + return running.size() > 0;
  68 + }
  69 +
  70 + private boolean isTransformed() throws IOException {
  71 +
  72 +
  73 + URL url = new URL(baseUrl + "/public/listSnapshotsByNetworkAcronym/teste");
  74 + URLConnection request = url.openConnection();
  75 + request.connect();
  76 +
  77 + // Convert to a JSON object to print data
  78 + JsonParser jp = new JsonParser(); //from gson
  79 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  80 + JsonArray rootobj = root.getAsJsonArray(); //May be an array, may be an object.
  81 +
  82 + JsonObject snapshotInfo = rootobj.get(rootobj.size() - 1).getAsJsonObject();
  83 +
  84 + int size = snapshotInfo.get("size").getAsInt();
  85 + int validSize = snapshotInfo.get("validSize").getAsInt();
  86 +
  87 + System.out.println("size: "+size+" validSize: "+validSize);
  88 +
  89 + return size > 0 && validSize >= 0 && validSize <= size;
  90 + }
  91 +
  92 +}
... ...