<commit_before>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlContains;

import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class IntegrationTest {

  private WebDriver driver;
  private WebDriverWait wait;

  private final String USER_NICKNAME = "Mafe";
  private final String USER_EMAIL = "<EMAIL>";
  private final String USER_ADDRESS = "123 Street Name, City, ST";
  private final String USER_PHONE = "1231231234";

  @BeforeClass
  public static void setupClass() {
    WebDriverManager.chromedriver().setup();
  }

  @Before
  public void setupTest() {
    driver = new ChromeDriver();
    wait = new WebDriverWait(driver, 10);

    // Clears datastore entities for start of test
    driver.get("http://localhost:8080/_ah/admin");
    By entityKindSelect = By.id("kind_input");
    wait.until(presenceOfElementLocated(entityKindSelect));
    // Retrieves number of Entity Kind select options to iterate through them
    Select kindSelect = new Select(driver.findElement(entityKindSelect));
    List<WebElement> allEntityKinds = kindSelect.getOptions();
    By listButton;
    By allKeys;
    By deleteButton;
    for (int i = 0; i < allEntityKinds.size(); i++) {
      listButton = By.id("list_button");
      wait.until(presenceOfElementLocated(listButton));
      driver.findElement(listButton).click();
      allKeys = By.id("allkeys");
      wait.until(presenceOfElementLocated(allKeys));
      driver.findElement(allKeys).click();
      deleteButton = By.id("delete_button");
      wait.until(presenceOfElementLocated(deleteButton));
      driver.findElement(deleteButton).click();
      driver.switchTo().alert().accept();
    }
  }

  @After
  public void teardown() {
    if (driver != null) {
      driver.quit();
    }
  }

  @Test
  public void test() {
    driver.get("http://localhost:8080/");
    By loginMessage = By.id("loginLogoutMessage");
    wait.until(presenceOfElementLocated(loginMessage));
    WebElement loginElement = driver.findElement(loginMessage);
    String actualLoginText = loginElement.getText();

    // Guest user should expect to see login message
    assertEquals("Login to help out a neighbor!", actualLoginText);

    By addTaskButton = By.id("addtaskbutton");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> addTaskButtonElement = driver.findElements(addTaskButton);

    // Add task button should be missing when user is not logged in
    assertTrue(
        "Add task button must not be present for guest users", addTaskButtonElement.isEmpty());

    By dashboardIcon = By.className("dashboard-icon");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> dashboardIconsElement = driver.findElements(dashboardIcon);

    // Dashboard icon (userpage or admin page) buttons
    // should be missing when user is not logged in
    assertTrue(
        "Dashboard icons must not be present for guest users", dashboardIconsElement.isEmpty());

    By taskResultsMessage = By.id("no-tasks-message");
    wait.until(presenceOfElementLocated(taskResultsMessage));
    WebElement taskResultsMessageElement = driver.findElement(taskResultsMessage);

    // Message alerting user there are no tasks nearby should be displayed
    assertTrue("No tasks in neighborhood messaage", taskResultsMessageElement.isDisplayed());

    loginElement.click();
    By emailInput = By.id("email");
    wait.until(presenceOfElementLocated(emailInput));
    WebElement emailInputElement = driver.findElement(emailInput);

    emailInputElement.clear();
    emailInputElement.sendKeys(USER_EMAIL);
    By loginButton = By.id("btn-login");
    wait.until(presenceOfElementLocated(loginButton));
    WebElement loginButtonElement = driver.findElement(loginButton);
    loginButtonElement.click();
    wait.until(urlContains("/account.jsp"));

    // User should now be logged in and redirected to the
    // account page to enter their user info
    assertTrue(driver.getCurrentUrl().contains("/account.jsp"));
    assertEquals("My Personal Info", driver.getTitle());

    By nicknameInput = By.id("nickname-input");
    wait.until(presenceOfElementLocated(nicknameInput));
    WebElement nicknameInputElement = driver.findElement(nicknameInput);
    nicknameInputElement.sendKeys(USER_NICKNAME);

    By addressInput = By.id("address-input");
    wait.until(presenceOfElementLocated(addressInput));
    WebElement addressInputElement = driver.findElement(addressInput);
    addressInputElement.sendKeys(USER_ADDRESS);

    By phoneInput = By.id("phone-input");
    wait.until(presenceOfElementLocated(phoneInput));
    WebElement phoneInputElement = driver.findElement(phoneInput);
    phoneInputElement.sendKeys(USER_PHONE);

    By submitButton = By.id("submit-button");
    wait.until(presenceOfElementLocated(submitButton));
    WebElement submitButtonElement = driver.findElement(submitButton);
    submitButtonElement.click();

    // After new user fills out user info, they should be redirected to userpage
    assertTrue("User in user profile page", driver.getCurrentUrl().contains("/user_profile.jsp"));
    assertEquals("My Account", driver.getTitle());

    By userpageLogoutMessage = By.id("log-out-link");
    wait.until(presenceOfElementLocated(userpageLogoutMessage));
    String actualyUPLogoutM = driver.findElement(userpageLogoutMessage).getText();
    // Userpage should show a custom logout message with user's nickname
    assertEquals(USER_NICKNAME + " | Logout", actualyUPLogoutM);

    By backToHome = By.id("backtohome");
    wait.until(presenceOfElementLocated(backToHome));
    driver.findElement(backToHome).click();
    wait.until(urlContains("/index.jsp"));

    By logoutMessage = By.id("login-logout");
    wait.until(presenceOfElementLocated(logoutMessage));
    WebElement logoutElement = driver.findElement(logoutMessage);
    String actualLogoutText = logoutElement.getText();

    // Homepage should show a custom logout message with user's nickname
    assertEquals(USER_NICKNAME + " | Logout", actualLogoutText);
  }
}<commit_msg>add @MethodSorters.NAME_ASCENDING, change setupClass to @BeforeClass and teardown to @AfterClass<commit_after>// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import static org.openqa.selenium.support.ui.ExpectedConditions.urlContains;

import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class IntegrationTest {

  private static WebDriver driver;
  private static WebDriverWait wait;

  private final String USER_NICKNAME = "Mafe";
  private final String USER_EMAIL = "<EMAIL>";
  private final String USER_ADDRESS = "123 Street Name, City, ST";
  private final String USER_PHONE = "1231231234";

  private static void clearAllDatastoreEntities(WebDriver driver) {
    // Clears datastore entities for start of test
    driver.get("http://localhost:8080/_ah/admin");
    By entityKindSelect = By.id("kind_input");
    wait.until(presenceOfElementLocated(entityKindSelect));
    // Retrieves number of Entity Kind select options to iterate through them
    Select kindSelect = new Select(driver.findElement(entityKindSelect));
    List<WebElement> allEntityKinds = kindSelect.getOptions();
    By listButton;
    By allKeys;
    By deleteButton;
    for (int i = 0; i < allEntityKinds.size(); i++) {
      listButton = By.id("list_button");
      wait.until(presenceOfElementLocated(listButton));
      driver.findElement(listButton).click();
      allKeys = By.id("allkeys");
      wait.until(presenceOfElementLocated(allKeys));
      driver.findElement(allKeys).click();
      deleteButton = By.id("delete_button");
      wait.until(presenceOfElementLocated(deleteButton));
      driver.findElement(deleteButton).click();
      driver.switchTo().alert().accept();
    }
  }

  @BeforeClass
  public static void setupClass() {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    wait = new WebDriverWait(driver, 10);
    clearAllDatastoreEntities(driver);
  }

  @AfterClass
  public static void teardown() {
    if (driver != null) {
      driver.quit();
    }
  }

  @Test
  public void _01_Homepage_AsNewGuestUser_LoginAndInputUserInfo() {
    driver.get("http://localhost:8080/");
    By loginMessage = By.id("loginLogoutMessage");
    wait.until(presenceOfElementLocated(loginMessage));
    WebElement loginElement = driver.findElement(loginMessage);
    String actualLoginText = loginElement.getText();

    // Guest user should expect to see login message
    assertEquals("Login to help out a neighbor!", actualLoginText);

    By addTaskButton = By.id("addtaskbutton");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> addTaskButtonElement = driver.findElements(addTaskButton);

    // Add task button should be missing when user is not logged in
    assertTrue(
        "Add task button must not be present for guest users", addTaskButtonElement.isEmpty());

    By dashboardIcon = By.className("dashboard-icon");
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    List<WebElement> dashboardIconsElement = driver.findElements(dashboardIcon);

    // Dashboard icon (userpage or admin page) buttons
    // should be missing when user is not logged in
    assertTrue(
        "Dashboard icons must not be present for guest users", dashboardIconsElement.isEmpty());

    By taskResultsMessage = By.id("no-tasks-message");
    wait.until(presenceOfElementLocated(taskResultsMessage));
    WebElement taskResultsMessageElement = driver.findElement(taskResultsMessage);

    // Message alerting user there are no tasks nearby should be displayed
    assertTrue(
        "No tasks in neighborhood message should be displayed",
        taskResultsMessageElement.isDisplayed());

    loginElement.click();
    By emailInput = By.id("email");
    wait.until(presenceOfElementLocated(emailInput));
    WebElement emailInputElement = driver.findElement(emailInput);

    emailInputElement.clear();
    emailInputElement.sendKeys(USER_EMAIL);
    By loginButton = By.id("btn-login");
    wait.until(presenceOfElementLocated(loginButton));
    WebElement loginButtonElement = driver.findElement(loginButton);
    loginButtonElement.click();
    wait.until(urlContains("/account.jsp"));

    // User should now be logged in and redirected to the
    // account page to enter their user info
    assertTrue(driver.getCurrentUrl().contains("/account.jsp"));
    assertEquals("My Personal Info", driver.getTitle());

    By nicknameInput = By.id("nickname-input");
    wait.until(presenceOfElementLocated(nicknameInput));
    WebElement nicknameInputElement = driver.findElement(nicknameInput);
    nicknameInputElement.sendKeys(USER_NICKNAME);

    By addressInput = By.id("address-input");
    wait.until(presenceOfElementLocated(addressInput));
    WebElement addressInputElement = driver.findElement(addressInput);
    addressInputElement.sendKeys(USER_ADDRESS);

    By phoneInput = By.id("phone-input");
    wait.until(presenceOfElementLocated(phoneInput));
    WebElement phoneInputElement = driver.findElement(phoneInput);
    phoneInputElement.sendKeys(USER_PHONE);

    By submitButton = By.id("submit-button");
    wait.until(presenceOfElementLocated(submitButton));
    WebElement submitButtonElement = driver.findElement(submitButton);
    submitButtonElement.click();

    // After new user fills out user info, they should be redirected to userpage
    assertTrue("User in user profile page", driver.getCurrentUrl().contains("/user_profile.jsp"));
    assertEquals("My Account", driver.getTitle());

    By userpageLogoutMessage = By.id("log-out-link");
    wait.until(presenceOfElementLocated(userpageLogoutMessage));
    String actualyUPLogoutM = driver.findElement(userpageLogoutMessage).getText();
    // Userpage should show a custom logout message with user's nickname
    assertEquals(USER_NICKNAME + " | Logout", actualyUPLogoutM);

    By backToHome = By.id("backtohome");
    wait.until(presenceOfElementLocated(backToHome));
    driver.findElement(backToHome).click();
    wait.until(urlContains("/index.jsp"));

    By logoutMessage = By.id("login-logout");
    wait.until(presenceOfElementLocated(logoutMessage));
    WebElement logoutElement = driver.findElement(logoutMessage);
    String actualLogoutText = logoutElement.getText();

    // Homepage should show a custom logout message with user's nickname
    assertEquals(USER_NICKNAME + " | Logout", actualLogoutText);
  }

  @Test
  public void _02_Homepage_AsLoggedUser_AddTask() {
    driver.get("http://localhost:8080/");
    By logoutMessage = By.id("login-logout");
    wait.until(presenceOfElementLocated(logoutMessage));
    WebElement logoutElement = driver.findElement(logoutMessage);
    String actualLogoutText = logoutElement.getText();

    // Homepage should show a custom logout message with user's nickname
    assertEquals(USER_NICKNAME + " | Logout", actualLogoutText);
  }
}
{'fraction_non_alphanumeric': 0.10676897067429612, 'fraction_numerical': 0.004941803758371805, 'mean_word_length': 4.512544802867383, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4552900', 'n_tokens_mistral': 4396, 'n_tokens_neox': 4261, 'n_words': 1049}