From fa5f9ea1b2609c92af3e21110dd406d8f2ede582 Mon Sep 17 00:00:00 2001
From: Matthew Williams <mattwilliams1515@gmail.com>
Date: Sun, 29 Nov 2020 16:20:17 -0600
Subject: [PATCH] Add further selenium tests for deactivate, activate, and
 restructure tests

---
 .../itrust/selenium/ActivatePatientTest.java  | 66 +++++++++++++
 .../selenium/DeactivatePatientTest.java       | 92 +++++++++++++++++++
 .../ViewAllPreregisteredPatientsTest.java     | 43 +--------
 3 files changed, 159 insertions(+), 42 deletions(-)
 create mode 100644 iTrust/test/edu/ncsu/csc/itrust/selenium/ActivatePatientTest.java
 create mode 100644 iTrust/test/edu/ncsu/csc/itrust/selenium/DeactivatePatientTest.java

diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/ActivatePatientTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/ActivatePatientTest.java
new file mode 100644
index 0000000..56d6f21
--- /dev/null
+++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/ActivatePatientTest.java
@@ -0,0 +1,66 @@
+package edu.ncsu.csc.itrust.selenium;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.*;
+import org.openqa.selenium.*;
+import org.openqa.selenium.htmlunit.HtmlUnitDriver;
+
+public class ActivatePatientTest extends iTrustSeleniumTest {
+    private WebDriver driver;
+    private StringBuffer verificationErrors = new StringBuffer();
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        gen.standardData();
+        gen.patient92();
+        driver = new HtmlUnitDriver();
+        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testActivatePreregisteredPatient() throws Exception {
+        HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw");
+
+        // Make sure we were able to log in
+        assertEquals("iTrust - HCP Home", driver.getTitle());
+        driver.findElement(By.cssSelector("h2.panel-title")).click();
+        driver.findElement(By.linkText("View Pre-Registered Patients")).click();
+        String text = driver.findElement(By.cssSelector("table.fTable")).getText();
+
+        // Make sure the preregistered patients show up in the preregistered patients list
+        assertTrue("Text not found!", text.contains("Brittany Franco"));
+        assertTrue("Text not found!", text.contains("1333 Who Cares Road Suite 102"));
+        assertTrue("Text not found!", text.contains("Raleigh NC"));
+        assertTrue("Text not found!", text.contains("brfranco@gmail.com"));
+
+        // Ensure we can click on the patient and see more details
+        driver.findElement(By.linkText("Brittany Franco")).click();
+        text = driver.findElement(By.cssSelector("table.fTable")).getText();
+        assertTrue("Text not found!", text.contains("Phone:919-971-0000"));
+        assertTrue("Text not found!", text.contains("Email:brfranco@gmail.com"));
+        assertTrue("Text not found!", text.contains("Address: 1333 Who Cares Road"));
+
+        // Activate the preregistered patient
+        driver.findElement(By.linkText("Activate")).click();
+        text = driver.findElement(By.cssSelector("table.fTable")).getText();
+        assertTrue("Text not found!", text.contains("type \"I UNDERSTAND\" into the box below and click the button"));
+        driver.findElement(By.name("understand")).sendKeys("I UNDERSTAND");
+        driver.findElement(By.name("action")).click();
+
+        // Ensure the patient gets the fully activated screen
+        text = driver.findElement(By.cssSelector("span.iTrustMessage")).getText();
+        assertTrue("Text not found!", text.contains("Patient Successfully Activated!"));
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        driver.quit();
+        String verificationErrorString = verificationErrors.toString();
+        if (!"".equals(verificationErrorString)) {
+            fail(verificationErrorString);
+        }
+    }
+
+}
diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/DeactivatePatientTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/DeactivatePatientTest.java
new file mode 100644
index 0000000..9af33e3
--- /dev/null
+++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/DeactivatePatientTest.java
@@ -0,0 +1,92 @@
+package edu.ncsu.csc.itrust.selenium;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.*;
+import org.openqa.selenium.*;
+import org.openqa.selenium.htmlunit.HtmlUnitDriver;
+import com.gargoylesoftware.htmlunit.WebClient;
+
+public class DeactivatePatientTest extends iTrustSeleniumTest {
+    private WebDriver driver;
+    private StringBuffer verificationErrors = new StringBuffer();
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        gen.standardData();
+        gen.patient92();
+        driver = new HtmlUnitDriver();
+        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void testDeactivatePatients() throws Exception {
+        HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw");
+
+        // Make sure we were able to log in
+        assertEquals("iTrust - HCP Home", driver.getTitle());
+        driver.findElement(By.cssSelector("h2.panel-title")).click();
+        driver.findElement(By.linkText("View Pre-Registered Patients")).click();
+        driver.findElement(By.cssSelector("input.deactivate")).click();
+
+        // Deactivate the specified patient
+        driver.findElement(By.name("understand")).sendKeys("I UNDERSTAND");
+        driver.findElement(By.name("action")).click();
+
+        driver.findElement(By.cssSelector("h2.panel-title")).click();
+        driver.findElement(By.linkText("View Pre-Registered Patients")).click();
+        String text = driver.findElement(By.cssSelector("table.fTable")).getText();
+
+        // Ensure the deactivated patient is no longer in the preregistered patients list
+        assertFalse("Text found, but shouldn't be!", text.contains("Brittany Franco"));
+        assertFalse("Text found, but shouldn't be!", text.contains("1333 Who Cares Road Suite 102"));
+        assertFalse("Text found, but shouldn't be!", text.contains("Raleigh NC"));
+        assertFalse("Text found, but shouldn't be!", text.contains("brfranco@gmail.com"));
+    }
+
+    @Test
+    public void testLoginAfterPatientDeactivated() throws Exception {
+        HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw");
+
+        // Make sure we were able to log in
+        assertEquals("iTrust - HCP Home", driver.getTitle());
+        driver.findElement(By.cssSelector("h2.panel-title")).click();
+        driver.findElement(By.linkText("View Pre-Registered Patients")).click();
+        driver.findElement(By.cssSelector("input.deactivate")).click();
+
+        // Deactivate the specified patient
+        driver.findElement(By.name("understand")).sendKeys("I UNDERSTAND");
+        driver.findElement(By.name("action")).click();
+
+        driver.findElement(By.cssSelector("h2.panel-title")).click();
+        driver.findElement(By.linkText("View Pre-Registered Patients")).click();
+        String text = driver.findElement(By.cssSelector("table.fTable")).getText();
+
+        // Make sure deactivated patient doesn't show up in preregistered list
+        assertFalse("Text found, but shouldn't be!", text.contains("Brittany Franco"));
+        assertFalse("Text found, but shouldn't be!", text.contains("1333 Who Cares Road Suite 102"));
+        assertFalse("Text found, but shouldn't be!", text.contains("Raleigh NC"));
+        assertFalse("Text found, but shouldn't be!", text.contains("brfranco@gmail.com"));
+
+        // Test if the deactivated patient can log in
+        HtmlUnitDriver patientDriver = (HtmlUnitDriver)login("92", "pw");
+        assertEquals("Server Rebooted", patientDriver.getTitle());
+        text = patientDriver.findElement(By.xpath("//body")).getText();
+        assertTrue("Text not found!", text.contains("Authorization Error!"));
+        assertTrue("Text not found!", text.contains("You are not allowed to access this page"));
+        assertTrue("Text not found!", text.contains("Log back in."));
+
+
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        driver.quit();
+        String verificationErrorString = verificationErrors.toString();
+        if (!"".equals(verificationErrorString)) {
+            fail(verificationErrorString);
+        }
+    }
+
+}
diff --git a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewAllPreregisteredPatientsTest.java b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewAllPreregisteredPatientsTest.java
index a54823d..ca0eec6 100644
--- a/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewAllPreregisteredPatientsTest.java
+++ b/iTrust/test/edu/ncsu/csc/itrust/selenium/ViewAllPreregisteredPatientsTest.java
@@ -32,54 +32,13 @@ public class ViewAllPreregisteredPatientsTest extends iTrustSeleniumTest {
 		driver.findElement(By.linkText("View Pre-Registered Patients")).click();
 		String text = driver.findElement(By.cssSelector("table.fTable")).getText();
 
+		// Make sure the preregistered patients are shown in the list
 	    assertTrue("Text not found!", text.contains("Brittany Franco"));
 	    assertTrue("Text not found!", text.contains("1333 Who Cares Road Suite 102"));
 	    assertTrue("Text not found!", text.contains("Raleigh NC"));
 	    assertTrue("Text not found!", text.contains("brfranco@gmail.com"));
 	}
 
-	@Test
-	public void testDeactivatePatients() throws Exception {
-		HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw");
-
-		// Make sure we were able to log in
-		assertEquals("iTrust - HCP Home", driver.getTitle());
-		driver.findElement(By.cssSelector("h2.panel-title")).click();
-		driver.findElement(By.linkText("View Pre-Registered Patients")).click();
-		driver.findElement(By.cssSelector("input.deactivate")).click();
-	}
-
-	@Test
-	public void testActivatePreregisteredPatient() throws Exception {
-		HtmlUnitDriver driver = (HtmlUnitDriver)login("9000000000", "pw");
-
-		// Make sure we were able to log in
-		assertEquals("iTrust - HCP Home", driver.getTitle());
-		driver.findElement(By.cssSelector("h2.panel-title")).click();
-		driver.findElement(By.linkText("View Pre-Registered Patients")).click();
-		String text = driver.findElement(By.cssSelector("table.fTable")).getText();
-
-		assertTrue("Text not found!", text.contains("Brittany Franco"));
-		assertTrue("Text not found!", text.contains("1333 Who Cares Road Suite 102"));
-		assertTrue("Text not found!", text.contains("Raleigh NC"));
-		assertTrue("Text not found!", text.contains("brfranco@gmail.com"));
-
-		driver.findElement(By.linkText("Brittany Franco")).click();
-		text = driver.findElement(By.cssSelector("table.fTable")).getText();
-		assertTrue("Text not found!", text.contains("Phone:919-971-0000"));
-		assertTrue("Text not found!", text.contains("Email:brfranco@gmail.com"));
-		assertTrue("Text not found!", text.contains("Address: 1333 Who Cares Road"));
-
-		driver.findElement(By.linkText("Activate")).click();
-		text = driver.findElement(By.cssSelector("table.fTable")).getText();
-		assertTrue("Text not found!", text.contains("type \"I UNDERSTAND\" into the box below and click the button"));
-		driver.findElement(By.name("understand")).sendKeys("I UNDERSTAND");
-		driver.findElement(By.name("action")).click();
-
-		text = driver.findElement(By.cssSelector("span.iTrustMessage")).getText();
-		assertTrue("Text not found!", text.contains("Patient Successfully Activated!"));
-	}
-
 	@After
 	public void tearDown() throws Exception {
 		driver.quit();
-- 
GitLab