package test;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.junit.After;
import org.junit.Before;
import junit.framework.Assert;
import junit.framework.TestCase;

import org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.Select;

/**
 * Tests that the payment endpoint /submit-paypal-checkout is responding
   The Paypal payment processor POSTs to this address to complete a transaction
   While the test doesn't check for specific behaviors, it confirms our endpoint
   is handling requests, and that the Cocoon pipeline is not failing.
*/
public class PaypalReturnStepTest extends TestCase {
    private WebDriver driver;
    private String baseUrl = System.getProperty("selenium_test_url");

    @Before
  public void setUp() throws Exception {
    driver = new SilentHtmlUnitDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testPaymentEndpointResponds() throws Exception {
    driver.get(baseUrl + "/submit-paypal-checkout");
    assertTrue(isElementPresent(By.cssSelector("div.ds-static-div")));
    assertTrue("body contains 'error response from paypal", sectionContains("p.ds-paragraph", "error response from paypal"));

  }

  @After
  public void tearDown() throws Exception {
    driver.quit();
  }

    private boolean sectionContains(String section, String targetText) {
  return driver.findElement(By.cssSelector(section)).getText().contains(targetText);
    }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }
}

@@ -12,40 +12,8 @@
 t;%0A%0A
-import java.util.regex.Pattern;%0A
 impo
@@ -46,16 +46,16 @@
 meUnit;%0A
+
 %0Aimport 
@@ -123,39 +123,8 @@
 re;%0A
-import junit.framework.Assert;%0A
 impo
@@ -185,24 +185,24 @@
 Matchers.*;%0A
+
 import org.o
@@ -222,54 +222,8 @@
 m.*;
-%0Aimport org.openqa.selenium.support.ui.Select;
 %0A%0A/*

Remove unused imports