Commit 338ecdd3590ba64cc8ce324c946b875eb2348c1e

Authored by Nelson Torres Universidade U Minho
1 parent bfb88dc042
Exists in master

asserts are made via Laref-rest or solr query

TestNGResources/Lrharvester/testng-lrharvester.xml
... ... @@ -12,11 +12,13 @@
12 12 <class name="testng.lrharvester.TestAddNetworkLrharvester"/>
13 13 <class name="testng.lrharvester.TestAddOaiLrharvester"/>
14 14 -->
15   - <class name="testng.lrharvester.TestAddHarvestFullLrharvester"/>
  15 + <class name="testng.lrharvester.TestHarvestFullLrharvester"/>
  16 + <class name="testng.lrharvester.TestTransformValidateFullLrharvester"/>
16 17 <!--
17   - <class name="testng.lrharvester.TestAddTransformValidateFullLrharvester"/>
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>
... ...
driver/linux/geckodriver
No preview for this file type
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;
3 6 import org.openqa.selenium.By;
  7 +import org.openqa.selenium.support.ui.FluentWait;
  8 +import org.openqa.selenium.support.ui.Wait;
4 9 import org.testng.annotations.Test;
5 10 import testng.rcaap.TestBase;
6 11  
  12 +import java.io.IOException;
  13 +import java.io.InputStream;
  14 +import java.io.InputStreamReader;
  15 +import java.net.URL;
  16 +import java.net.URLConnection;
  17 +import java.util.concurrent.TimeUnit;
  18 +
7 19 import static org.testng.Assert.assertTrue;
8 20  
9 21 public class TestAddDescargadeODLrharvester extends TestBase {
  22 + String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
10 23  
11 24  
12 25  
... ... @@ -17,9 +30,41 @@ public class TestAddDescargadeODLrharvester extends TestBase {
17 30 acceptNextAlert = true;
18 31 driver.findElement(By.xpath("(//a[contains(text(),'Descarga de OD (full)')])[2]")).click();
19 32 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Descarga de OD \\(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(!isRunning());
  51 + //TODO check BD alteration
20 52 }
21 53  
22   -
23   -
  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 + }
24 69  
25 70 }
... ...
src/test/java/testng/lrharvester/TestAddHarvestFullLrharvester.java
... ... @@ -1,76 +0,0 @@
1   -package testng.lrharvester;
2   -
3   -import com.google.gson.JsonElement;
4   -import com.google.gson.JsonObject;
5   -import com.google.gson.JsonParser;
6   -import org.openqa.selenium.By;
7   -import org.openqa.selenium.support.ui.FluentWait;
8   -import org.openqa.selenium.support.ui.Wait;
9   -import org.testng.annotations.Test;
10   -import testng.rcaap.TestBase;
11   -
12   -import java.io.IOException;
13   -import java.io.InputStream;
14   -import java.io.InputStreamReader;
15   -import java.net.URL;
16   -import java.net.URLConnection;
17   -import java.util.concurrent.TimeUnit;
18   -
19   -import static org.testng.Assert.assertTrue;
20   -
21   -public class TestAddHarvestFullLrharvester extends TestBase {
22   -
23   -
24   -
25   - @Test
26   - public void testHarvestFull() throws Exception {
27   - driver.get("http://dev6.rcaap.pt/backend/home#");
28   - driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
29   - acceptNextAlert = true;
30   - driver.findElement(By.xpath("(//a[contains(text(),'Cosecha (full)')])[2]")).click();
31   - assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Cosecha \\(full\\) [\\s\\S]$"));
32   -
33   - TimeUnit.SECONDS.sleep(30);
34   -
35   - Wait wait = new FluentWait(driver)
36   - .withTimeout(3600, TimeUnit.SECONDS)
37   - .pollingEvery(30, TimeUnit.SECONDS)
38   - .ignoring(IOException.class);
39   -
40   - wait.until(o -> {
41   -
42   - try {
43   - return isRunning();
44   - } catch (IOException e) {
45   - e.printStackTrace();
46   -
47   - }
48   - return true;
49   - }
50   - );
51   -
52   - assertTrue(!isRunning());
53   -
54   - }
55   -
56   - private boolean isRunning() throws IOException {
57   -
58   - String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus"; //just a string
59   -
60   - // Connect to the URL using java's native library
61   - URL url = new URL(sURL);
62   - URLConnection request = url.openConnection();
63   - request.connect();
64   -
65   - // Convert to a JSON object to print data
66   - JsonParser jp = new JsonParser(); //from gson
67   - JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
68   - JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
69   - JsonObject running = rootobj.getAsJsonObject("running");
70   -
71   - System.out.println("json object: "+ running);
72   - return running.size() > 0;
73   - }
74   -
75   -
76   -}
src/test/java/testng/lrharvester/TestAddTransformValidateFullLrharvester.java
... ... @@ -1,21 +0,0 @@
1   -package testng.lrharvester;
2   -
3   -import org.openqa.selenium.By;
4   -import org.testng.annotations.Test;
5   -import testng.rcaap.TestBase;
6   -
7   -import static org.testng.Assert.assertTrue;
8   -
9   -public class TestAddTransformValidateFullLrharvester extends TestBase {
10   -
11   - @Test
12   - public void testTransformValidateFull() throws Exception {
13   - driver.get("http://dev6.rcaap.pt/backend/home#");
14   - driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
15   - acceptNextAlert = true;
16   - driver.findElement(By.xpath("(//a[contains(text(),'Validación/Transformación (full)')])[2]")).click();
17   - assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Validación/Transformación \\(full\\) [\\s\\S]$"));
18   - }
19   -
20   -
21   -}
src/test/java/testng/lrharvester/TestHarvestFullLrharvester.java
... ... @@ -0,0 +1,94 @@
  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 org.openqa.selenium.By;
  8 +import org.openqa.selenium.support.ui.FluentWait;
  9 +import org.openqa.selenium.support.ui.Wait;
  10 +import org.testng.annotations.Test;
  11 +import testng.rcaap.TestBase;
  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 +
  20 +import static org.testng.Assert.assertTrue;
  21 +
  22 +public class TestHarvestFullLrharvester extends TestBase {
  23 + String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  24 + URL url;
  25 + URLConnection request;
  26 +
  27 +
  28 + @Test
  29 + public void testHarvestFull() throws Exception {
  30 + driver.get("http://dev6.rcaap.pt/backend/home#");
  31 + driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
  32 + acceptNextAlert = true;
  33 + driver.findElement(By.xpath("(//a[contains(text(),'Cosecha (full)')])[2]")).click();
  34 + assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Cosecha \\(full\\) [\\s\\S]$"));
  35 +
  36 +
  37 + Wait wait = new FluentWait(driver)
  38 + .withTimeout(3600, TimeUnit.SECONDS)
  39 + .pollingEvery(20, TimeUnit.SECONDS)
  40 + .ignoring(IOException.class);
  41 + TimeUnit.SECONDS.sleep(10);
  42 +
  43 +
  44 + wait.until(o -> {
  45 + try {
  46 + return !isRunning();
  47 + } catch (IOException e) {
  48 + e.printStackTrace();
  49 + }
  50 + return false;
  51 + }
  52 + );
  53 +
  54 +
  55 + assertTrue(isHarvested());
  56 + }
  57 +
  58 + private boolean isRunning() throws IOException {
  59 +
  60 + url = new URL(sURL);
  61 + request = url.openConnection();
  62 + request.connect();
  63 +
  64 + // Convert to a JSON object to print data
  65 + JsonParser jp = new JsonParser(); //from gson
  66 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  67 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  68 + JsonObject running = rootobj.getAsJsonObject("running");
  69 +
  70 + return running.size() > 0;
  71 + }
  72 +
  73 + private boolean isHarvested() throws IOException {
  74 +
  75 +
  76 + url = new URL("http://dev6.rcaap.pt/backend/public/listSnapshotsByNetworkAcronym/teste");
  77 + request = url.openConnection();
  78 + request.connect();
  79 +
  80 + // Convert to a JSON object to print data
  81 + JsonParser jp = new JsonParser(); //from gson
  82 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  83 + JsonArray rootobj = root.getAsJsonArray(); //May be an array, may be an object.
  84 +
  85 + JsonObject snapshotInfo = rootobj.get(rootobj.size() - 1).getAsJsonObject();
  86 +
  87 + int size = snapshotInfo.get("size").getAsInt();
  88 + int validSize = snapshotInfo.get("validSize").getAsInt();
  89 +
  90 + return size > 0 && validSize == 0;
  91 + }
  92 +
  93 +
  94 +}
... ...
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;
3 6 import org.openqa.selenium.By;
  7 +import org.openqa.selenium.support.ui.FluentWait;
  8 +import org.openqa.selenium.support.ui.Wait;
4 9 import org.testng.annotations.Test;
5 10 import testng.rcaap.TestBase;
6 11  
  12 +import java.io.IOException;
  13 +import java.io.InputStream;
  14 +import java.io.InputStreamReader;
  15 +import java.net.URL;
  16 +import java.net.URLConnection;
  17 +import java.util.concurrent.TimeUnit;
  18 +
7 19 import static org.testng.Assert.assertTrue;
8 20  
9 21 public class TestIndexHistoricLrharvester extends TestBase {
  22 + String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
10 23  
11 24  
12 25 @Test
... ... @@ -16,11 +29,40 @@ public class TestIndexHistoricLrharvester extends TestBase {
16 29 acceptNextAlert = true;
17 30 driver.findElement(By.xpath("(//a[contains(text(),'Indexar histórico no Portal')])[2]")).click();
18 31 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Indexar histórico no Portal [\\s\\S]$"));
  32 + Wait wait = new FluentWait(driver)
  33 + .withTimeout(3600, TimeUnit.SECONDS)
  34 + .pollingEvery(20, TimeUnit.SECONDS)
  35 + .ignoring(IOException.class);
  36 + TimeUnit.SECONDS.sleep(10);
  37 +
  38 +
  39 + wait.until(o -> {
  40 + try {
  41 + return !isRunning();
  42 + } catch (IOException e) {
  43 + e.printStackTrace();
  44 + }
  45 + return false;
  46 + }
  47 + );
  48 +
  49 + assertTrue(!isRunning());
  50 + //TODO check BD alteration
19 51 }
20 52  
21   -
22   -
23   -
24   -
25   -
  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 + System.out.println("json object: "+ running);
  66 + return running.size() > 0;
  67 + }
26 68 }
... ...
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;
3 6 import org.openqa.selenium.By;
  7 +import org.openqa.selenium.support.ui.FluentWait;
  8 +import org.openqa.selenium.support.ui.Wait;
4 9 import org.testng.annotations.Test;
5 10 import testng.rcaap.TestBase;
6 11  
  12 +import java.io.IOException;
  13 +import java.io.InputStream;
  14 +import java.io.InputStreamReader;
  15 +import java.net.URL;
  16 +import java.net.URLConnection;
  17 +import java.util.concurrent.TimeUnit;
  18 +
7 19 import static org.testng.Assert.assertTrue;
8 20  
9 21 public class TestIndexVufindLrharvester extends TestBase {
  22 + String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
10 23  
11 24  
12 25 @Test
... ... @@ -16,8 +29,65 @@ public class TestIndexVufindLrharvester extends TestBase {
16 29 acceptNextAlert = true;
17 30 driver.findElement(By.xpath("(//a[contains(text(),'Indexación Vufind (full)')])[2]")).click();
18 31 assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Indexación Vufind \\(full\\) [\\s\\S]$"));
  32 + Wait wait = new FluentWait(driver)
  33 + .withTimeout(3600, TimeUnit.SECONDS)
  34 + .pollingEvery(20, TimeUnit.SECONDS)
  35 + .ignoring(IOException.class);
  36 + TimeUnit.SECONDS.sleep(10);
  37 +
  38 +
  39 + wait.until(o -> {
  40 + try {
  41 + return !isRunning();
  42 + } catch (IOException e) {
  43 + e.printStackTrace();
  44 + }
  45 + return false;
  46 + }
  47 + );
  48 +
  49 + assertTrue(isIndexed());
19 50 }
20 51  
  52 + private boolean isRunning() throws IOException {
  53 +
  54 + URL url = new URL(sURL);
  55 + URLConnection request = url.openConnection();
  56 + request.connect();
  57 +
  58 + // Convert to a JSON object to print data
  59 + JsonParser jp = new JsonParser(); //from gson
  60 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  61 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  62 + JsonObject running = rootobj.getAsJsonObject("running");
  63 +
  64 + return running.size() > 0;
  65 + }
21 66  
22   -
  67 + private boolean isIndexed() throws IOException {
  68 +
  69 + URL url = new URL("http://dev6.rcaap.pt/solr/coreTest/select?ident=on&q=network_acronym_str:teste&wt=json");
  70 + URLConnection request = url.openConnection();
  71 + request.connect();
  72 +
  73 + // Convert to a JSON object to print data
  74 + JsonParser jp = new JsonParser(); //from gson
  75 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  76 + JsonObject rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  77 +
  78 + JsonObject response= rootobj.get("response").getAsJsonObject();
  79 + int numFound = response.get("numFound").getAsInt();
  80 +
  81 + url = new URL("http://dev6.rcaap.pt/backend/public/lastGoodKnowSnapshotByNetworkID/4");
  82 + request = url.openConnection();
  83 + request.connect();
  84 + jp = new JsonParser(); //from gson
  85 + root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  86 + rootobj = root.getAsJsonObject(); //May be an array, may be an object.
  87 +
  88 + int validSize = rootobj.get("validSize").getAsInt();
  89 +
  90 +
  91 + return numFound == validSize ;
  92 + }
23 93 }
... ...
src/test/java/testng/lrharvester/TestTransformValidateFullLrharvester.java
... ... @@ -0,0 +1,91 @@
  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 org.openqa.selenium.By;
  8 +import org.openqa.selenium.support.ui.FluentWait;
  9 +import org.openqa.selenium.support.ui.Wait;
  10 +import org.testng.annotations.Test;
  11 +import testng.rcaap.TestBase;
  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 +
  20 +import static org.testng.Assert.assertTrue;
  21 +
  22 +public class TestTransformValidateFullLrharvester extends TestBase {
  23 + String sURL = "http://dev6.rcaap.pt/backend/public/getRunningStatus";
  24 +
  25 +
  26 +
  27 + @Test
  28 + public void testTransformValidateFull() throws Exception {
  29 + driver.get("http://dev6.rcaap.pt/backend/home#");
  30 + driver.findElement(By.xpath("(//button[@type='button'])[3]")).click();
  31 + acceptNextAlert = true;
  32 + driver.findElement(By.xpath("(//a[contains(text(),'Validación/Transformación (full)')])[2]")).click();
  33 + assertTrue(closeAlertAndGetItsText().matches("^¿Está seguro de ejecutar Validación/Transformación \\(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(isTransformed());
  52 + }
  53 +
  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 + return running.size() > 0;
  67 + }
  68 +
  69 + private boolean isTransformed() throws IOException {
  70 +
  71 +
  72 + URL url = new URL("http://dev6.rcaap.pt/backend/public/listSnapshotsByNetworkAcronym/teste");
  73 + URLConnection request = url.openConnection();
  74 + request.connect();
  75 +
  76 + // Convert to a JSON object to print data
  77 + JsonParser jp = new JsonParser(); //from gson
  78 + JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); //Convert the input stream to a json element
  79 + JsonArray rootobj = root.getAsJsonArray(); //May be an array, may be an object.
  80 +
  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 + System.out.println("size: "+size+" validSize: "+validSize);
  87 +
  88 + return size > 0 && validSize >= 0 && validSize <= size;
  89 + }
  90 +
  91 +}
... ...