Skip to content

Commit

Permalink
Reformatting, some cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
burythehammer committed Aug 1, 2018
1 parent 5d0402d commit 696b500
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 86 deletions.
4 changes: 2 additions & 2 deletions acceptance-tests-common/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-automation-quickstart</artifactId>
Expand Down
Expand Up @@ -23,10 +23,9 @@ public class EmailAdaptor {
private static final String TEST_EMAIL_SUBJECT = "OpenCredo Test Email";

private final Session session;
private Store store;

private final String emailAddress;
private final String password;
private Store store;

public EmailAdaptor(String emailAddress, String password) {

Expand Down
@@ -1,13 +1,13 @@
package com.opencredo.test;

import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.remote.CapabilityType;

/**
* Creates a browser session which can be used to interact with a web UI.
Expand Down
@@ -1,13 +1,11 @@
package com.opencredo.test.utils;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;
import java.util.Random;

public class RandomUtils {
protected static Random random = new Random(System.currentTimeMillis());
public static String alphaCharacters = "abcdefghijklmnopqrstuvwxyz";
public static String numericCharacters = "0123456789";
protected static Random random = new Random(System.currentTimeMillis());

public static synchronized int randomInt(final int min, final int max) {
return random.nextInt((max - min) + 1) + min;
Expand Down
7 changes: 4 additions & 3 deletions api-acceptance-tests/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-automation-quickstart</artifactId>
Expand Down Expand Up @@ -29,7 +29,8 @@
<glue>com.opencredo.test.api.acceptance.test.step.definitions</glue>
<!-- These are the default values -->
<!-- Where to output the generated Junit tests -->
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber
</outputDirectory>
<!-- The diectory containing your feature files. -->
<featuresDirectory>src/test/resources/cucumber/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
Expand Down
Expand Up @@ -2,7 +2,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

public class ApiTestProperties {

Expand Down
Expand Up @@ -8,12 +8,12 @@ public class TestWorld {
public static final String USER_PASSWORD = "Testing123!";

public HashMap<String, String> sharedState = new HashMap<>();
public String currentUserAlias;
private HashMap<String, User> users = new HashMap<>();

public void addUser(String userAlias, User user) {
users.put(userAlias, user);
}
public String currentUserAlias;

public User getUserByAlias(String userAlias) {
return users.get(userAlias);
Expand Down
@@ -1,8 +1,8 @@
package com.opencredo.test.api.acceptance.test.config.spring;

import com.opencredo.test.EmailAdaptor;
import com.opencredo.test.api.acceptance.test.config.TestWorld;
import com.opencredo.test.api.acceptance.test.config.ApiTestProperties;
import com.opencredo.test.api.acceptance.test.config.TestWorld;
import com.opencredo.test.api.acceptance.test.interaction.api.objects.GithubApi;
import com.opencredo.test.api.acceptance.test.interaction.api.objects.GithubStatusApi;
import com.opencredo.test.api.acceptance.test.interaction.api.objects.MessagingApi;
Expand Down Expand Up @@ -38,7 +38,9 @@ public GithubStatusApi githubStatus() {
}

@Bean
public MessagingApi messagingApi() { return new MessagingApi(properties().getMessagingApiUrl());}
public MessagingApi messagingApi() {
return new MessagingApi(properties().getMessagingApiUrl());
}

@Bean
public HttpClient httpClient() {
Expand Down
Expand Up @@ -5,14 +5,14 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.client.RestTemplate;

@ContextConfiguration(classes= ApiTestConfig.class)
@ContextConfiguration(classes = ApiTestConfig.class)
public abstract class AbstractApiObject {
protected String baseUrl;

@Autowired
RestTemplate restTemplate;

public AbstractApiObject (String baseUrl) {
public AbstractApiObject(String baseUrl) {
this.baseUrl = baseUrl;
}
}
Expand Up @@ -5,7 +5,7 @@ public class Message {
public String recipientUserName;
public String message;

public Message (String senderUserName, String recipientUserName, String message) {
public Message(String senderUserName, String recipientUserName, String message) {
this.senderUserName = senderUserName;
this.recipientUserName = recipientUserName;
this.message = message;
Expand Down
@@ -1,7 +1,6 @@
package com.opencredo.test.api.acceptance.test.step.definitions;

import com.opencredo.test.api.acceptance.test.interaction.api.objects.MessagingApi;
import com.opencredo.test.api.acceptance.test.interaction.dto.Message;
import com.opencredo.test.api.acceptance.test.interaction.dto.User;
import com.opencredo.test.utils.RandomUtils;
import cucumber.api.Scenario;
Expand Down
Expand Up @@ -3,8 +3,8 @@ Feature: Demonstrate use of aliases to keep tests readable with complex data

Scenario: Send a message between two users
Given the following users:
| Bob |
| Dave |
| Bob |
| Dave |
When I log in as "Bob"
And I send a message to "Dave"
Then "Dave" should have received a message from "Bob"
Expand Up @@ -3,6 +3,5 @@
api.acceptance.test.github.status.api=https://status.github.com/api
api.acceptance.test.github.api=https://api.github.com
api.acceptance.test.messaging.api=https://localhost

api.acceptance.test.email.address=CHANGE_ME
api.acceptance.test.email.password=CHANGE)ME
api.acceptance.test.email.password=CHANGE_ME
5 changes: 2 additions & 3 deletions performance-tests/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-automation-quickstart</artifactId>
Expand Down Expand Up @@ -150,5 +150,4 @@
</build>



</project>
7 changes: 4 additions & 3 deletions security-acceptance-tests/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-automation-quickstart</artifactId>
Expand Down Expand Up @@ -29,7 +29,8 @@
<glue>com.opencredo.test.security.acceptance.test.step.definitions</glue>
<!-- These are the default values -->
<!-- Where to output the generated Junit tests -->
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber
</outputDirectory>
<!-- The diectory containing your feature files. -->
<featuresDirectory>src/test/resources/cucumber/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
Expand Down
Expand Up @@ -2,7 +2,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
* Used to retrieve properties and make them available to tests
Expand Down
Expand Up @@ -3,8 +3,8 @@
import com.opencredo.test.SharedDriver;
import com.opencredo.test.security.acceptance.test.config.SecurityTestProperties;
import com.opencredo.test.security.acceptance.test.config.TestWorld;
import com.opencredo.test.security.acceptance.test.interaction.objects.GoogleSearchPageObject;
import com.opencredo.test.security.acceptance.test.config.ZapProxy;
import com.opencredo.test.security.acceptance.test.interaction.objects.GoogleSearchPageObject;
import org.openqa.selenium.Proxy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Expand Up @@ -8,9 +8,9 @@
* Reusable methods for all page objects
*/
public abstract class AbstractPageObject {
private String path;
private final WebDriver driver;
private final int waitTimeOutSeconds;
private String path;

public AbstractPageObject(String path, WebDriver driver, int waitTimeOutSeconds) {
this.path = path;
Expand All @@ -32,18 +32,18 @@ public void goToAndWait() {
}

public void ensure_is_current() {
wait_until_true_or_timeout(WaitConditions.urlContains(path));
waitUntilTrueOrTimeout(WaitConditions.urlContains(path));
}

public boolean is_text_present(String text) {
wait_until_true_or_timeout(WaitConditions.pageContainsText(text));
waitUntilTrueOrTimeout(WaitConditions.pageContainsText(text));
return true;
}

/**
* wait until condition is true or timeout is reached
*/
protected <V> V wait_until_true_or_timeout(ExpectedCondition<V> isTrue) {
protected <V> V waitUntilTrueOrTimeout(ExpectedCondition<V> isTrue) {
Wait<WebDriver> wait = new WebDriverWait(this.driver, waitTimeOutSeconds)
.ignoring(StaleElementReferenceException.class);
try {
Expand Down
Expand Up @@ -6,7 +6,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(classes= SecurityTestConfig.class)
@ContextConfiguration(classes = SecurityTestConfig.class)
public abstract class AbstractStepDefinition {
protected Scenario scenario;

Expand All @@ -16,6 +16,7 @@ public abstract class AbstractStepDefinition {
/**
* Get a reference to the current cucumber scenario
* Supports writing text and xml to report within test steps
*
* @param scenario
*/
public void before(Scenario scenario) {
Expand Down
Expand Up @@ -5,7 +5,6 @@
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
Expand All @@ -14,31 +13,21 @@
import org.zaproxy.clientapi.core.ClientApi;
import org.zaproxy.clientapi.core.ClientApiException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.*;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class GoogleSearchStepDefs extends AbstractStepDefinition {
private static Logger log = Logger.getLogger(GoogleSearchStepDefs.class.getName());

@Autowired
private GoogleSearchPageObject googleSearchPage;
@Autowired
private ClientApi clientApi;

private final String setBoldText = "\033[0;1m";
private final String setPlainText = "\033[0;0m";
private final String reportPath = "security-reports/security-report.html";

static Logger log = Logger.getLogger(GoogleSearchStepDefs.class.getName());

@Before
public void before(Scenario scenario) {
super.before(scenario);
Expand All @@ -50,17 +39,17 @@ public void before(Scenario scenario) {
}

@Given("^I am on the Google search page")
public void I_am_on_the_google_search_page() throws Throwable {
public void iAmOnTheGoogleSearchPage() throws Throwable {
googleSearchPage.goToAndWait();
}

@When("^I search for \"(.+)\"$")
public void I_search_for(String searchText) throws Throwable {
public void iSearchFor(String searchText) throws Throwable {
googleSearchPage.search(searchText);
}

@Then("^the site \"(.+)\" should be present in the results$")
public void the_result_should_contain_url(String resultUrl) throws Throwable {
public void theResultShouldContainUrl(String resultUrl) throws Throwable {
assertThat(googleSearchPage.isSearchResultPresent(resultUrl)).isTrue();
}

Expand All @@ -83,6 +72,8 @@ public void theNumberOfSecurityAlertsShouldNotBeGreaterThan(List<StepDefRisks> r
assertThat(mediumAlerts.size()).as("Medium risk Alerts").isLessThanOrEqualTo(risks.get(0).getMedium());
assertThat(highAlerts.size()).as("High risk Alerts").isLessThanOrEqualTo(risks.get(0).getHigh());

String setPlainText = "\033[0;0m";
String setBoldText = "\033[0;1m";
log.info(setBoldText + " Found " + lowAlerts.size() + " low risk alerts: " + setPlainText);
lowAlerts.forEach(a -> log.info("Alert: " + a.getAlert() + " at URL: " + a.getUrl() + " Parameter: " + a.getParam() + " CWE ID: " + a.getCweId() + " Risk: " + a.getRisk()));
log.info(setBoldText + " Found " + mediumAlerts.size() + " medium risk alerts: " + setPlainText);
Expand All @@ -105,6 +96,7 @@ public void generateHTMLReport() {
}
OutputStream htmlFile = null;
try {
String reportPath = "security-reports/security-report.html";
File htmlReport = new File(reportPath);
htmlReport.getParentFile().mkdirs();
htmlReport.createNewFile();
Expand Down
7 changes: 4 additions & 3 deletions ui-acceptance-tests/pom.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>test-automation-quickstart</artifactId>
Expand Down Expand Up @@ -29,7 +29,8 @@
<glue>com.opencredo.test.ui.acceptance.test.step.definitions</glue>
<!-- These are the default values -->
<!-- Where to output the generated Junit tests -->
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber
</outputDirectory>
<!-- The diectory containing your feature files. -->
<featuresDirectory>src/test/resources/cucumber/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
Expand Down
Expand Up @@ -2,7 +2,6 @@

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
* Used to retrieve properties and make them available to tests
Expand Down
@@ -1,9 +1,9 @@
package com.opencredo.test.ui.acceptance.test.config.spring;

import com.opencredo.test.SharedDriver;
import com.opencredo.test.ui.acceptance.test.interaction.objects.GoogleSearchPageObject;
import com.opencredo.test.ui.acceptance.test.config.TestWorld;
import com.opencredo.test.ui.acceptance.test.config.UiTestProperties;
import com.opencredo.test.ui.acceptance.test.interaction.objects.GoogleSearchPageObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
Expand Down

0 comments on commit 696b500

Please sign in to comment.