Skip to content

Commit

Permalink
Fixing up the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Casperson authored and Matthew Casperson committed Apr 5, 2017
1 parent 44ce6f6 commit d37d02b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/au/com/agic/apptesting/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public int run(final List<File> globalTempFiles) {
Gracefully shutdown the proxies
*/
if (proxies != null) {
PROXY_MANAGER.stopProxies(proxies);
PROXY_MANAGER.stopProxies(proxies, reportOutput);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ List<ProxyDetails<?>> configureProxies(
* Gracefully shutdown proxies before we exit the app
* @param proxies The list of proxies that were created for this test
*/
void stopProxies(@NotNull List<ProxyDetails<?>> proxies);
void stopProxies(@NotNull List<ProxyDetails<?>> proxies, final String reportOutput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ public synchronized FeatureState getDesiredCapabilitiesForThread(@NotNull final
/*
We have allocated our available configurations
*/
if (currentUrl >= Math.max(originalApplicationUrls.size(), 1)) {
throw new ConfigurationException("Configuration pool has been exhausted!");
final int urlCount = Math.max(originalApplicationUrls.size(), 1);
if (currentUrl >= urlCount) {
throw new ConfigurationException("Configuration pool has been exhausted! "
+ currentUrl + " is greater than or equal to " + urlCount);
}

/*
Expand Down Expand Up @@ -237,7 +239,7 @@ public synchronized void shutdown() {
threadIdToCapMap.clear();

/*
Attemp to delete all the temp folders
Attempt to delete all the temp folders
*/
getTempFolders().forEach(e -> Try.run(() -> FileUtils.deleteDirectory(e)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package au.com.agic.apptesting.utils.impl;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import au.com.agic.apptesting.State;
Expand All @@ -13,6 +14,7 @@

import net.lightbody.bmp.BrowserMobProxy;

import org.apache.commons.lang3.StringUtils;
import org.zaproxy.clientapi.core.ClientApi;

import java.io.File;
Expand Down Expand Up @@ -93,8 +95,9 @@ public List<ProxyDetails<?>> configureProxies(
}

@Override
public void stopProxies(@NotNull final List<ProxyDetails<?>> proxies) {
public void stopProxies(@NotNull final List<ProxyDetails<?>> proxies, final String reportOutput) {
checkNotNull(proxies);
checkArgument(StringUtils.isNotBlank(reportOutput));

proxies.stream()
.filter(proxyDetails -> BrowsermobProxyUtilsImpl.PROXY_NAME.equals(proxyDetails.getProxyName()))
Expand All @@ -114,7 +117,7 @@ public void stopProxies(@NotNull final List<ProxyDetails<?>> proxies) {
+ Constants.HAR_FILE_NAME_EXTENSION;

final File file = new File(
State.getFeatureStateForThread().getReportDirectory()
reportOutput
+ "/"
+ filename);
proxy.getHar().writeTo(file);
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/au/com/agic/apptesting/LiveTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ public void stepTests() {
We always expect to find the browsermob<date>.har file, regardless of the
success or failure of the test.
*/
Stream.of(getHarFiles()).map(File::getName).forEach(LOGGER::info);
Assert.assertTrue(Stream.of(getHarFiles()).anyMatch(file -> file.getName().matches(
LOGGER.info("Testing for har file presence");
Assert.assertTrue(getHarFiles().length != 0);
Assert.assertTrue(Stream.of(getHarFiles())
.anyMatch(file -> file.getName().matches(
Constants.HAR_FILE_NAME_PREFIX
+ "\\d{17}\\."
+ Constants.HAR_FILE_NAME_EXTENSION)));
Expand All @@ -192,7 +194,8 @@ public void stepTests() {
/*
We expect to have a manually dumped har file
*/
Assert.assertTrue(Stream.of(getHarFiles()).anyMatch(file -> file.getName().matches("test\\d{17}\\.har")));
Assert.assertTrue(Stream.of(getHarFiles())
.anyMatch(file -> file.getName().matches("test\\d{17}\\.har")));

continue browserLoop;
}
Expand Down

0 comments on commit d37d02b

Please sign in to comment.