From 3bd08a581fd63c249c8494fde5a204d6bb589dec Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 10:39:56 +0200 Subject: [PATCH 001/301] oops: NPEx when addMusts --- .../java/il/co/topq/integframework/cli/conn/CliCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/CliCommand.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/CliCommand.java index 4b845aa..39fcec3 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/CliCommand.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/CliCommand.java @@ -396,6 +396,9 @@ public List getMusts() { * @param musts */ public void addMusts(List musts) { + if (this.musts == null) { + this.musts = new ArrayList(); + } this.musts.addAll(musts); for (String must: musts){ addAnalyzers(new FindTextAssertion(must)); From b2b52807a3197d4e41631f769863116c05bfe32d Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 11:00:54 +0200 Subject: [PATCH 002/301] 1. the command is now protected. 2. if the CliConnection is a module - use integs Assert for cleaner code and reading the clear result 3. removed some unused predicated in if statements --- .../cli/process/CliCommandExecution.java | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java index 6f9cf96..770d3e4 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java @@ -1,7 +1,10 @@ package il.co.topq.integframework.cli.process; import il.co.topq.integframework.AbstractModule; +import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.assertion.FindTextAssertion; import il.co.topq.integframework.assertion.IAssertionLogic; +import il.co.topq.integframework.assertion.TextNotFoundAssertion; import il.co.topq.integframework.cli.conn.CliCommand; import il.co.topq.integframework.cli.conn.CliConnection; import il.co.topq.integframework.utils.StringUtils; @@ -15,7 +18,7 @@ public class CliCommandExecution { private final CliConnection cliConnection; private long timeout = -1; private String title = ""; - private String cmd = ""; + protected String cmd = ""; private List musts, errors; protected String result; protected final List> assrtions; @@ -46,7 +49,7 @@ public CliCommandExecution withTitle(String title) { } public CliCommandExecution mustHaveResponse(String... strings) { - if (musts == null || musts.isEmpty()) { + if (musts == null) { musts = new ArrayList(strings.length); } musts.addAll(Arrays.asList(strings)); @@ -64,25 +67,39 @@ public void execute() throws Exception { } CliCommand cliCommand = new CliCommand(cmd); - if (musts != null && !musts.isEmpty()) { - cliCommand.addMusts(musts); - } - if (errors != null && !errors.isEmpty()) { - for (String error : errors) { - cliCommand.addErrors(error); + if (!(cliConnection instanceof AbstractModule)) { + if (musts != null && !musts.isEmpty()) { + cliCommand.addMusts(musts); + } + if (errors != null && !errors.isEmpty()) { + for (String error : errors) { + cliCommand.addErrors(error); + } } } cliCommand.setTimeout(timeout); this.cliConnection.handleCliCommand(title, cliCommand); if (cliConnection instanceof AbstractModule) { - String result = ((AbstractModule) cliConnection).getActual(String.class); + AbstractModule cliModule = (AbstractModule) cliConnection; + String result = cliModule.getActual(String.class); String commandLine = cmd + this.cliConnection.getEnterStr(); result = StringUtils.getFirstSubStringSuffix(result, commandLine, true); if (result.contains(this.cliConnection.getEnterStr())) { result = StringUtils.getPrefix(result, this.cliConnection.getEnterStr()); } setResult(result.trim()); + cliModule.setActual(this.result); + if (musts != null && !musts.isEmpty()) { + for (String must : musts) { + Assert.assertLogic(cliModule.getActual(String.class), new FindTextAssertion(must)); + } + } + if (errors != null && !errors.isEmpty()) { + for (String error : errors) { + Assert.assertLogic(cliModule.getActual(String.class), new TextNotFoundAssertion(error)); + } + } } } @@ -115,7 +132,7 @@ protected void setResult(String result) { // } public CliCommandExecution error(String... errors) { - if (this.errors == null || this.errors.isEmpty()) { + if (this.errors == null) { this.errors = new ArrayList(errors.length); } this.errors.addAll(Arrays.asList(errors)); From 537db51936b47da5d5429b53926d3c1a2d002254 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 11:01:35 +0200 Subject: [PATCH 003/301] typo --- .../main/java/il/co/topq/integframework/assertion/Assert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index a41b7f9..bba6595 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -18,7 +18,7 @@ static public void assertStringContains(final String actual, final String expect throw new IllegalArgumentException("Actual can't be null"); } if (null == expected) { - throw new IllegalArgumentException("logic can't be null"); + throw new IllegalArgumentException("expected can't be null"); } if (!actual.contains(expected)) { fail(expected + " is not contained in " + actual); From faf64de64ee6bce2609aedb888d5b65dbff8f47c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 11:01:58 +0200 Subject: [PATCH 004/301] varargs safty --- .../il/co/topq/integframework/assertion/CollectionAssertion.java | 1 + 1 file changed, 1 insertion(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java index 7c245c9..c408a4a 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java @@ -235,6 +235,7 @@ public CollectionAssertion compareWith(List> comparators) { * @param comparators * @return */ + @SafeVarargs public CollectionAssertion andNowCompareWith(Comparator... comparators) { this.comparators = null; return andNowCompareWith(Arrays.asList(comparators)); From 8ed706c2a1d10f5771e2fade162c4b4f23131e34 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 11:02:55 +0200 Subject: [PATCH 005/301] new method: get a random item from a collection --- .../java/il/co/topq/integframework/utils/RandomUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java index 0b4bd52..5b73c21 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java @@ -1,6 +1,7 @@ package il.co.topq.integframework.utils; import java.util.ArrayList; +import java.util.Collection; import java.util.Random; /** @@ -235,4 +236,9 @@ public static Object[] randomizeGroup(Object[] originalGroup, Random random) { return toReturn; } + public static E getRandomItemFrom(Collection collection) { + return new ArrayList(collection).get(getRandomInt(0, collection.size(), new Random())); + + } + } From 6077046a917096b6a029fdefb93bf4751167e6a6 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 11:03:32 +0200 Subject: [PATCH 006/301] new module: wget --- integ-parent/pom.xml | 1 + integ-wget/pom.xml | 16 ++++ .../il/co/topq/integframework/WgetClient.java | 79 ++++++++++++++++ .../il/co/topq/integframework/WgetModule.java | 91 +++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 integ-wget/pom.xml create mode 100644 integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java create mode 100644 integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java diff --git a/integ-parent/pom.xml b/integ-parent/pom.xml index 137c17a..47a30ea 100644 --- a/integ-parent/pom.xml +++ b/integ-parent/pom.xml @@ -80,5 +80,6 @@ ../integ-hdfs ../integ-support ../integ-rest + ../integ-wget \ No newline at end of file diff --git a/integ-wget/pom.xml b/integ-wget/pom.xml new file mode 100644 index 0000000..6ca9dbd --- /dev/null +++ b/integ-wget/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + + il.co.topq.integframework + integ-parent + 1.0.1-SNAPSHOT + + integ-wget + + + il.co.topq.integframework + integ-cli + 1.0.1-SNAPSHOT + + + \ No newline at end of file diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java new file mode 100644 index 0000000..836ccf5 --- /dev/null +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -0,0 +1,79 @@ +package il.co.topq.integframework; + + +public class WgetClient { + final String userAgent, ip; + + private final WgetModule module; + + + public WgetClient(WgetModule module, String ip, String userAgent) { + this.module = module; + this.ip = ip; + this.userAgent = userAgent; + } + + public String getUserAgent() { + return userAgent; + } + + public String getIp() { + return ip; + } + + public void post(CharSequence data) throws Exception { + module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(data).error("failed") + .execute(); + } + + public void bindAddress() throws Exception { + module.new AddIpCommand(ip).execute(); + } + + public void unbindAddress() throws Exception { + module.new DeleteIpCommand(ip).execute(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((ip == null) ? 0 : ip.hashCode()); + result = prime * result + ((userAgent == null) ? 0 : userAgent.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + WgetClient other = (WgetClient) obj; + if (ip == null) { + if (other.ip != null) + return false; + } else if (!ip.equals(other.ip)) + return false; + if (userAgent == null) { + if (other.userAgent != null) + return false; + } else if (!userAgent.equals(other.userAgent)) + return false; + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WgetClient [ip="); + builder.append(ip); + builder.append(", userAgent="); + builder.append(userAgent); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java new file mode 100644 index 0000000..8c67457 --- /dev/null +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java @@ -0,0 +1,91 @@ +package il.co.topq.integframework; + +import il.co.topq.integframework.cli.process.CliCommandExecution; +import il.co.topq.integframework.cli.process.CommandLineModule; +import il.co.topq.integframework.utils.StringUtils; + +import java.net.URL; + +import org.testng.Assert; + +public class WgetModule extends CommandLineModule { + + String url; + + @Override + public void init() throws Exception { + + super.init(); + Assert.assertNotNull(cliConnectionImpl, "cli property not set"); + Assert.assertNotSame(url, "", "url property not set"); + } + public class AddIpCommand extends CliCommandExecution { + public AddIpCommand(String ipAddress) { + super(getCliConnectionImpl(), "sudo ip -4 addr add " + ipAddress + "/32 dev lo scope host"); + withTitle("add ip address"); + } + } + + public class DeleteIpCommand extends CliCommandExecution { + public DeleteIpCommand(String ipAddress) { + super(getCliConnectionImpl(), "sudo ip -4 addr del " + ipAddress + "/32 dev lo scope host"); + withTitle("remove ip address"); + } + } + + public class WgetCommand extends CliCommandExecution { + private final StringBuilder command = new StringBuilder("wget"); + + public WgetCommand() { + super(getCliConnectionImpl()); + withTitle("wget"); + } + + public WgetCommand withUserAgent(String userAgent) { + command.append(" --user-agent='").append(userAgent).append("' "); + return this; + } + + public WgetCommand doNotDownloadAnything() { + return downloadTo("/dev/null"); + } + + public WgetCommand downloadTo(String target) { + command.append("-O ").append(target); + return this; + } + + public WgetCommand bindAddress(String address) { + command.append(" --bind-address=").append(address); + return this; + } + + public WgetCommand referer(URL url) { + command.append(" --referer='").append(url).append("' "); + return this; + } + + public WgetCommand post(CharSequence data) { + command.append(" --post-data=\"").append(data).append('"'); + return this; + } + + @Override + public void execute() throws Exception { + if (StringUtils.isEmpty(cmd)) { + cmd = command.append(' ').append(url).toString(); + } + super.execute(); + } + + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + +} From c2df362efc4bb6dd06eb5ad1ff8251451d342f44 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Feb 2014 13:23:50 +0200 Subject: [PATCH 007/301] boolean logic should be AND rather than OR --- .../main/java/il/co/topq/integframework/assertion/Assert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index bba6595..09639eb 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -53,7 +53,7 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< throw new TimeoutException("Assertion interrupted"); } } - } while (timeUp < System.currentTimeMillis() || !logic.status); + } while (timeUp < System.currentTimeMillis() && !logic.status); if (!logic.status) { throw new TimeoutException("Assertion failed"); } From 8b7279f3a8ecbc8dad02b1a317f251ef5eaee456 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:08:54 +0200 Subject: [PATCH 008/301] ignoring assertion error in CliConnectionWait --- .../il/co/topq/integframework/cli/support/CliConnectionWait.java | 1 + 1 file changed, 1 insertion(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliConnectionWait.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliConnectionWait.java index 7fa7a4d..f01af78 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliConnectionWait.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliConnectionWait.java @@ -14,6 +14,7 @@ public CliConnectionWait(CliConnection input) { super(input); withTimeout(DEFAULT_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); pollingEvery(DEFAULT_POLLING_INTERVAL_IN_MILLISECONDS, TimeUnit.MILLISECONDS); + ignoring(AssertionError.class); } } From 28b99c754112ed1e655c2312ad315811edeae0d7 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:10:37 +0200 Subject: [PATCH 009/301] clean up line --- .../integframework/cli/support/LinuxCliExpectedConditions.java | 1 - 1 file changed, 1 deletion(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java index a9c4f5e..c15daa5 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java @@ -219,5 +219,4 @@ public Boolean apply(LinuxDefaultCliConnection linux) throws Exception { } }; } - } From 0f29a64368ddbdff91b1e91548c95fb6f236387a Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:12:36 +0200 Subject: [PATCH 010/301] CliExecution wait mechanism +ExpectedCondition(s) and examples --- .../CliExecutionExpectedCondition.java | 9 ++ .../CliExecutionExpectedConditions.java | 56 +++++++++ .../cli/support/CliExecutionWait.java | 25 ++++ .../LinuxFileContentExecutionBuilder.java | 55 +++++++++ .../LinuxFileInfoExecutionBuilder.java | 108 ++++++++++++++++++ 5 files changed, 253 insertions(+) create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedCondition.java create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionWait.java create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedCondition.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedCondition.java new file mode 100644 index 0000000..81857b9 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedCondition.java @@ -0,0 +1,9 @@ +package il.co.topq.integframework.cli.support; + +import il.co.topq.integframework.cli.process.CliCommandExecution; + +import com.google.common.base.Function; + +public interface CliExecutionExpectedCondition extends Function { + +} diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java new file mode 100644 index 0000000..dbd78c5 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -0,0 +1,56 @@ +package il.co.topq.integframework.cli.support; + +import il.co.topq.integframework.assertion.AbstractAssertionLogic; +import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.cli.process.CliCommandExecution; + +public abstract class CliExecutionExpectedConditions { + final Object __; + + private CliExecutionExpectedConditions() { + __ = null; // util class, do not init! + } + + public static CliExecutionExpectedCondition executionLogicHappens(final AbstractAssertionLogic logic) { + return new CliExecutionExpectedCondition() { + @Override + public String apply(CliCommandExecution execution) { + try { + execution.execute(); + } catch (Exception e) { + Assert.fail(toString(), e); + } + Assert.assertLogic(execution.getResult(), logic); + return execution.getResult(); + } + + @Override + public String toString() { + return logic.getTitle(); + } + }; + + } + + public static CliExecutionExpectedCondition executionResponseReturn(final String mustHaveResponse) { + return new CliExecutionExpectedCondition() { + @Override + public String apply(CliCommandExecution execution) { + try { + execution.mustHaveResponse(mustHaveResponse).execute(); + } catch (Exception e) { + Assert.fail(toString(), e); + } + return execution.getResult(); + } + + @Override + public String toString() { + return "execution must have response of " + mustHaveResponse; + } + }; + + } + + +} diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionWait.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionWait.java new file mode 100644 index 0000000..7483779 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionWait.java @@ -0,0 +1,25 @@ +package il.co.topq.integframework.cli.support; + +import il.co.topq.integframework.cli.conn.CliConnection; +import il.co.topq.integframework.cli.process.CliCommandExecution; +import il.co.topq.integframework.support.FluentWait; + +import java.util.concurrent.TimeUnit; + +public class CliExecutionWait extends FluentWait { + + private static final int DEFAULT_POLLING_INTERVAL_IN_MILLISECONDS = 500; + private static final int DEFAULT_TIMEOUT_IN_MINUTES = 2; + + public CliExecutionWait(CliCommandExecution execution) { + super(execution); + withTimeout(DEFAULT_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES); + pollingEvery(DEFAULT_POLLING_INTERVAL_IN_MILLISECONDS, TimeUnit.MILLISECONDS); + ignoring(AssertionError.class); + } + + public CliExecutionWait(CliConnection cliConnection, String command) { + this(new CliCommandExecution(cliConnection, command)); + } + +} diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java new file mode 100644 index 0000000..5336097 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java @@ -0,0 +1,55 @@ +package il.co.topq.integframework.cli.support; + +import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.cli.conn.CliConnection; +import il.co.topq.integframework.cli.process.CliCommandExecution; + +public class LinuxFileContentExecutionBuilder { + String name = ""; + private final CliConnection cliConnection; + private boolean fromHead = false; + private int maxLines = 10; + + public LinuxFileContentExecutionBuilder(CliConnection cliConnection, String fileName) { + + this.cliConnection = cliConnection; + this.name = fileName; + } + + LinuxFileContentExecutionBuilder named(String name) { + this.name = name; + return this; + } + + public CliCommandExecution build() { + if (name.length() == 0) + throw new IllegalStateException("file name is not set"); + StringBuilder command = new StringBuilder(); + if (fromHead) { + command.append("head "); + } else { + command.append("tail "); + } + command.append("-n ").append(maxLines).append(" "); + command.append(name); + + return new CliCommandExecution(cliConnection, command.toString()); + } + + public CliExecutionExpectedCondition containingText(final String expected) { + + return new CliExecutionExpectedCondition() { + + @Override + public String apply(CliCommandExecution input) { + try { + input.mustHaveResponse(expected).execute(); + } catch (Exception e) { + Assert.fail("execution failed", e); + } + return input.getResult(); + } + }; + + } +} diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java new file mode 100644 index 0000000..d99d22a --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java @@ -0,0 +1,108 @@ +package il.co.topq.integframework.cli.support; + +import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.assertion.CompareMethod; +import il.co.topq.integframework.assertion.LongCompareAssertion; +import il.co.topq.integframework.cli.conn.CliConnection; +import il.co.topq.integframework.cli.process.CliCommandExecution; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class LinuxFileInfoExecutionBuilder { + + String name = ""; + private final CliConnection cliConnection; + + private ResultType resultType = ResultType.FileSize; + + public LinuxFileInfoExecutionBuilder(CliConnection cliConnection, String fileName) { + super(); + this.cliConnection = cliConnection; + this.name = fileName; + } + + LinuxFileInfoExecutionBuilder named(String name) { + this.name = name; + return this; + } + + public CliCommandExecution build() { + if (name.length() == 0) + throw new IllegalStateException("file name is not set"); + return new CliCommandExecution(cliConnection, "ls -l --time-style=full-iso " + this.name + + " | grep -v '^total' | awk {'print " + resultType.awkPrint + "'}").error("No such file or directory").error( + "cannot access"); + } + + public LinuxFileInfoExecutionBuilder getFileSize() { + this.resultType = ResultType.FileSize; + return this; + } + + public LinuxFileInfoExecutionBuilder getFileDate() { + this.resultType = ResultType.FileSize; + return this; + } + + public CliExecutionExpectedCondition fileSizeToBe(CompareMethod compareMethod, long expectedSize) { + getFileSize(); + return execute(resultType, expectedSize, compareMethod); + } + + private static CliExecutionExpectedCondition execute(final ResultType resultType, final long expected, + final CompareMethod compareMethod) { + return new CliExecutionExpectedCondition() { + + @Override + public Long apply(CliCommandExecution input) { + try { + long result; + input.execute(); + LongCompareAssertion compareAssertion = new LongCompareAssertion(expected, compareMethod); + Assert.assertLogicHappens(result = resultType.parser.parse(input.getResult()), compareAssertion, 0l, true); + return result; + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + }; + } + + public enum ResultType { + FileDate("$6,$7,$8", new Parser() { + private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); + + @Override + public Long parse(String s) throws ParseException { + Date actual = dateFormat.parse(s); + return actual.getTime(); + } + + }), + + FileSize("$5", new Parser() { + @Override + public Long parse(String s) { + long actual = Long.parseLong(s); + return actual; + } + }); + + final String awkPrint; + final Parser parser; + + ResultType(final String awkPrint, final Parser parser) { + this.awkPrint = awkPrint; + this.parser = parser; + } + + private interface Parser> { + + Long parse(String result) throws ParseException; + } + } + +} From a2c32fa84a4080e87fa3b45f056f89377594846c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:23:22 +0200 Subject: [PATCH 011/301] post data with ' instead of " --- .../src/main/java/il/co/topq/integframework/WgetModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java index 8c67457..87560e7 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java @@ -66,7 +66,7 @@ public WgetCommand referer(URL url) { } public WgetCommand post(CharSequence data) { - command.append(" --post-data=\"").append(data).append('"'); + command.append(" --post-data=\'").append(data).append('\''); return this; } From 568086f692dac45c573efc8eb940f33f53080910 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:24:01 +0200 Subject: [PATCH 012/301] @SafeVarargs requires method to be final --- .../co/topq/integframework/assertion/CollectionAssertion.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java index c408a4a..25d90ae 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java @@ -218,7 +218,7 @@ public CollectionAssertion withComparator(Comparator comparator) { } @SafeVarargs - public CollectionAssertion compareWith(Comparator... comparators) { + public final CollectionAssertion compareWith(Comparator... comparators) { return compareWith(Arrays.asList(comparators)); } @@ -236,7 +236,7 @@ public CollectionAssertion compareWith(List> comparators) { * @return */ @SafeVarargs - public CollectionAssertion andNowCompareWith(Comparator... comparators) { + public final CollectionAssertion andNowCompareWith(Comparator... comparators) { this.comparators = null; return andNowCompareWith(Arrays.asList(comparators)); } From 776164273c9ca600ef51f55fd2bf368811c76ecc Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:26:25 +0200 Subject: [PATCH 013/301] 1. Refactoring enum CompareMethod is now in a new file. this means that you need to add import to your code! 2. New compare assertions (Long, Comparable) --- .../db/DatabaseSystemModule.java | 2 +- .../assertion/ComparableAssertion.java | 81 ++++++++++++++++++ .../assertion/CompareMethod.java | 6 ++ .../assertion/LongCompareAssertion.java | 82 +++++++++++++++++++ .../assertion/NumberCompareAssertion.java | 5 -- 5 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/assertion/LongCompareAssertion.java diff --git a/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java b/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java index 5a28ca4..8e7c3e8 100644 --- a/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java +++ b/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java @@ -2,8 +2,8 @@ import il.co.topq.integframework.AbstractModuleImpl; import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.assertion.CompareMethod; import il.co.topq.integframework.assertion.NumberCompareAssertion; -import il.co.topq.integframework.assertion.NumberCompareAssertion.CompareMethod; import java.util.ArrayList; import java.util.List; diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java new file mode 100644 index 0000000..e92c3dd --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java @@ -0,0 +1,81 @@ +package il.co.topq.integframework.assertion; + +public class ComparableAssertion> extends AbstractAssertionLogic { + + private final T expected; + + private T actualObject; + + private final CompareMethod compareMethod; + + public ComparableAssertion(T expected, CompareMethod compareMethod) { + super(); + this.expected = expected; + this.compareMethod = compareMethod; + } + + @Override + public void doAssertion() { + status = true; + switch (compareMethod) { + case BIGGER: + if (actualObject.compareTo(expected) > 0) { + title = "Actual [" + actualObject + "] is bigger then " + expected; + } else { + title = "Actual [" + actualObject + "] is NOT bigger then " + expected; + status = false; + } + break; + case BIGGER_OR_EQUALS: + if (actualObject.compareTo(expected) >= 0) { + title = "Actual [" + actualObject + "] is bigger or equals to " + expected; + } else { + title = "Actual [" + actualObject + "] is NOT bigger or equals to " + expected; + status = false; + } + + break; + case EQUALS: + if (actualObject.compareTo(expected) == 0) { + title = "Actual [" + actualObject + "] is equals to " + expected; + } else { + title = "Actual [" + actualObject + "] is NOT equals to " + expected; + status = false; + } + break; + + case SMALLER_OR_EQUALS: + if (actualObject.compareTo(expected) <= 0) { + title = "Actual [" + actualObject + "] is smaller or equals to " + expected; + } else { + title = "Actual [" + actualObject + "] is NOT smaller or equals to " + expected; + status = false; + } + break; + case SMALLER: + if (actualObject.compareTo(expected) < 0) { + title = "Actual [" + actualObject + "] is smaller then " + expected; + } else { + title = "Actual [" + actualObject + "] is NOT smaller then " + expected; + status = false; + } + break; + + default: + break; + } + + } + + + /** + * Sets the actual object to perfrom assertion on + */ + @Override + public void setActual(T actual) { + if (actual != null) { + actualObject = actual; + } + } + +} diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java new file mode 100644 index 0000000..4ece0c3 --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java @@ -0,0 +1,6 @@ +package il.co.topq.integframework.assertion; + +public enum CompareMethod { + BIGGER, BIGGER_OR_EQUALS, EQUALS, SMALLER_OR_EQUALS, SMALLER + +} \ No newline at end of file diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/LongCompareAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/LongCompareAssertion.java new file mode 100644 index 0000000..08510c5 --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/LongCompareAssertion.java @@ -0,0 +1,82 @@ +package il.co.topq.integframework.assertion; + +public class LongCompareAssertion extends AbstractAssertionLogic { + + + private final long expected; + + private long actualLong; + + private final CompareMethod compareMethod; + + public LongCompareAssertion(long expected, CompareMethod compareMethod) { + super(); + this.expected = expected; + this.compareMethod = compareMethod; + } + + @Override + public void doAssertion() { + status = true; + switch (compareMethod) { + case BIGGER: + if (actualLong > expected) { + title = "Actual number " + actualLong + " is bigger then " + expected; + } else { + title = "Actual number " + actualLong + " is NOT bigger then " + expected; + status = false; + } + break; + case BIGGER_OR_EQUALS: + if (actualLong >= expected) { + title = "Actual number " + actualLong + " is bigger or equals to " + expected; + } else { + title = "Actual number " + actualLong + " is NOT bigger or equals to " + expected; + status = false; + } + + break; + case EQUALS: + if (actualLong == expected) { + title = "Actual number " + actualLong + " is equals to " + expected; + } else { + title = "Actual number " + actualLong + " is NOT equals to " + expected; + status = false; + } + break; + + case SMALLER_OR_EQUALS: + if (actualLong <= expected) { + title = "Actual number " + actualLong + " is smaller or equals to " + expected; + } else { + title = "Actual number " + actualLong + " is NOT smaller or equals to " + expected; + status = false; + } + break; + case SMALLER: + if (actualLong < expected) { + title = "Actual number " + actualLong + " is smaller then " + expected; + } else { + title = "Actual number " + actualLong + " is NOT smaller then " + expected; + status = false; + } + break; + + default: + break; + } + + } + + + /** + * Sets the actual object to perfrom assertion on + */ + @Override + public void setActual(Long actual) { + if (actual != null) { + actualLong = actual; + } + } + +} diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/NumberCompareAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/NumberCompareAssertion.java index 43126a3..c8c8abd 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/NumberCompareAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/NumberCompareAssertion.java @@ -2,11 +2,6 @@ public class NumberCompareAssertion extends AbstractAssertionLogic { - public enum CompareMethod { - BIGGER, BIGGER_OR_EQUALS, EQUALS, SMALLER_OR_EQUALS, SMALLER - - } - private final int expected; private int actualInt; From 578175a04d612afbd4d5dd2903e78c0f76bb85b9 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 16:26:50 +0200 Subject: [PATCH 014/301] version 1.0.2-SNAPSHOT --- integ-bdd/pom.xml | 2 +- integ-cli/pom.xml | 2 +- integ-db/pom.xml | 5 ++-- integ-groovy-bdd/pom.xml | 7 ++--- integ-hdfs/pom.xml | 5 ++-- integ-image-validator/pom.xml | 55 +++++++++++++++++------------------ integ-jms/pom.xml | 5 ++-- integ-junit/pom.xml | 5 ++-- integ-parent/pom.xml | 8 +++-- integ-rest/pom.xml | 2 +- integ-support/pom.xml | 2 +- integ-testng/pom.xml | 9 +++--- integ-webdriver/pom.xml | 5 ++-- integ-wget/pom.xml | 2 +- 14 files changed, 54 insertions(+), 60 deletions(-) diff --git a/integ-bdd/pom.xml b/integ-bdd/pom.xml index f5bd72f..f3b5e0c 100644 --- a/integ-bdd/pom.xml +++ b/integ-bdd/pom.xml @@ -4,7 +4,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent diff --git a/integ-cli/pom.xml b/integ-cli/pom.xml index 3f7ab9a..1d19ef1 100644 --- a/integ-cli/pom.xml +++ b/integ-cli/pom.xml @@ -31,7 +31,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-db/pom.xml b/integ-db/pom.xml index 079ea66..9b65cef 100644 --- a/integ-db/pom.xml +++ b/integ-db/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-db @@ -22,7 +21,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-groovy-bdd/pom.xml b/integ-groovy-bdd/pom.xml index 7a2638c..1ab8237 100644 --- a/integ-groovy-bdd/pom.xml +++ b/integ-groovy-bdd/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-groovy-bdd @@ -70,7 +69,7 @@ - + @@ -83,7 +82,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-hdfs/pom.xml b/integ-hdfs/pom.xml index 57e9900..b6ec4b0 100644 --- a/integ-hdfs/pom.xml +++ b/integ-hdfs/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-hdfs @@ -39,7 +38,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent diff --git a/integ-image-validator/pom.xml b/integ-image-validator/pom.xml index 5ec9f9a..52d0636 100644 --- a/integ-image-validator/pom.xml +++ b/integ-image-validator/pom.xml @@ -1,29 +1,28 @@ - - 4.0.0 - integ-image-validator - - - - junit - junit - 4.10 - - - il.co.topq.integframework - integ-cli - ${project.version} - - - il.co.topq.integframework - integ-testng - ${project.version} - - - - il.co.topq.integframework - integ-parent - 1.0.1-SNAPSHOT - ../integ-parent - + + 4.0.0 + integ-image-validator + + + + junit + junit + 4.10 + + + il.co.topq.integframework + integ-cli + ${project.version} + + + il.co.topq.integframework + integ-testng + ${project.version} + + + + il.co.topq.integframework + integ-parent + 1.0.2-SNAPSHOT + ../integ-parent + \ No newline at end of file diff --git a/integ-jms/pom.xml b/integ-jms/pom.xml index 108f542..37e4886 100644 --- a/integ-jms/pom.xml +++ b/integ-jms/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-jms @@ -22,7 +21,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-junit/pom.xml b/integ-junit/pom.xml index ac17c61..047cb29 100644 --- a/integ-junit/pom.xml +++ b/integ-junit/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-junit @@ -18,7 +17,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-parent/pom.xml b/integ-parent/pom.xml index 47a30ea..be7cd0c 100644 --- a/integ-parent/pom.xml +++ b/integ-parent/pom.xml @@ -1,9 +1,8 @@ - + 4.0.0 il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT pom UTF-8 @@ -82,4 +81,7 @@ ../integ-rest ../integ-wget + + scm:git:https://github.com/aharonha/integ-framework + \ No newline at end of file diff --git a/integ-rest/pom.xml b/integ-rest/pom.xml index 06af590..0ac3bad 100644 --- a/integ-rest/pom.xml +++ b/integ-rest/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../../integ/integ-parent integ-rest diff --git a/integ-support/pom.xml b/integ-support/pom.xml index c72a92a..8106d03 100644 --- a/integ-support/pom.xml +++ b/integ-support/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent integ-support diff --git a/integ-testng/pom.xml b/integ-testng/pom.xml index 3a4a705..6c6d9e1 100644 --- a/integ-testng/pom.xml +++ b/integ-testng/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-testng @@ -44,8 +43,8 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + 1.7 + 1.7 @@ -55,7 +54,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-webdriver/pom.xml b/integ-webdriver/pom.xml index 0be0551..77d7ca3 100644 --- a/integ-webdriver/pom.xml +++ b/integ-webdriver/pom.xml @@ -1,5 +1,4 @@ - + 4.0.0 integ-webdriver @@ -72,7 +71,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT ../integ-parent diff --git a/integ-wget/pom.xml b/integ-wget/pom.xml index 6ca9dbd..bcb1c99 100644 --- a/integ-wget/pom.xml +++ b/integ-wget/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.1-SNAPSHOT + 1.0.2-SNAPSHOT integ-wget From 40b6dae6b089b4c821b28403f028e87e196ff6e2 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 17:05:43 +0200 Subject: [PATCH 015/301] assertLogicHappens is now deprecated! --- .../cli/support/LinuxFileInfoExecutionBuilder.java | 2 +- .../il/co/topq/integframework/db/DatabaseSystemModule.java | 5 ++--- .../java/il/co/topq/integframework/assertion/Assert.java | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java index d99d22a..4b6f157 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java @@ -61,7 +61,7 @@ public Long apply(CliCommandExecution input) { long result; input.execute(); LongCompareAssertion compareAssertion = new LongCompareAssertion(expected, compareMethod); - Assert.assertLogicHappens(result = resultType.parser.parse(input.getResult()), compareAssertion, 0l, true); + Assert.assertLogic(result = resultType.parser.parse(input.getResult()), compareAssertion); return result; } catch (Exception e) { throw new RuntimeException(e); diff --git a/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java b/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java index 8e7c3e8..692a08d 100644 --- a/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java +++ b/integ-db/src/main/java/il/co/topq/integframework/db/DatabaseSystemModule.java @@ -95,8 +95,7 @@ public void executeUpdateStatement(final String sql, int expectedNumOfAffectedRo } int rows = template.update(sql); if (expectedNumOfAffectedRows >= 0) { - Assert.assertLogicHappens(rows, - new NumberCompareAssertion(expectedNumOfAffectedRows, CompareMethod.EQUALS), 0l, true); + Assert.assertLogic(rows, new NumberCompareAssertion(expectedNumOfAffectedRows, CompareMethod.EQUALS)); } } @@ -115,7 +114,7 @@ public void executeUpdateStatement(final String sql, int expectedNumOfAffectedRo */ public void assertNumOfRows(final String sql, int expectedNumOfRows, CompareMethod compareMethod) throws Exception { int actual = getResultList(sql).size(); - Assert.assertLogicHappens(actual, new NumberCompareAssertion(expectedNumOfRows, compareMethod), 0l, true); + Assert.assertLogic(actual, new NumberCompareAssertion(expectedNumOfRows, compareMethod)); } public void assertNumOfRows(final String sql, int expectedNumOfRows) throws Exception { diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index 09639eb..adb4de8 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -115,6 +115,7 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< } } + @Deprecated static public void assertLogicHappens(final T actual, final AbstractAssertionLogic logic, final long timeout, boolean silent) throws TimeoutException { From 07a1c2630fe70989478fa54ce2443a269d3b008f Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 17:09:12 +0200 Subject: [PATCH 016/301] parent module relative path fixed --- integ-bdd/pom.xml | 2 +- integ-db/pom.xml | 2 +- integ-hdfs/pom.xml | 4 ++-- integ-jms/pom.xml | 2 +- integ-rest/pom.xml | 2 +- integ-webdriver-archetype/pom.xml | 4 ++-- integ-webdriver/pom.xml | 4 ++-- integ-wget/pom.xml | 3 ++- 8 files changed, 12 insertions(+), 11 deletions(-) diff --git a/integ-bdd/pom.xml b/integ-bdd/pom.xml index f3b5e0c..bc7973a 100644 --- a/integ-bdd/pom.xml +++ b/integ-bdd/pom.xml @@ -11,7 +11,7 @@ il.co.topq.integframework integ-testng - 1.0.1-SNAPSHOT + ${project.version} \ No newline at end of file diff --git a/integ-db/pom.xml b/integ-db/pom.xml index 9b65cef..ede6c26 100644 --- a/integ-db/pom.xml +++ b/integ-db/pom.xml @@ -10,7 +10,7 @@ il.co.topq.integframework integ-testng - 1.0.1-SNAPSHOT + ${project.version} commons-dbcp diff --git a/integ-hdfs/pom.xml b/integ-hdfs/pom.xml index b6ec4b0..c89973c 100644 --- a/integ-hdfs/pom.xml +++ b/integ-hdfs/pom.xml @@ -10,7 +10,7 @@ il.co.topq.integframework integ-testng - 1.0.1-SNAPSHOT + ${project.version} commons-dbcp @@ -32,7 +32,7 @@ il.co.topq.integframework integ-support - 1.0.1-SNAPSHOT + ${project.version} diff --git a/integ-jms/pom.xml b/integ-jms/pom.xml index 37e4886..78f9878 100644 --- a/integ-jms/pom.xml +++ b/integ-jms/pom.xml @@ -15,7 +15,7 @@ il.co.topq.integframework integ-testng - 1.0.1-SNAPSHOT + ${project.version} diff --git a/integ-rest/pom.xml b/integ-rest/pom.xml index 0ac3bad..20e7481 100644 --- a/integ-rest/pom.xml +++ b/integ-rest/pom.xml @@ -4,7 +4,7 @@ il.co.topq.integframework integ-parent 1.0.2-SNAPSHOT - ../../integ/integ-parent + ../integ-parent integ-rest diff --git a/integ-webdriver-archetype/pom.xml b/integ-webdriver-archetype/pom.xml index 55b2d8a..2554532 100644 --- a/integ-webdriver-archetype/pom.xml +++ b/integ-webdriver-archetype/pom.xml @@ -43,10 +43,10 @@ il.co.topq.integframework integ-parent - 1.0.0 + 1.0.2-SNAPSHOT ../integ-parent - 1.0.00-SNAPSHOT + 1.0.2-SNAPSHOT diff --git a/integ-webdriver/pom.xml b/integ-webdriver/pom.xml index 77d7ca3..ef3d104 100644 --- a/integ-webdriver/pom.xml +++ b/integ-webdriver/pom.xml @@ -20,14 +20,14 @@ il.co.topq.integframework integ-testng - 1.0.1-SNAPSHOT + ${project.version} il.co.topq.integframework integ-junit - 1.0.1-SNAPSHOT + ${project.version} com.github.detro.ghostdriver diff --git a/integ-wget/pom.xml b/integ-wget/pom.xml index bcb1c99..bb96303 100644 --- a/integ-wget/pom.xml +++ b/integ-wget/pom.xml @@ -4,13 +4,14 @@ il.co.topq.integframework integ-parent 1.0.2-SNAPSHOT + ../integ-parent integ-wget il.co.topq.integframework integ-cli - 1.0.1-SNAPSHOT + ${project.version} \ No newline at end of file From 45b70d5b7a333e57c4c6b4b1d78c930581d2fef3 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 18:09:07 +0200 Subject: [PATCH 017/301] reports when assertion failed moved to DefaultAssertionListener (because FailSafeAssertionListener should supress them) --- .../java/il/co/topq/integframework/assertion/Assert.java | 6 +++--- .../integframework/assertion/DefaultAssertionListener.java | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index adb4de8..342c534 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -105,12 +105,12 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< if (logic.isStatus()) { listener.assertionPassed(actual, logic); } else { - Reporter.log("Assertion failed: " + logic.getTitle(), - logic.getMessage(), false); + // Reporter.log("Assertion failed: " + logic.getTitle(), + // logic.getMessage(), false); listener.assertionFailed(actual, logic); } } catch (Throwable t) { - Reporter.log("Assertion process failed: ", t); + // Reporter.log("Assertion process failed: ", t); listener.assertionFailed(actual, logic, t); } } diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/DefaultAssertionListener.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/DefaultAssertionListener.java index 951264c..3c6e77f 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/DefaultAssertionListener.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/DefaultAssertionListener.java @@ -1,5 +1,7 @@ package il.co.topq.integframework.assertion; +import il.co.topq.integframework.reporting.Reporter; + public class DefaultAssertionListener implements AssertionListener{ @Override @@ -9,12 +11,14 @@ public void assertionPassed(T actual, AbstractAssertionLogic logic) { @Override public void assertionFailed(T actual, AbstractAssertionLogic logic) { + Reporter.log("Assertion failed: " + logic.getTitle(), logic.getMessage(), false); org.testng.Assert.fail(logic.message); } @Override public void assertionFailed(T actual, AbstractAssertionLogic logic, Throwable t) { + Reporter.log("Assertion process failed: ", t); org.testng.Assert.fail(logic.message, t); } }; \ No newline at end of file From ea99fb1520f4202375bf7443cf3d4f845403874d Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 18:19:12 +0200 Subject: [PATCH 018/301] Fixed conditions of CliExecution --- .../CliExecutionExpectedConditions.java | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index dbd78c5..995d02a 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -2,6 +2,8 @@ import il.co.topq.integframework.assertion.AbstractAssertionLogic; import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.assertion.FailSafeAssertionListener; +import il.co.topq.integframework.assertion.FindTextAssertion; import il.co.topq.integframework.cli.process.CliCommandExecution; public abstract class CliExecutionExpectedConditions { @@ -16,12 +18,17 @@ public static CliExecutionExpectedCondition executionLogicHappens(final @Override public String apply(CliCommandExecution execution) { try { + FailSafeAssertionListener failSafeListener = new FailSafeAssertionListener(); execution.execute(); + Assert.assertLogic(execution.getResult(), logic, failSafeListener); + if (failSafeListener.getSuppressedThrowables().hasNext()) { + Assert.fail("execution failed", failSafeListener.getSuppressedThrowables().next()); + } + return execution.getResult(); } catch (Exception e) { Assert.fail(toString(), e); } - Assert.assertLogic(execution.getResult(), logic); - return execution.getResult(); + return null; } @Override @@ -32,25 +39,53 @@ public String toString() { } - public static CliExecutionExpectedCondition executionResponseReturn(final String mustHaveResponse) { - return new CliExecutionExpectedCondition() { + public static CliExecutionExpectedCondition executionResponseReturn(final String expectedResponse) { + return executionLogicHappens(new FindTextAssertion(expectedResponse) { @Override - public String apply(CliCommandExecution execution) { - try { - execution.mustHaveResponse(mustHaveResponse).execute(); - } catch (Exception e) { - Assert.fail(toString(), e); - } - return execution.getResult(); + public String toString() { + return "execution response must contain " + expectedResponse; + } + }); + // final FindTextAssertion findTextAssertion = new + // FindTextAssertion(mustHaveResponse); + // final FailSafeAssertionListener failSafeListener = new + // FailSafeAssertionListener(); + // return new CliExecutionExpectedCondition() { + // @Override + // public String apply(CliCommandExecution execution) { + // String result; + // try { + // execution.execute(); + // Assert.assertLogic(result = execution.getResult(), findTextAssertion, + // failSafeListener); + // return result; + // } catch (Exception e) { + // Assert.fail(toString(), e); + // } + // return null; + // } + // + // @Override + // public String toString() { + // return "execution must have response with " + mustHaveResponse; + // } + // }; + + } + + public static CliExecutionExpectedCondition executionResponseReturnExactly(final String expectedResponse) { + return executionLogicHappens(new AbstractAssertionLogic() { + + @Override + public void doAssertion() { + this.status = this.actual.equals(expectedResponse); } @Override public String toString() { - return "execution must have response of " + mustHaveResponse; + return "execution response must be " + expectedResponse; } - }; - + }); } - } From b55e49f2351728147591bcf25ad4832c6612593c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Feb 2014 18:37:51 +0200 Subject: [PATCH 019/301] new generic expected condition --- .../CliExecutionExpectedConditions.java | 39 +++++++++++++++++++ .../integframework/cli/support/Parser.java | 5 +++ 2 files changed, 44 insertions(+) create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 995d02a..8362c27 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -88,4 +88,43 @@ public String toString() { }); } + /** + * this condition will return the return value of cli execution, after + * parsed by a parser and analyzed by the assertion logic + * + * @param T + * the type of the value the execution response. e.g. execution + * of wc -l file returns java.lang.Long + * meaning the amount of lines in the file + * @param parser + * an object that gets the string from the execution and + * translates it to a T.
+ * a parser should be aware of all fields in the result. + * @param logic + * the logic and sometimes the expected value to examine. + * @return the parsed value + */ + public static CliExecutionExpectedCondition executionLogicHappens(final AbstractAssertionLogic logic, + final Parser parser) { + return new CliExecutionExpectedCondition() { + + @Override + public T apply(CliCommandExecution execution) { + try { + FailSafeAssertionListener failSafeListener = new FailSafeAssertionListener(); + execution.execute(); + T actual = parser.parse(execution.getResult()); + Assert.assertLogic(actual, logic, failSafeListener); + if (failSafeListener.getSuppressedThrowables().hasNext()) { + Assert.fail("execution failed", failSafeListener.getSuppressedThrowables().next()); + } + return actual; + } catch (Exception e) { + Assert.fail(toString(), e); + } + return null; + } + }; + + } } diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java new file mode 100644 index 0000000..b1a7e02 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java @@ -0,0 +1,5 @@ +package il.co.topq.integframework.cli.support; + +public interface Parser { + T parse(String source); +} From 29080760302466514c517e25243feeaf1c6c188c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 14:32:37 +0200 Subject: [PATCH 020/301] wget client can post a file now --- .../il/co/topq/integframework/WgetClient.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java index 836ccf5..7950ec3 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -1,12 +1,17 @@ package il.co.topq.integframework; +import il.co.topq.integframework.cli.conn.LinuxDefaultCliConnection; + +import java.io.ByteArrayInputStream; +import java.io.OutputStream; + +import org.apache.commons.io.IOUtils; public class WgetClient { final String userAgent, ip; private final WgetModule module; - public WgetClient(WgetModule module, String ip, String userAgent) { this.module = module; this.ip = ip; @@ -26,6 +31,23 @@ module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadA .execute(); } + public void postFile(String remoteFile) throws Exception { + module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().postFile(remoteFile) + .error("failed").execute(); + } + + public void post(byte[] data, String remoteDir, String remoteFile) throws Exception { + LinuxDefaultCliConnection linux = null; + if (module.getCliConnectionImpl() instanceof LinuxDefaultCliConnection) { + linux = (LinuxDefaultCliConnection) module.getCliConnectionImpl(); + } + OutputStream put = linux.put(remoteDir, remoteFile, null, data.length); + IOUtils.copy(new ByteArrayInputStream(data), put); + IOUtils.closeQuietly(put); + + postFile(remoteDir + "/" + remoteFile); + } + public void bindAddress() throws Exception { module.new AddIpCommand(ip).execute(); } From ebceb0afd07f1935f0e00d689510feaf4aa822d1 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 14:34:13 +0200 Subject: [PATCH 021/301] safe changes to wgetr command --- .../il/co/topq/integframework/WgetModule.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java index 87560e7..e140698 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java @@ -35,13 +35,23 @@ public DeleteIpCommand(String ipAddress) { public class WgetCommand extends CliCommandExecution { private final StringBuilder command = new StringBuilder("wget"); - + private boolean userAgentSet = false, downloadSet = false, bindAddressSet = false, referrerSet = false, + postDataSet = false, + alreadyRun = false; public WgetCommand() { super(getCliConnectionImpl()); withTitle("wget"); } + private boolean setFlag(boolean flag, String exceptionString) { + if (flag) { + throw new IllegalStateException(exceptionString); + } + return true; + } + public WgetCommand withUserAgent(String userAgent) { + userAgentSet = setFlag(userAgentSet, "User agent" + " already set!"); command.append(" --user-agent='").append(userAgent).append("' "); return this; } @@ -51,27 +61,38 @@ public WgetCommand doNotDownloadAnything() { } public WgetCommand downloadTo(String target) { + downloadSet = setFlag(downloadSet, "Download target" + " already set!"); command.append("-O ").append(target); return this; } public WgetCommand bindAddress(String address) { + bindAddressSet = setFlag(bindAddressSet, "Bind address" + " already set!"); command.append(" --bind-address=").append(address); return this; } public WgetCommand referer(URL url) { + referrerSet = setFlag(referrerSet, "Referrer" + " already set!"); command.append(" --referer='").append(url).append("' "); return this; } public WgetCommand post(CharSequence data) { + postDataSet = setFlag(postDataSet, "Post data" + " already set!"); command.append(" --post-data=\'").append(data).append('\''); return this; } + public WgetCommand postFile(String name) { + postDataSet = setFlag(postDataSet, "Post data" + " already set!"); + command.append(" --post-file=\'").append(name).append('\''); + return this; + } + @Override public void execute() throws Exception { + alreadyRun = setFlag(alreadyRun, "A client can execute only once!"); if (StringUtils.isEmpty(cmd)) { cmd = command.append(' ').append(url).toString(); } From 39c8c60cdf5c7b94b8815e766292c541530f27af Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 14:34:48 +0200 Subject: [PATCH 022/301] toString returns more meaningful result --- .../assertion/CompareMethod.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java index 4ece0c3..37d0bdd 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java @@ -1,6 +1,22 @@ package il.co.topq.integframework.assertion; public enum CompareMethod { - BIGGER, BIGGER_OR_EQUALS, EQUALS, SMALLER_OR_EQUALS, SMALLER + BIGGER, BIGGER_OR_EQUALS, EQUALS, SMALLER_OR_EQUALS, SMALLER; + public String toString() { + switch (this) { + case BIGGER: + return "bigger then"; + case BIGGER_OR_EQUALS: + return "bigger then or equals to"; + case EQUALS: + return "equals to"; + case SMALLER_OR_EQUALS: + return "smaller then or equals to"; + case SMALLER: + return "smaller then"; + default: + return null; + } + }; } \ No newline at end of file From 073173e286bcf72a322f615dee3b3d5699690fb1 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 14:35:22 +0200 Subject: [PATCH 023/301] Parser.parse throws ParseException --- .../java/il/co/topq/integframework/cli/support/Parser.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java index b1a7e02..4be47f6 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java @@ -1,5 +1,7 @@ package il.co.topq.integframework.cli.support; +import java.text.ParseException; + public interface Parser { - T parse(String source); + T parse(String source) throws ParseException; } From f32f8025cb758ff202ed23209121e8ab115d251c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 17:47:29 +0200 Subject: [PATCH 024/301] Compare method now compares comparables --- .../assertion/ComparableAssertion.java | 70 +++---------------- .../assertion/CompareMethod.java | 33 ++++++++- 2 files changed, 41 insertions(+), 62 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java index e92c3dd..a4f7979 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java @@ -4,8 +4,6 @@ public class ComparableAssertion> extends AbstractAssert private final T expected; - private T actualObject; - private final CompareMethod compareMethod; public ComparableAssertion(T expected, CompareMethod compareMethod) { @@ -14,68 +12,18 @@ public ComparableAssertion(T expected, CompareMethod compareMethod) { this.compareMethod = compareMethod; } - @Override - public void doAssertion() { - status = true; - switch (compareMethod) { - case BIGGER: - if (actualObject.compareTo(expected) > 0) { - title = "Actual [" + actualObject + "] is bigger then " + expected; - } else { - title = "Actual [" + actualObject + "] is NOT bigger then " + expected; - status = false; - } - break; - case BIGGER_OR_EQUALS: - if (actualObject.compareTo(expected) >= 0) { - title = "Actual [" + actualObject + "] is bigger or equals to " + expected; - } else { - title = "Actual [" + actualObject + "] is NOT bigger or equals to " + expected; - status = false; - } - - break; - case EQUALS: - if (actualObject.compareTo(expected) == 0) { - title = "Actual [" + actualObject + "] is equals to " + expected; - } else { - title = "Actual [" + actualObject + "] is NOT equals to " + expected; - status = false; - } - break; - - case SMALLER_OR_EQUALS: - if (actualObject.compareTo(expected) <= 0) { - title = "Actual [" + actualObject + "] is smaller or equals to " + expected; - } else { - title = "Actual [" + actualObject + "] is NOT smaller or equals to " + expected; - status = false; - } - break; - case SMALLER: - if (actualObject.compareTo(expected) < 0) { - title = "Actual [" + actualObject + "] is smaller then " + expected; - } else { - title = "Actual [" + actualObject + "] is NOT smaller then " + expected; - status = false; - } - break; - - default: - break; - } - + public ComparableAssertion(CompareMethod compareMethod, T expected) { + this(expected, compareMethod); } - - - /** - * Sets the actual object to perfrom assertion on - */ @Override - public void setActual(T actual) { - if (actual != null) { - actualObject = actual; + public void doAssertion() { + status = compareMethod.compare(actual, expected); + StringBuilder titleBuilder = new StringBuilder(); + titleBuilder.append("Actual [").append(actual).append("] is "); + if (!status) { + titleBuilder.append("NOT "); } + titleBuilder.append(compareMethod.toString()).append(" [").append(expected).append("]"); } } diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java index 37d0bdd..8297f65 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CompareMethod.java @@ -1,7 +1,36 @@ package il.co.topq.integframework.assertion; public enum CompareMethod { - BIGGER, BIGGER_OR_EQUALS, EQUALS, SMALLER_OR_EQUALS, SMALLER; + BIGGER { + @Override + public > boolean compare(T o1, T o2) { + return o1.compareTo(o2) > 0; + } + }, + BIGGER_OR_EQUALS { + @Override + public > boolean compare(T o1, T o2) { + return o1.compareTo(o2) >= 0; + } + }, + EQUALS { + @Override + public > boolean compare(T o1, T o2) { + return o1.compareTo(o2) == 0; + } + }, + SMALLER_OR_EQUALS { + @Override + public > boolean compare(T o1, T o2) { + return o1.compareTo(o2) <= 0; + } + }, + SMALLER { + @Override + public > boolean compare(T o1, T o2) { + return o1.compareTo(o2) < 0; + } + }; public String toString() { switch (this) { case BIGGER: @@ -19,4 +48,6 @@ public String toString() { } }; + + public abstract > boolean compare(T o1, T o2); } \ No newline at end of file From c0470126409d14c851b27347065dc655af483545 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 18:16:15 +0200 Subject: [PATCH 025/301] the fiels actual is inherited from AbstractAssertionLogic --- .../assertion/FindTextAssertion.java | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java index 864b168..9ae70b0 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java @@ -13,8 +13,6 @@ public class FindTextAssertion extends AbstractAssertionLogic { private final String expectedText; - private String actualText; - private final boolean isRegex; /** @@ -37,7 +35,7 @@ public FindTextAssertion(String expectedText) { @Override public void doAssertion() { - if (actualText == null) { + if (actual == null) { status = false; title = "Actual text can't be null"; return; @@ -51,7 +49,7 @@ public void doAssertion() { if (isRegex) { try { Pattern pattern = Pattern.compile(expectedText); - Matcher matcher = pattern.matcher(actualText); + Matcher matcher = pattern.matcher(actual); status = matcher.find(); } catch (Throwable t) { @@ -59,7 +57,7 @@ public void doAssertion() { } } else { - status = actualText.contains(expectedText); + status = actual.contains(expectedText); } if (status) { title = "Expected text was found in actual text"; @@ -70,19 +68,8 @@ public void doAssertion() { messageBuilder.append("Text to find: \n"); messageBuilder.append(expectedText).append("\n\n"); messageBuilder.append("Actual text\n"); - messageBuilder.append(actualText); + messageBuilder.append(actual); message = messageBuilder.toString(); } - - - - @Override - public void setActual(String actual) { - this.actual = actual; - if (actual != null) { - actualText = (String) actual; - } - } - } From 4a4b8e0b6a160bf4a57e60b5a14ae257f50c2173 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 18:18:04 +0200 Subject: [PATCH 026/301] oops: getRandomItemFrom can throw ArrayIndexOutOfBoundsException when the random int goes to the maximum --- .../main/java/il/co/topq/integframework/utils/RandomUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java index 5b73c21..986e021 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/RandomUtils.java @@ -237,7 +237,7 @@ public static Object[] randomizeGroup(Object[] originalGroup, Random random) { } public static E getRandomItemFrom(Collection collection) { - return new ArrayList(collection).get(getRandomInt(0, collection.size(), new Random())); + return new ArrayList(collection).get(getRandomInt(0, collection.size() - 1, new Random())); } From da68be3e70ba823af903d7339d9c1167a338afd8 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 18:19:06 +0200 Subject: [PATCH 027/301] new method: LinuxFileContentExecutionBuilder.notContainingText --- .../LinuxFileContentExecutionBuilder.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java index 5336097..969feeb 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java @@ -52,4 +52,21 @@ public String apply(CliCommandExecution input) { }; } + + public CliExecutionExpectedCondition notContainingText(final String expected) { + + return new CliExecutionExpectedCondition() { + + @Override + public String apply(CliCommandExecution input) { + try { + input.error(expected).execute(); + } catch (Exception e) { + Assert.fail("execution failed", e); + } + return input.getResult(); + } + }; + + } } From dade2792523c4710f93becd8cc623d8da21478e0 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 18:29:57 +0200 Subject: [PATCH 028/301] 1. toString for more informative condition 2. format ----"---- 3. using ComparableAssertion for fun --- .../LinuxFileInfoExecutionBuilder.java | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java index 4b6f157..5d3fda2 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java @@ -1,8 +1,8 @@ package il.co.topq.integframework.cli.support; -import il.co.topq.integframework.assertion.Assert; +import static il.co.topq.integframework.assertion.Assert.assertLogic; +import il.co.topq.integframework.assertion.ComparableAssertion; import il.co.topq.integframework.assertion.CompareMethod; -import il.co.topq.integframework.assertion.LongCompareAssertion; import il.co.topq.integframework.cli.conn.CliConnection; import il.co.topq.integframework.cli.process.CliCommandExecution; @@ -51,17 +51,24 @@ public CliExecutionExpectedCondition fileSizeToBe(CompareMethod compareMet return execute(resultType, expectedSize, compareMethod); } - private static CliExecutionExpectedCondition execute(final ResultType resultType, final long expected, + private CliExecutionExpectedCondition execute(final ResultType resultType, final long expected, final CompareMethod compareMethod) { return new CliExecutionExpectedCondition() { - + @Override + public String toString() { + StringBuilder builder = new StringBuilder("the file "); + builder.append(name).append(" "); + builder.append(resultType.name()).append(" to be "); + builder.append(compareMethod.toString()).append(" ").append(resultType.format(expected)); + return builder.toString(); + } @Override public Long apply(CliCommandExecution input) { try { long result; input.execute(); - LongCompareAssertion compareAssertion = new LongCompareAssertion(expected, compareMethod); - Assert.assertLogic(result = resultType.parser.parse(input.getResult()), compareAssertion); + assertLogic(result = resultType.parser.parse(input.getResult()), new ComparableAssertion(expected, + compareMethod)); return result; } catch (Exception e) { throw new RuntimeException(e); @@ -71,17 +78,23 @@ public Long apply(CliCommandExecution input) { }; } + private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); + public enum ResultType { FileDate("$6,$7,$8", new Parser() { - private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); - @Override public Long parse(String s) throws ParseException { Date actual = dateFormat.parse(s); return actual.getTime(); } - }), + }) { + @Override + String format(long l) { + return dateFormat.format(l); + } + + }, FileSize("$5", new Parser() { @Override @@ -89,20 +102,22 @@ public Long parse(String s) { long actual = Long.parseLong(s); return actual; } - }); + }) { + @Override + String format(long l) { + return Long.toString(l); + } + }; final String awkPrint; - final Parser parser; + final Parser parser; - ResultType(final String awkPrint, final Parser parser) { + ResultType(final String awkPrint, final Parser parser) { this.awkPrint = awkPrint; this.parser = parser; } - private interface Parser> { - - Long parse(String result) throws ParseException; - } + abstract String format(long l); } } From 17ac65eb7aed0a08d9e8b55a56749d4f072012b7 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 26 Feb 2014 18:44:31 +0200 Subject: [PATCH 029/301] cleanup code --- .../CliExecutionExpectedConditions.java | 35 ++----------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 8362c27..8842b07 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -2,6 +2,8 @@ import il.co.topq.integframework.assertion.AbstractAssertionLogic; import il.co.topq.integframework.assertion.Assert; +import il.co.topq.integframework.assertion.ComparableAssertion; +import il.co.topq.integframework.assertion.CompareMethod; import il.co.topq.integframework.assertion.FailSafeAssertionListener; import il.co.topq.integframework.assertion.FindTextAssertion; import il.co.topq.integframework.cli.process.CliCommandExecution; @@ -46,41 +48,10 @@ public String toString() { return "execution response must contain " + expectedResponse; } }); - // final FindTextAssertion findTextAssertion = new - // FindTextAssertion(mustHaveResponse); - // final FailSafeAssertionListener failSafeListener = new - // FailSafeAssertionListener(); - // return new CliExecutionExpectedCondition() { - // @Override - // public String apply(CliCommandExecution execution) { - // String result; - // try { - // execution.execute(); - // Assert.assertLogic(result = execution.getResult(), findTextAssertion, - // failSafeListener); - // return result; - // } catch (Exception e) { - // Assert.fail(toString(), e); - // } - // return null; - // } - // - // @Override - // public String toString() { - // return "execution must have response with " + mustHaveResponse; - // } - // }; - } public static CliExecutionExpectedCondition executionResponseReturnExactly(final String expectedResponse) { - return executionLogicHappens(new AbstractAssertionLogic() { - - @Override - public void doAssertion() { - this.status = this.actual.equals(expectedResponse); - } - + return executionLogicHappens(new ComparableAssertion(expectedResponse, CompareMethod.EQUALS) { @Override public String toString() { return "execution response must be " + expectedResponse; From f9345b4830f86474cd1e314e56973d0d5606dad7 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 10:31:23 +0200 Subject: [PATCH 030/301] Parser and formatter: new utils in integ-testng --- .../topq/integframework/cli/support/Parser.java | 7 ------- .../co/topq/integframework/utils/Formatter.java | 13 +++++++++++++ .../topq/integframework/utils/FormatterImpl.java | 10 ++++++++++ .../il/co/topq/integframework/utils/Parser.java | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) delete mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/utils/Formatter.java create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/utils/FormatterImpl.java create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/utils/Parser.java diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java deleted file mode 100644 index 4be47f6..0000000 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/Parser.java +++ /dev/null @@ -1,7 +0,0 @@ -package il.co.topq.integframework.cli.support; - -import java.text.ParseException; - -public interface Parser { - T parse(String source) throws ParseException; -} diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/Formatter.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/Formatter.java new file mode 100644 index 0000000..fd7a19b --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/Formatter.java @@ -0,0 +1,13 @@ +package il.co.topq.integframework.utils; + +/** + * A formatter of T returns a string representation of the T object. + * + * @author Aharon + * + * @param + * the type of object to be formatted + */ +public interface Formatter { + public String toString(T t); +} diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/FormatterImpl.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/FormatterImpl.java new file mode 100644 index 0000000..a6ac8ac --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/FormatterImpl.java @@ -0,0 +1,10 @@ +package il.co.topq.integframework.utils; + +public class FormatterImpl implements Formatter { + + @Override + public String toString(T t) { + return t.toString(); + } + +} diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/Parser.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parser.java new file mode 100644 index 0000000..b7c8a95 --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parser.java @@ -0,0 +1,15 @@ +package il.co.topq.integframework.utils; + +import java.text.ParseException; + +/** + * A parser of T parses a string representation of a T object and returns it. + * + * @author Aharon + * + * @param + * the type of object to be parsed + */ +public interface Parser { + T parse(String source) throws ParseException; +} From f48dd9ad0fabf31760bb17ac2f35ad4665f98d8f Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 10:36:13 +0200 Subject: [PATCH 031/301] typo --- .../il/co/topq/integframework/assertion/FindTextAssertion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java index 9ae70b0..be53d4d 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/FindTextAssertion.java @@ -6,7 +6,7 @@ /** * Asserts that given text exists in an actual text * - * @author Ita Agmon + * @author Itai Agmon * */ public class FindTextAssertion extends AbstractAssertionLogic { From 74d91c7704ce4c1bda2ffa2f74a3b72526ba76ce Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 10:36:53 +0200 Subject: [PATCH 032/301] parser refactored --- .../cli/support/CliExecutionExpectedConditions.java | 1 + 1 file changed, 1 insertion(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 8842b07..1a9fd8d 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -7,6 +7,7 @@ import il.co.topq.integframework.assertion.FailSafeAssertionListener; import il.co.topq.integframework.assertion.FindTextAssertion; import il.co.topq.integframework.cli.process.CliCommandExecution; +import il.co.topq.integframework.utils.Parser; public abstract class CliExecutionExpectedConditions { final Object __; From d288dcbbc83e769a36cc1d20307719f61c0c3eae Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 10:40:21 +0200 Subject: [PATCH 033/301] textual enhancements --- .../LinuxFileInfoExecutionBuilder.java | 52 ++++++++----------- .../assertion/ComparableAssertion.java | 30 ++++++++++- 2 files changed, 51 insertions(+), 31 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java index 5d3fda2..bb160b8 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java @@ -1,10 +1,12 @@ package il.co.topq.integframework.cli.support; -import static il.co.topq.integframework.assertion.Assert.assertLogic; +import static il.co.topq.integframework.cli.support.CliExecutionExpectedConditions.executionLogicHappens; import il.co.topq.integframework.assertion.ComparableAssertion; import il.co.topq.integframework.assertion.CompareMethod; import il.co.topq.integframework.cli.conn.CliConnection; import il.co.topq.integframework.cli.process.CliCommandExecution; +import il.co.topq.integframework.utils.Formatter; +import il.co.topq.integframework.utils.Parser; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -53,34 +55,20 @@ public CliExecutionExpectedCondition fileSizeToBe(CompareMethod compareMet private CliExecutionExpectedCondition execute(final ResultType resultType, final long expected, final CompareMethod compareMethod) { - return new CliExecutionExpectedCondition() { - @Override - public String toString() { - StringBuilder builder = new StringBuilder("the file "); - builder.append(name).append(" "); - builder.append(resultType.name()).append(" to be "); - builder.append(compareMethod.toString()).append(" ").append(resultType.format(expected)); - return builder.toString(); - } - @Override - public Long apply(CliCommandExecution input) { - try { - long result; - input.execute(); - assertLogic(result = resultType.parser.parse(input.getResult()), new ComparableAssertion(expected, - compareMethod)); - return result; - } catch (Exception e) { - throw new RuntimeException(e); - } + StringBuilder examinedObjectName = new StringBuilder("file "); + examinedObjectName.append(name).append(" "); + examinedObjectName.append(resultType.name()); + return executionLogicHappens( + new ComparableAssertion(compareMethod, expected).examinedObjectTitled(examinedObjectName.toString()) + .formatObjectWith(resultType) + + , resultType.parser); - } - }; } private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z"); - public enum ResultType { + public enum ResultType implements Formatter { FileDate("$6,$7,$8", new Parser() { @Override public Long parse(String s) throws ParseException { @@ -90,10 +78,14 @@ public Long parse(String s) throws ParseException { }) { @Override - String format(long l) { + public String toString(Long l) { return dateFormat.format(l); } + @Override + public String toString() { + return "date"; + } }, FileSize("$5", new Parser() { @@ -104,9 +96,14 @@ public Long parse(String s) { } }) { @Override - String format(long l) { + public String toString(Long l) { return Long.toString(l); } + + @Override + public String toString() { + return "size"; + } }; final String awkPrint; @@ -116,8 +113,5 @@ String format(long l) { this.awkPrint = awkPrint; this.parser = parser; } - - abstract String format(long l); } - } diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java index a4f7979..0e813eb 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java @@ -1,9 +1,15 @@ package il.co.topq.integframework.assertion; +import il.co.topq.integframework.utils.Formatter; +import il.co.topq.integframework.utils.FormatterImpl; + public class ComparableAssertion> extends AbstractAssertionLogic { private final T expected; + private String titleOfExaminedObject = ""; + private Formatter formatter = new FormatterImpl<>(); + private final CompareMethod compareMethod; public ComparableAssertion(T expected, CompareMethod compareMethod) { @@ -15,15 +21,35 @@ public ComparableAssertion(T expected, CompareMethod compareMethod) { public ComparableAssertion(CompareMethod compareMethod, T expected) { this(expected, compareMethod); } + + public ComparableAssertion examinedObjectTitled(String title) { + this.titleOfExaminedObject = title; + return this; + + } + + public ComparableAssertion formatObjectWith(Formatter formatter) { + this.formatter = formatter; + return this; + } + @Override public void doAssertion() { status = compareMethod.compare(actual, expected); StringBuilder titleBuilder = new StringBuilder(); - titleBuilder.append("Actual [").append(actual).append("] is "); + titleBuilder.append("Actual ").append(titleOfExaminedObject).append(" [").append(formatter.toString(actual)) + .append("] is "); if (!status) { titleBuilder.append("NOT "); } - titleBuilder.append(compareMethod.toString()).append(" [").append(expected).append("]"); + titleBuilder.append(compareMethod.toString()).append(" [").append(formatter.toString(expected)).append("]"); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(this.titleOfExaminedObject).append(" to be "); + builder.append(compareMethod.toString()).append(" ").append(formatter.toString(expected)); + return builder.toString(); } } From 6228c41e60eb2ab10870a2bb4bf070fa00071cf0 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 10:48:22 +0200 Subject: [PATCH 034/301] name is a property of a module! --- .../il/co/topq/integframework/AbstractModuleImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/AbstractModuleImpl.java b/integ-testng/src/main/java/il/co/topq/integframework/AbstractModuleImpl.java index 3f52f10..377d6b5 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/AbstractModuleImpl.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/AbstractModuleImpl.java @@ -9,4 +9,13 @@ public void init() throws Exception { public void close() throws Exception { } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } From 74f2bb2e344cab3e3cfdca341b435f80e4d5487a Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 11:33:39 +0200 Subject: [PATCH 035/301] JDOcs --- .../support/LinuxCliExpectedConditions.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java index c15daa5..3217fd2 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java @@ -18,6 +18,13 @@ private LinuxCliExpectedConditions() { _ = 1; } + /** + * an expectation of existence of a file. + * + * @param path + * the file path to find + * @return true if the file exists + */ public static Predicate fileExists(final String path) { return new Predicate() { @@ -42,6 +49,13 @@ public boolean apply(LinuxDefaultCliConnection cliConnection) { }; } + /** + * expectation for a file to be readable. + * + * @param path + * the file path to find + * @return an input stream to the file + */ public static CliExpectedCondition fileIsReadable(final String path) { return new CliExpectedCondition() { @@ -73,6 +87,15 @@ public InputStream apply(CliConnection input) { }; } + /** + * an expectation for a directory to contain a file + * + * @param directory + * the path of the directory to find the file in + * @param file + * the exact name of the file to find in the folder + * @return the filename + */ public static CliExpectedCondition directoryConatins(final String directory, final String file) { return new CliExpectedCondition() { @Override @@ -166,6 +189,14 @@ public String apply(LinuxDefaultCliConnection linux) { }; } + /** + * an expectation for a process to be running + * + * @param processName + * the name of the process (the name of the binary executable) + * @return true if the process is running + * @see man ps + */ public static CliExpectedCondition processIsRunning(final String processName) { return new CliExpectedCondition() { @@ -193,6 +224,16 @@ public Boolean apply(LinuxDefaultCliConnection linux) throws Exception { }; } + /** + * an expectation for a process not to be running, i.e that the machine does + * not run a process with this name + * + * @param processName + * the name of the process (the name of the binary executable) + * @return true if there is no process running with the given name + * @see man ps + */ + public static CliExpectedCondition processIsNotRunning(final String processName) { return new CliExpectedCondition() { From 6cd2c6c0b3613d148707cded8700a12a036ef43b Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 12:35:16 +0200 Subject: [PATCH 036/301] jdocs --- .../cli/support/CliExecutionExpectedConditions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 1a9fd8d..38919f2 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -71,7 +71,7 @@ public String toString() { * @param parser * an object that gets the string from the execution and * translates it to a T.
- * a parser should be aware of all fields in the result. + * the parser should be able to crop the result. * @param logic * the logic and sometimes the expected value to examine. * @return the parsed value From ac12e67cd18054eba964ffdc67ca5c59b6ca053e Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 27 Feb 2014 12:35:28 +0200 Subject: [PATCH 037/301] tostring --- .../cli/support/LinuxFileContentExecutionBuilder.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java index 969feeb..900b27c 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileContentExecutionBuilder.java @@ -37,8 +37,11 @@ public CliCommandExecution build() { } public CliExecutionExpectedCondition containingText(final String expected) { - return new CliExecutionExpectedCondition() { + @Override + public String toString() { + return "the file " + name + " to contain [" + expected + "]"; + } @Override public String apply(CliCommandExecution input) { @@ -56,6 +59,10 @@ public String apply(CliCommandExecution input) { public CliExecutionExpectedCondition notContainingText(final String expected) { return new CliExecutionExpectedCondition() { + @Override + public String toString() { + return "the file " + name + " not to contain [" + expected + "]"; + } @Override public String apply(CliCommandExecution input) { From 65f1f471d62b8a36d43323edda3b5b404380f8bf Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 14:36:32 +0200 Subject: [PATCH 038/301] silently execute commands for loops --- .../integframework/cli/process/CliCommandExecution.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java index 770d3e4..4dcf1b6 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/CliCommandExecution.java @@ -21,6 +21,7 @@ public class CliCommandExecution { protected String cmd = ""; private List musts, errors; protected String result; + private boolean silently = false; protected final List> assrtions; public CliCommandExecution(CliConnection cliConnection) { @@ -78,6 +79,7 @@ public void execute() throws Exception { } } cliCommand.setTimeout(timeout); + cliCommand.setSilent(silently); this.cliConnection.handleCliCommand(title, cliCommand); if (cliConnection instanceof AbstractModule) { @@ -138,4 +140,9 @@ public CliCommandExecution error(String... errors) { this.errors.addAll(Arrays.asList(errors)); return this; } + + public CliCommandExecution silently() { + this.silently = true; + return this; + } } From 2f45bd54ec4f2d183800311143163e8356bcc4be Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 14:36:59 +0200 Subject: [PATCH 039/301] wget can work silently --- .../main/java/il/co/topq/integframework/WgetClient.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java index 7950ec3..01c9481 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -31,6 +31,11 @@ module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadA .execute(); } + public void silentlyPost(CharSequence data) throws Exception { + module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(data).error("failed") + .silently().execute(); + + } public void postFile(String remoteFile) throws Exception { module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().postFile(remoteFile) .error("failed").execute(); @@ -48,6 +53,7 @@ public void post(byte[] data, String remoteDir, String remoteFile) throws Except postFile(remoteDir + "/" + remoteFile); } + public void bindAddress() throws Exception { module.new AddIpCommand(ip).execute(); } @@ -98,4 +104,5 @@ public String toString() { return builder.toString(); } + } From 1929c2708b80e77ccb846e99d616d5d34f7acb58 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 14:37:59 +0200 Subject: [PATCH 040/301] ooops missed executionLogicHappens.toString() method (delegation to logic's toString()) --- .../cli/support/CliExecutionExpectedConditions.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 38919f2..465ebcf 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -96,6 +96,11 @@ public T apply(CliCommandExecution execution) { } return null; } + + @Override + public String toString() { + return logic.toString(); + } }; } From c1c5cf330ca44f0843b2e00924de1837f3f8806b Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 14:38:56 +0200 Subject: [PATCH 041/301] 1. titleOfExaminedObject - default value is now "value" 2. doAssertion now sets this.title to the result title --- .../co/topq/integframework/assertion/ComparableAssertion.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java index 0e813eb..5078598 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/ComparableAssertion.java @@ -7,7 +7,7 @@ public class ComparableAssertion> extends AbstractAssert private final T expected; - private String titleOfExaminedObject = ""; + private String titleOfExaminedObject = "value"; private Formatter formatter = new FormatterImpl<>(); private final CompareMethod compareMethod; @@ -43,6 +43,7 @@ public void doAssertion() { titleBuilder.append("NOT "); } titleBuilder.append(compareMethod.toString()).append(" [").append(formatter.toString(expected)).append("]"); + this.title = titleBuilder.toString(); } @Override From f72caacaac468aaa5393723e543f6a9e27a327df Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 18:33:26 +0200 Subject: [PATCH 042/301] getParser is now public --- .../cli/support/LinuxFileInfoExecutionBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java index bb160b8..32e260f 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxFileInfoExecutionBuilder.java @@ -113,5 +113,9 @@ public String toString() { this.awkPrint = awkPrint; this.parser = parser; } + + public Parser getParser() { + return parser; + } } } From c7f3eb0972d5b03e234ad9ce604144670c833bd0 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Sun, 2 Mar 2014 19:11:58 +0200 Subject: [PATCH 043/301] repeating assert as long as the logic is successful --- .../topq/integframework/assertion/Assert.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index 342c534..4839862 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -3,8 +3,11 @@ import il.co.topq.integframework.reporting.Reporter; import il.co.topq.integframework.reporting.Reporter.Color; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import com.google.common.base.Function; + /** * Class for comparing between actual and expected states * @@ -115,6 +118,48 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< } } + /** + * Execute the logic and repeating on the the + * actual object, as gained from the actualValueGenerator + * + * @param + * the type of actual to examine + * @param + * the type of the resource to gain the actual value from + * @param resource + * a {@link il.co.topq.integframework.Module} or another kind of + * external {@link Object}, from which the actual value is + * gained. + * @param actualValueGenerator + * a function from the resource above to the actual value- on + * which to perform assertion on + * @param logic + * Logic to operate on the actual object + * @param timeout + * maximum time for this operation + * @param timeoutUnit + * time unit for the parameter above + * @param interval + * time to sleep between assertions + * @param intervalUnit + * time unit for the parameter above + * @throws AssertionError + * If assertion fails + */ + static public void assertLogic(R resource, final Function actualValueGenerator, + AbstractAssertionLogic logic, long timeout, TimeUnit timeoutUnit, long interval, TimeUnit intervalUnit) + throws InterruptedException { + long end = System.currentTimeMillis() + timeoutUnit.toMillis(timeout); + while (true) { + Assert.assertLogic(actualValueGenerator.apply(resource), logic); + Thread.sleep(intervalUnit.toMillis(interval)); + if (end > System.currentTimeMillis()) { + return; + } + } + + } + @Deprecated static public void assertLogicHappens(final T actual, final AbstractAssertionLogic logic, final long timeout, From b7b04a22441c0864ed64fa741e3ee81fbfa59927 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:05:28 +0200 Subject: [PATCH 044/301] javadocs --- .../assertion/AssertionListener.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/AssertionListener.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/AssertionListener.java index 2a3fa5f..deff26b 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/AssertionListener.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/AssertionListener.java @@ -1,7 +1,23 @@ package il.co.topq.integframework.assertion; +/** + * + * Listen to assertion pseodo-events: + *
    + *
  1. pass
  2. + *
  3. fail
  4. + *
  5. exception thrown
  6. + *
+ * + * @author Aharon Hacmon + * + * @param + * the type of actual. you may get it's value + */ public interface AssertionListener { public void assertionPassed(final T actual, final AbstractAssertionLogic logic); + public void assertionFailed(final T actual, final AbstractAssertionLogic logic); + public void assertionFailed(final T actual, final AbstractAssertionLogic logic, Throwable t); } \ No newline at end of file From be4281d8a92d4c0bffc9a21d763c84610a1a3b28 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:06:30 +0200 Subject: [PATCH 045/301] repeated execution of assertion with assertion listener --- .../topq/integframework/assertion/Assert.java | 105 ++++++++++++++---- 1 file changed, 86 insertions(+), 19 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java index 4839862..c5cffc7 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/Assert.java @@ -44,11 +44,17 @@ static public void assertStringContains(final String actual, final String expect * If exception occurced during assertion * @throws AssertionError * If assertion fails + * @deprecated actual value is set only once, loop has no meaning!
+ * use + * {@link #assertLogic(Object, Function, AbstractAssertionLogic, long, TimeUnit, long, TimeUnit)} + * instead */ - static public void assertLogic(final T actual, final AbstractAssertionLogic logic, final long timeout) throws TimeoutException { + @Deprecated + static public void assertLogic(final T actual, final AbstractAssertionLogic logic, final long timeout) + throws TimeoutException { long timeUp = System.currentTimeMillis() + timeout; do { - assertLogic(actual, logic,null); + assertLogic(actual, logic, null); if (!logic.status) { try { Thread.sleep(3000); @@ -61,7 +67,7 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< throw new TimeoutException("Assertion failed"); } } - + /** * Execute the logic on the the actual object. * @@ -72,11 +78,9 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< * @throws AssertionError * If assertion fails */ - static public void assertLogic(final T actual, - final AbstractAssertionLogic logic) { + static public void assertLogic(final T actual, final AbstractAssertionLogic logic) { assertLogic(actual, logic, null); } - /** * Execute the logic on the the actual object. @@ -120,7 +124,56 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< /** * Execute the logic and repeating on the the - * actual object, as gained from the actualValueGenerator + * actual object, as gained from the actualValueGenerator
+ * stop when either one of the following occurs: + *
    + *
  1. the actual object is null
  2. + *
  3. the thread was interrupted while sleeping
  4. + *
  5. timeout expires
  6. + *
+ * + * @param
+ * the type of actual to examine + * @param + * the type of the resource to gain the actual value from + * @param resource + * a {@link il.co.topq.integframework.Module} or another kind of + * external {@link Object}, from which the actual value is + * gained. + * @param actualValueGenerator + * a function from the resource above to the actual value- on + * which to perform assertion on + * @param logic + * Logic to operate on the actual object + * @param timeout + * maximum time for this operation + * @param timeoutUnit + * time unit for the parameter above + * @param interval + * time to sleep between assertions + * @param intervalUnit + * time unit for the parameter above + * @throws AssertionError + * If assertion fails + * @return true if assertion finished due to timeout i.e. the assertion + * passed on all invocations of + * {@link AbstractAssertionLogic#doAssertion()} + */ + static public void assertLogic(R resource, final Function actualValueGenerator, AbstractAssertionLogic logic, + long timeout, TimeUnit timeoutUnit, long interval, TimeUnit intervalUnit) { + assertLogic(resource, actualValueGenerator, logic, new DefaultAssertionListener(), timeout, timeoutUnit, interval, + intervalUnit); + } + + /** + * Execute the logic and repeating on the the + * actual object, as gained from the actualValueGenerator
+ * stop when either one of the following occurs: + *
    + *
  1. the actual object is null
  2. + *
  3. the thread was interrupted while sleeping
  4. + *
  5. timeout expires
  6. + *
* * @param
* the type of actual to examine @@ -135,6 +188,8 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< * which to perform assertion on * @param logic * Logic to operate on the actual object + * @param listener + * an {@link AssertionListener} for ssertion events. * @param timeout * maximum time for this operation * @param timeoutUnit @@ -145,24 +200,36 @@ static public void assertLogic(final T actual, final AbstractAssertionLogic< * time unit for the parameter above * @throws AssertionError * If assertion fails + * @return true if assertion finished due to timeout i.e. the assertion + * passed on all invocations of + * {@link AbstractAssertionLogic#doAssertion()} */ - static public void assertLogic(R resource, final Function actualValueGenerator, - AbstractAssertionLogic logic, long timeout, TimeUnit timeoutUnit, long interval, TimeUnit intervalUnit) - throws InterruptedException { + static public void assertLogic(R resource, final Function actualValueGenerator, AbstractAssertionLogic logic, + AssertionListener listener, long timeout, TimeUnit timeoutUnit, long interval, TimeUnit intervalUnit) { long end = System.currentTimeMillis() + timeoutUnit.toMillis(timeout); - while (true) { - Assert.assertLogic(actualValueGenerator.apply(resource), logic); - Thread.sleep(intervalUnit.toMillis(interval)); - if (end > System.currentTimeMillis()) { - return; + A actual; + do { + actual = actualValueGenerator.apply(resource); + if (actual == null) { + listener.assertionFailed(actual, logic); } - } - + Assert.assertLogic(actual, logic, listener); + try { + Thread.sleep(intervalUnit.toMillis(interval)); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + listener.assertionFailed(actual, logic); + } + } while (end < System.currentTimeMillis()); + listener.assertionPassed(actual, logic); } + /** + * @deprecated use + * {@link Assert#assertLogic(Object, Function, AbstractAssertionLogic, long, TimeUnit, long, TimeUnit) + */ @Deprecated - static public void assertLogicHappens(final T actual, - final AbstractAssertionLogic logic, final long timeout, + static public void assertLogicHappens(final T actual, final AbstractAssertionLogic logic, final long timeout, boolean silent) throws TimeoutException { assertLogic(actual, logic, timeout); From 440c8334186226041c537bfea3d744d49691595a Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:09:30 +0200 Subject: [PATCH 046/301] wget client is now callable. data is generated with PostDataGenerator --- .../integframework/PostDataGenerator.java | 5 +++ .../il/co/topq/integframework/WgetClient.java | 37 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 integ-wget/src/main/java/il/co/topq/integframework/PostDataGenerator.java diff --git a/integ-wget/src/main/java/il/co/topq/integframework/PostDataGenerator.java b/integ-wget/src/main/java/il/co/topq/integframework/PostDataGenerator.java new file mode 100644 index 0000000..e8680d2 --- /dev/null +++ b/integ-wget/src/main/java/il/co/topq/integframework/PostDataGenerator.java @@ -0,0 +1,5 @@ +package il.co.topq.integframework; + +public interface PostDataGenerator { + public CharSequence generateData(WgetClient forClient); +} diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java index 01c9481..e3c9565 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -1,16 +1,23 @@ package il.co.topq.integframework; +import il.co.topq.integframework.WgetModule.WgetCommand; import il.co.topq.integframework.cli.conn.LinuxDefaultCliConnection; +import il.co.topq.integframework.utils.StringUtils; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.OutputStream; +import java.io.StringReader; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; -public class WgetClient { +public class WgetClient implements Callable { final String userAgent, ip; private final WgetModule module; + private PostDataGenerator dataGenerator; public WgetClient(WgetModule module, String ip, String userAgent) { this.module = module; @@ -26,16 +33,24 @@ public String getIp() { return ip; } + public synchronized void setDataGenerator(PostDataGenerator postDataGenerator) { + if (null == this.dataGenerator) { + this.dataGenerator = postDataGenerator; + } + } + public void post(CharSequence data) throws Exception { module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(data).error("failed") .execute(); } public void silentlyPost(CharSequence data) throws Exception { - module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(data).error("failed") + module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(data) + .withTimeout(30, TimeUnit.SECONDS).error("failed") .silently().execute(); } + public void postFile(String remoteFile) throws Exception { module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().postFile(remoteFile) .error("failed").execute(); @@ -53,7 +68,6 @@ public void post(byte[] data, String remoteDir, String remoteFile) throws Except postFile(remoteDir + "/" + remoteFile); } - public void bindAddress() throws Exception { module.new AddIpCommand(ip).execute(); } @@ -104,5 +118,22 @@ public String toString() { return builder.toString(); } + @Override + public String call() throws Exception { + WgetCommand wgetCommand = module.new WgetCommand(); + wgetCommand.bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().post(this.dataGenerator.generateData(this)); + wgetCommand.error("failed").silently().execute(); + String httpRequestSentMessage = "HTTP request sent, awaiting response... "; + wgetCommand.mustHaveResponse(httpRequestSentMessage); + BufferedReader responseReader = new BufferedReader(new StringReader(wgetCommand.getResult())); + String resultLine; + + while (null != (resultLine = responseReader.readLine())) { + if (resultLine.startsWith(httpRequestSentMessage)) { + return StringUtils.getFirstSubStringSuffix(resultLine, httpRequestSentMessage); + } + } + return null; + } } From 8684c87885230dcb583f898b3f2f4298729b9719 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:11:11 +0200 Subject: [PATCH 047/301] 1. refactor: using the term "result" instead of response 2. new contdition for getting a parsed result from the command --- .../CliExecutionExpectedConditions.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java index 465ebcf..26b7aa8 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/CliExecutionExpectedConditions.java @@ -42,7 +42,7 @@ public String toString() { } - public static CliExecutionExpectedCondition executionResponseReturn(final String expectedResponse) { + public static CliExecutionExpectedCondition executionResultContains(final String expectedResponse) { return executionLogicHappens(new FindTextAssertion(expectedResponse) { @Override public String toString() { @@ -51,7 +51,7 @@ public String toString() { }); } - public static CliExecutionExpectedCondition executionResponseReturnExactly(final String expectedResponse) { + public static CliExecutionExpectedCondition executionResultIs(final String expectedResponse) { return executionLogicHappens(new ComparableAssertion(expectedResponse, CompareMethod.EQUALS) { @Override public String toString() { @@ -104,4 +104,31 @@ public String toString() { }; } + + /** + * execute the given execution and parse the result. + * + * @param parser + * for parsing the result. the parser may return null. + * @return the result + */ + public static CliExecutionExpectedCondition executionResult(final Parser parser) { + return new CliExecutionExpectedCondition() { + + @Override + public T apply(CliCommandExecution execution) { + try { + execution.execute(); + T actual = parser.parse(execution.getResult()); + if (actual == null) { + throw new NullPointerException(execution.toString() + " result parsed to null\n" + execution.getResult()); + } + return actual; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + + } } From 55aa4cf27f72a5bc2a3fd19adbf9513104a4c6e8 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:24:04 +0200 Subject: [PATCH 048/301] NamedThreadFactory is a factory that names threads with a specific prefix --- .../support/threads/NamedThreadFactory.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 integ-support/src/main/java/il/co/topq/integframework/support/threads/NamedThreadFactory.java diff --git a/integ-support/src/main/java/il/co/topq/integframework/support/threads/NamedThreadFactory.java b/integ-support/src/main/java/il/co/topq/integframework/support/threads/NamedThreadFactory.java new file mode 100644 index 0000000..7b3affb --- /dev/null +++ b/integ-support/src/main/java/il/co/topq/integframework/support/threads/NamedThreadFactory.java @@ -0,0 +1,28 @@ +package il.co.topq.integframework.support.threads; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +public class NamedThreadFactory implements ThreadFactory { + private final String name; + private static Map names = new ConcurrentHashMap(); + + public NamedThreadFactory(String name) { + synchronized (names) { + if (!names.containsKey(name)) { + names.put(name, new AtomicInteger()); + } + } + this.name = name; + } + + @Override + public Thread newThread(Runnable r) { + Thread thread = Executors.defaultThreadFactory().newThread(r); + thread.setName(name + "#" + names.get(name).incrementAndGet()); + return thread; + } +} \ No newline at end of file From 1ca87e7f821ad3c2ac2e297843f23eb62bd11126 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 3 Mar 2014 16:39:22 +0200 Subject: [PATCH 049/301] Version 1.0.3-SNAPSHOT --- integ-cli/pom.xml | 2 +- integ-db/pom.xml | 2 +- integ-hdfs/pom.xml | 2 +- integ-parent/pom.xml | 2 +- integ-rest/pom.xml | 2 +- integ-support/pom.xml | 2 +- integ-testng/pom.xml | 2 +- integ-webdriver/pom.xml | 2 +- integ-wget/pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/integ-cli/pom.xml b/integ-cli/pom.xml index 1d19ef1..4fe9eb1 100644 --- a/integ-cli/pom.xml +++ b/integ-cli/pom.xml @@ -31,7 +31,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-db/pom.xml b/integ-db/pom.xml index ede6c26..8f0a57d 100644 --- a/integ-db/pom.xml +++ b/integ-db/pom.xml @@ -21,7 +21,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-hdfs/pom.xml b/integ-hdfs/pom.xml index c89973c..cc5409d 100644 --- a/integ-hdfs/pom.xml +++ b/integ-hdfs/pom.xml @@ -38,7 +38,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent diff --git a/integ-parent/pom.xml b/integ-parent/pom.xml index be7cd0c..a55838d 100644 --- a/integ-parent/pom.xml +++ b/integ-parent/pom.xml @@ -2,7 +2,7 @@ 4.0.0 il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT pom UTF-8 diff --git a/integ-rest/pom.xml b/integ-rest/pom.xml index 20e7481..08fb791 100644 --- a/integ-rest/pom.xml +++ b/integ-rest/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent integ-rest diff --git a/integ-support/pom.xml b/integ-support/pom.xml index 8106d03..8cbbfc9 100644 --- a/integ-support/pom.xml +++ b/integ-support/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent integ-support diff --git a/integ-testng/pom.xml b/integ-testng/pom.xml index 6c6d9e1..4bf30b6 100644 --- a/integ-testng/pom.xml +++ b/integ-testng/pom.xml @@ -54,7 +54,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-webdriver/pom.xml b/integ-webdriver/pom.xml index ef3d104..7d8741e 100644 --- a/integ-webdriver/pom.xml +++ b/integ-webdriver/pom.xml @@ -71,7 +71,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent diff --git a/integ-wget/pom.xml b/integ-wget/pom.xml index bb96303..c883759 100644 --- a/integ-wget/pom.xml +++ b/integ-wget/pom.xml @@ -3,7 +3,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent integ-wget From 33d31b49914f6da606e36128cb37240c8e674d8a Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 10 Mar 2014 17:50:20 +0200 Subject: [PATCH 050/301] parent version 1.0.3-SNAPSHOT --- integ-bdd/pom.xml | 2 +- integ-groovy-bdd/pom.xml | 2 +- integ-image-validator/pom.xml | 2 +- integ-jms/pom.xml | 2 +- integ-junit/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/integ-bdd/pom.xml b/integ-bdd/pom.xml index bc7973a..9a00af1 100644 --- a/integ-bdd/pom.xml +++ b/integ-bdd/pom.xml @@ -4,7 +4,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent diff --git a/integ-groovy-bdd/pom.xml b/integ-groovy-bdd/pom.xml index 1ab8237..c053511 100644 --- a/integ-groovy-bdd/pom.xml +++ b/integ-groovy-bdd/pom.xml @@ -82,7 +82,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-image-validator/pom.xml b/integ-image-validator/pom.xml index 52d0636..cb5b9b0 100644 --- a/integ-image-validator/pom.xml +++ b/integ-image-validator/pom.xml @@ -22,7 +22,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-jms/pom.xml b/integ-jms/pom.xml index 78f9878..6d8ba76 100644 --- a/integ-jms/pom.xml +++ b/integ-jms/pom.xml @@ -21,7 +21,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file diff --git a/integ-junit/pom.xml b/integ-junit/pom.xml index 047cb29..0c512c2 100644 --- a/integ-junit/pom.xml +++ b/integ-junit/pom.xml @@ -17,7 +17,7 @@ il.co.topq.integframework integ-parent - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT ../integ-parent \ No newline at end of file From a8487867582d01670463b7eea1ad2c9939fdf07d Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 10 Mar 2014 17:51:40 +0200 Subject: [PATCH 051/301] new method log (title, body, style) --- .../integframework/reporting/Reporter.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java index 0a0de38..6a5b84a 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java @@ -115,7 +115,36 @@ public static void log(String s, boolean logToStandardOut, Style style, Color co * Will appear when clicking on the title. */ public static void log(String title, String body) { - log(title, body, null); + log(title, body, Style.REGULAR); + } + + /** + * Adds toggle element to the report + * + * @param title + * Will appear as link. If none given the link will appear with + * the test 'link' + * @param body + * Will appear when clicking on the title. + * @param style + * The {@link Style} to style the body + */ + public static void log(String title, String body, Style style) { + if (null == title) { + title = "title"; + } + System.out.println(title + "\n"); + if (body != null) { + System.out.println(body + "\n"); + } + if (null == body || body.isEmpty()) { + log(title, style); + return; + } + startLogToggle(title); + log(body, style); + stopLogToggle(); + } /** @@ -260,6 +289,10 @@ private static String appendStyleParagraph(String s, Style style) { final StringBuilder sb = new StringBuilder(); sb.append("

"); sb.append("<").append(style.value).append(">"); + if (Style.PLAINTEXT.equals(style)) { + s = s.replaceAll("<", "<"); + s = s.replaceAll(">", ">"); + } sb.append(s); sb.append(""); sb.append("

"); From 21f0a168430279232c3fa445febb0c4dcc3cd9de Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Tue, 11 Mar 2014 13:53:35 +0200 Subject: [PATCH 052/301] using style object instead of hardcoded "
" tag

---
 .../integframework/rest/RESTClientModule.java    | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java b/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java
index bbc01c9..11797aa 100644
--- a/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java
+++ b/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java
@@ -4,7 +4,9 @@
 import il.co.topq.integframework.AbstractModuleImpl;
 import il.co.topq.integframework.reporting.Reporter;
 import il.co.topq.integframework.reporting.Reporter.Color;
+import il.co.topq.integframework.reporting.Reporter.Style;
 
+import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
 
 import com.sun.jersey.api.client.ClientResponse;
@@ -13,8 +15,7 @@ public class RESTClientModule extends AbstractModuleImpl {
 	String uri;
 
 	public ClientResponse post(JSONObject input, String action) throws Exception {
-		Reporter.log("Request", Color.BLUE);
-		Reporter.log("
\n" + input.toString() + "
\n"); + Reporter.log("Request", input.toString(3), Style.PLAINTEXT); StringBuilder builder = new StringBuilder(uri); if (!uri.endsWith("/")) { builder.append("/"); @@ -24,8 +25,15 @@ public ClientResponse post(JSONObject input, String action) throws Exception { .accept("application/json").post(ClientResponse.class, input); setActual(clientResponse.getEntity(String.class)); - Reporter.log("Response", Color.BLUE); - Reporter.log("
\n" + getActual(String.class) + "
\n"); + try { + JSONObject response = new JSONObject(getActual(String.class)); + Reporter.log("Response", response.toString(3), Style.PLAINTEXT); + } catch (JSONException e) { + Reporter.log("Response", getActual(String.class), Style.PLAINTEXT);// should + // never + // happen!! + } + return clientResponse; } From 05d9867292dcbbdca172e2dd6cad642a4db66381 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 17 Mar 2014 11:50:42 +0200 Subject: [PATCH 053/301] Parses for int and long --- .../co/topq/integframework/utils/Parsers.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java new file mode 100644 index 0000000..0ea6fce --- /dev/null +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java @@ -0,0 +1,28 @@ +package il.co.topq.integframework.utils; + +import java.text.ParseException; + +public class Parsers { + + private final Object __; + + private Parsers() { + __ = null; + } + + public static final Parser longParser = new Parser() { + @Override + public Long parse(String source) throws ParseException { + return Long.parseLong(source); + } + }; + + public static final Parser intParser = new Parser() { + @Override + public Integer parse(String source) throws ParseException { + return Integer.parseInt(source); + } + }; + + +} From 8d46e114294abe027e72a4d140e8985b75980550 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 17 Mar 2014 11:54:41 +0200 Subject: [PATCH 054/301] 1. running process methods fixed (non zero VS exactly one) 2. new method: process instances counter command 3. new methods for getting remote machine time --- .../cli/conn/LinuxDefaultCliConnection.java | 36 +++++++++++++++++-- .../support/LinuxCliExpectedConditions.java | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/LinuxDefaultCliConnection.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/LinuxDefaultCliConnection.java index 92805b4..141d690 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/LinuxDefaultCliConnection.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/conn/LinuxDefaultCliConnection.java @@ -15,7 +15,11 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.Iterator; +import java.util.TimeZone; /** * Default CliConnection for a Cli connection to a linux machine. Protocol is @@ -141,9 +145,37 @@ public Iterator fileList(String directory) throws Exception { } public boolean isProccessRunning(String name) throws Exception { - CliCommandExecution execution = new CliCommandExecution(this, "ps -C '" + name + "' -o pid= |wc -l"); + CliCommandExecution execution = new CliCommandExecution(this, processInstancesCounterCommand(name)); execution.withTitle("check if process " + name + " is running").execute(); - return "1".equals(execution.getResult()); + return !"0".equals(execution.getResult()); } + public boolean isProccessNotRunning(String name) throws Exception { + CliCommandExecution execution = new CliCommandExecution(this, processInstancesCounterCommand(name)); + execution.withTitle("check if process " + name + " is running").execute(); + return "0".equals(execution.getResult()); + } + + public static String processInstancesCounterCommand(String cmd) { + return "ps -C '" + cmd + "' -o pid= |wc -l"; + } + + public Date getRemoteMachineDate() throws Exception { + CliCommandExecution execution = new CliCommandExecution(this, "date +%s"); + // seconds since epoch + execution.execute(); + return new Date(Long.parseLong(execution.getResult() + "000")); + } + + public Calendar getRemoteMachineCalendar() throws Exception { + Calendar calendar = new GregorianCalendar(getRemoteMachineTimeZone()); + calendar.setTimeInMillis(getRemoteMachineDate().getTime()); + return calendar; + } + + public TimeZone getRemoteMachineTimeZone() throws Exception { + CliCommandExecution execution = new CliCommandExecution(this, "date +%Z"); + execution.execute(); + return TimeZone.getTimeZone(execution.getResult()); + } } diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java index 3217fd2..213e2b5 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java @@ -256,7 +256,7 @@ public Boolean apply(CliConnection cliConnection) { } public Boolean apply(LinuxDefaultCliConnection linux) throws Exception { - return !linux.isProccessRunning(processName); + return linux.isProccessNotRunning(processName); } }; } From f988f0acb0ec11d3f29f1caf2e14bb721e4ef422 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 17 Mar 2014 18:12:58 +0200 Subject: [PATCH 055/301] plaintext style when sending REST requests --- .../java/il/co/topq/integframework/rest/RESTClientModule.java | 4 ++-- .../integframework/rest/TomcatRESTApplicationContainer.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java b/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java index 11797aa..54fe27e 100644 --- a/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java +++ b/integ-rest/src/main/java/il/co/topq/integframework/rest/RESTClientModule.java @@ -47,7 +47,7 @@ public void setUri(String uri) { public ClientResponse put(JSONObject input, String action) { Reporter.log("Request", Color.BLUE); - Reporter.log("
\n" + input.toString() + "
\n"); + Reporter.log(input.toString(), Style.PLAINTEXT); StringBuilder builder = new StringBuilder(uri); if (!uri.endsWith("/")) { builder.append("/"); @@ -58,7 +58,7 @@ public ClientResponse put(JSONObject input, String action) { setActual(clientResponse.getEntity(String.class)); Reporter.log("Response", Color.BLUE); - Reporter.log("
\n" + getActual(String.class) + "
\n"); + Reporter.log(getActual(String.class), Style.PLAINTEXT); return clientResponse; } diff --git a/integ-rest/src/main/java/il/co/topq/integframework/rest/TomcatRESTApplicationContainer.java b/integ-rest/src/main/java/il/co/topq/integframework/rest/TomcatRESTApplicationContainer.java index 5da7e56..2d4b27d 100644 --- a/integ-rest/src/main/java/il/co/topq/integframework/rest/TomcatRESTApplicationContainer.java +++ b/integ-rest/src/main/java/il/co/topq/integframework/rest/TomcatRESTApplicationContainer.java @@ -4,6 +4,7 @@ import static il.co.topq.integframework.utils.StringUtils.isEmpty; import il.co.topq.integframework.reporting.Reporter; import il.co.topq.integframework.reporting.Reporter.Color; +import il.co.topq.integframework.reporting.Reporter.Style; import il.co.topq.integframework.utils.StringUtils; import java.net.URI; @@ -70,7 +71,7 @@ public ClientResponse reload() throws URISyntaxException { setActual(clientResponse.getEntity(String.class)); Reporter.log("Response", Color.BLUE); - Reporter.log("
\n" + getActual(String.class) + "
\n"); + Reporter.log(getActual(String.class), Style.PLAINTEXT); return clientResponse; } From d3cb31b828302d788754720bc8278f55f41d0451 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 17 Mar 2014 18:14:14 +0200 Subject: [PATCH 056/301] being more informative and less verbose --- .../topq/integframework/assertion/CollectionAssertion.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java index 25d90ae..68f3fc2 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/assertion/CollectionAssertion.java @@ -188,7 +188,7 @@ public void doAssertion() { } } else if (matches != null) { status = true; - Reporter.step("Validating matches data:\n"); + Reporter.step("Validating matches data using " + comparator.toString()); long mismatchCounter = 0; for (PairOfMatches match : matches) { if (comparator.compare(match.actual, match.expected) != 0) { @@ -201,9 +201,10 @@ public void doAssertion() { mismatchCounter++; } } - message = message + "Total reproccessed items:" + matches.size() + "\n"; + message = "Total reproccessed items:" + matches.size() + "\n"; if (mismatchCounter > 0) { - message = message + "Total mismatch data items found:" + mismatchCounter + "\n"; + message = message + "Total mismatch data items found:" + mismatchCounter + "\n when comparing " + + comparator.toString(); } } From c4065f7d9cb98eb2a03ef7ba55ff3fe9c8997313 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 19 Mar 2014 11:00:25 +0200 Subject: [PATCH 057/301] LinuxCommandLineModule --- .../cli/process/LinuxCommandLineModule.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 integ-cli/src/main/java/il/co/topq/integframework/cli/process/LinuxCommandLineModule.java diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/process/LinuxCommandLineModule.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/LinuxCommandLineModule.java new file mode 100644 index 0000000..328ad42 --- /dev/null +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/process/LinuxCommandLineModule.java @@ -0,0 +1,14 @@ +package il.co.topq.integframework.cli.process; + +import il.co.topq.integframework.cli.conn.LinuxDefaultCliConnection; + +public class LinuxCommandLineModule extends CommandLineModule { + protected LinuxDefaultCliConnection linux; + + @Override + public void init() throws Exception { + super.init(); + linux = (LinuxDefaultCliConnection) cliConnectionImpl; + // casting exception is good!!! misuse of this class will cause it!! + } +} From 2d6ff8e1267eceea223552222bfbc0327b64b2e7 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 19 Mar 2014 11:34:32 +0200 Subject: [PATCH 058/301] typo --- .../integframework/cli/support/LinuxCliExpectedConditions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java index 213e2b5..a7fba80 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/support/LinuxCliExpectedConditions.java @@ -61,7 +61,7 @@ public static CliExpectedCondition fileIsReadable(final String path @Override public String toString() { - return "the file in " + path.toString() + " to be openable"; + return "the file in " + path.toString() + " to be readable"; }; public InputStream apply(LinuxDefaultCliConnection cliConnection) { From 80439ae2c737ed55105c28c14a31367b698bec6d Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 19 Mar 2014 11:35:11 +0200 Subject: [PATCH 059/301] casting exception in misuse --- .../main/java/il/co/topq/integframework/WgetClient.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java index e3c9565..4e29d69 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -57,11 +57,8 @@ module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadA } public void post(byte[] data, String remoteDir, String remoteFile) throws Exception { - LinuxDefaultCliConnection linux = null; - if (module.getCliConnectionImpl() instanceof LinuxDefaultCliConnection) { - linux = (LinuxDefaultCliConnection) module.getCliConnectionImpl(); - } - OutputStream put = linux.put(remoteDir, remoteFile, null, data.length); + OutputStream put = ((LinuxDefaultCliConnection) module.getCliConnectionImpl()) + .put(remoteDir, remoteFile, null, data.length); IOUtils.copy(new ByteArrayInputStream(data), put); IOUtils.closeQuietly(put); From 34df186121fb51dcda8f4e2599459908a660b2b0 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Wed, 19 Mar 2014 12:17:56 +0200 Subject: [PATCH 060/301] ignore target folder --- integ-db/.gitignore | 1 + integ-hdfs/.gitignore | 1 + integ-rest/.gitignore | 1 + integ-support/.gitignore | 1 + integ-testng/.gitignore | 1 + integ-wget/.gitignore | 1 + 6 files changed, 6 insertions(+) create mode 100644 integ-db/.gitignore create mode 100644 integ-hdfs/.gitignore create mode 100644 integ-rest/.gitignore create mode 100644 integ-support/.gitignore create mode 100644 integ-testng/.gitignore create mode 100644 integ-wget/.gitignore diff --git a/integ-db/.gitignore b/integ-db/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-db/.gitignore @@ -0,0 +1 @@ +/target diff --git a/integ-hdfs/.gitignore b/integ-hdfs/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-hdfs/.gitignore @@ -0,0 +1 @@ +/target diff --git a/integ-rest/.gitignore b/integ-rest/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-rest/.gitignore @@ -0,0 +1 @@ +/target diff --git a/integ-support/.gitignore b/integ-support/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-support/.gitignore @@ -0,0 +1 @@ +/target diff --git a/integ-testng/.gitignore b/integ-testng/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-testng/.gitignore @@ -0,0 +1 @@ +/target diff --git a/integ-wget/.gitignore b/integ-wget/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/integ-wget/.gitignore @@ -0,0 +1 @@ +/target From 4d64e3c3bf9f51bccb55134f85fd741a41818a5c Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Mar 2014 18:17:07 +0200 Subject: [PATCH 061/301] silentlyPostLater --- .../il/co/topq/integframework/WgetClient.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java index 4e29d69..7620c02 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetClient.java @@ -51,6 +51,23 @@ module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadA } + public Runnable silentlyPostLater(final CharSequence data) { + return new Runnable() { + @Override + public void run() { + try { + synchronized (this) { + silentlyPost(data); + } + } catch (Exception e) { + + } + + } + }; + + } + public void postFile(String remoteFile) throws Exception { module.new WgetCommand().bindAddress(ip).withUserAgent(userAgent).doNotDownloadAnything().postFile(remoteFile) .error("failed").execute(); From 3f244fa016a6c1f66dd9eabfcf03e150a4491df3 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Thu, 20 Mar 2014 18:17:28 +0200 Subject: [PATCH 062/301] wget is linux command --- .../java/il/co/topq/integframework/WgetModule.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java index e140698..592ed54 100644 --- a/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java +++ b/integ-wget/src/main/java/il/co/topq/integframework/WgetModule.java @@ -1,14 +1,14 @@ package il.co.topq.integframework; import il.co.topq.integframework.cli.process.CliCommandExecution; -import il.co.topq.integframework.cli.process.CommandLineModule; +import il.co.topq.integframework.cli.process.LinuxCommandLineModule; import il.co.topq.integframework.utils.StringUtils; import java.net.URL; import org.testng.Assert; -public class WgetModule extends CommandLineModule { +public class WgetModule extends LinuxCommandLineModule { String url; @@ -21,14 +21,14 @@ public void init() throws Exception { } public class AddIpCommand extends CliCommandExecution { public AddIpCommand(String ipAddress) { - super(getCliConnectionImpl(), "sudo ip -4 addr add " + ipAddress + "/32 dev lo scope host"); + super(linux, "sudo ip -4 addr add " + ipAddress + "/32 dev lo scope host"); withTitle("add ip address"); } } public class DeleteIpCommand extends CliCommandExecution { public DeleteIpCommand(String ipAddress) { - super(getCliConnectionImpl(), "sudo ip -4 addr del " + ipAddress + "/32 dev lo scope host"); + super(linux, "sudo ip -4 addr del " + ipAddress + "/32 dev lo scope host"); withTitle("remove ip address"); } } @@ -39,7 +39,7 @@ public class WgetCommand extends CliCommandExecution { postDataSet = false, alreadyRun = false; public WgetCommand() { - super(getCliConnectionImpl()); + super(linux); withTitle("wget"); } From 725701b67bdc2d3385530b6a9be1fb8c128f6344 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Mon, 24 Mar 2014 09:50:54 +0200 Subject: [PATCH 063/301] debug system output when key file is not good --- .../java/il/co/topq/integframework/cli/terminal/SSHWithRSA.java | 1 + 1 file changed, 1 insertion(+) diff --git a/integ-cli/src/main/java/il/co/topq/integframework/cli/terminal/SSHWithRSA.java b/integ-cli/src/main/java/il/co/topq/integframework/cli/terminal/SSHWithRSA.java index 71993c7..87f666e 100644 --- a/integ-cli/src/main/java/il/co/topq/integframework/cli/terminal/SSHWithRSA.java +++ b/integ-cli/src/main/java/il/co/topq/integframework/cli/terminal/SSHWithRSA.java @@ -65,6 +65,7 @@ public void connect() throws IOException { } else { System.out .println("Auth Error - The privateKeyFile should be init from the SUT with a valid path to ppk/pem RSA private key"); + System.out.println(privateKeyFile); } } catch (Exception e) { System.out.println(e.getMessage()); From 07666f0936d2fcba82b336aadecd03626c99003e Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Tue, 1 Apr 2014 14:34:41 +0300 Subject: [PATCH 064/301] reportng version --- integ-testng/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integ-testng/pom.xml b/integ-testng/pom.xml index 4bf30b6..5120434 100644 --- a/integ-testng/pom.xml +++ b/integ-testng/pom.xml @@ -3,9 +3,9 @@ integ-testng - org.uncommons + il.co.topq.integframework reportng - 1.1.2 + 1.1.41 org.testng From c93bd3f2cf71c9d479ad5df3e496a7f0057e5f25 Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Tue, 1 Apr 2014 14:45:33 +0300 Subject: [PATCH 065/301] cleanup code --- .../src/main/java/il/co/topq/integframework/utils/Parsers.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java index 0ea6fce..1a14a0d 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/utils/Parsers.java @@ -8,6 +8,8 @@ public class Parsers { private Parsers() { __ = null; + if (__ == null) + ; } public static final Parser longParser = new Parser() { From 0e0bd6369a37c3ac69df4c49ad15ebe6c692d63e Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Tue, 1 Apr 2014 15:25:10 +0300 Subject: [PATCH 066/301] 1. only one DateFormat object is needed. 2. format is fixed (milliseconds padding) --- .../main/java/il/co/topq/integframework/reporting/Reporter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java index 6a5b84a..81c8a17 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java @@ -81,6 +81,7 @@ public static void log(final String title, final Throwable t) { log(title, StringUtils.getStackTrace(t), false); } + protected static DateFormat df = new SimpleDateFormat("HH:mm:ss.SSS"); /** * Appending s to the report with time stamp * @@ -88,7 +89,6 @@ public static void log(final String title, final Throwable t) { */ public static void log(String s, boolean logToStandardOut, Style style, Color color) { if(!s.startsWith(" Date: Tue, 1 Apr 2014 16:22:42 +0300 Subject: [PATCH 067/301] removed style from timestamp --- .../java/il/co/topq/integframework/reporting/Reporter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java index 81c8a17..4d90bbe 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java @@ -88,9 +88,10 @@ public static void log(final String title, final Throwable t) { * @param s */ public static void log(String s, boolean logToStandardOut, Style style, Color color) { + String reportDate = ""; if(!s.startsWith(" Date: Tue, 1 Apr 2014 18:33:46 +0300 Subject: [PATCH 068/301] testing styles --- .../co/topq/integframework/ReporterTests.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/integ-testng/src/test/java/il/co/topq/integframework/ReporterTests.java b/integ-testng/src/test/java/il/co/topq/integframework/ReporterTests.java index d994772..6ed8c4c 100644 --- a/integ-testng/src/test/java/il/co/topq/integframework/ReporterTests.java +++ b/integ-testng/src/test/java/il/co/topq/integframework/ReporterTests.java @@ -46,11 +46,27 @@ public void testReportColors() { Reporter.log("In yellow", Style.ITALIC, Color.YELLOW); Reporter.log("In green", Style.ITALIC, Color.GREEN); + Reporter.step("All colors and styles in a loop:"); + for (Color color : Color.values()) { + for (Style style : Style.values()) { + Reporter.log(color.name() + " log with a " + style.name() + " style", style, color); + } + } + Reporter.step("****** All colors in a loop ******"); } @Test public void testLogImage(){ - Reporter.logImage("my title", new File("src/test/resources/screenshot.png")); + Reporter.logImage("my title", new File(this.getClass().getResource("/screenshot.png").getPath())); + } + + @Test + public void testException() { + Reporter.log(new RuntimeException()); + Reporter.log(new RuntimeException("with message")); + Reporter.log("with my own title", new RuntimeException()); + Reporter.log("with my own title", new RuntimeException("with message")); + Reporter.getCurrentTestResult().setStatus(0); } @Test @@ -101,8 +117,10 @@ public void testToggleWithColor() { @Test public void testStyle() { - Reporter.log("In bold", Style.BOLD); - Reporter.log("In italic", Style.ITALIC); + for (Style style : Style.values()) { + Reporter.log("Style is " + style.name(), style); + } } + } From 936ebb275ea4d42e3093888759f5f034581babad Mon Sep 17 00:00:00 2001 From: aharon hacmon Date: Tue, 1 Apr 2014 18:37:15 +0300 Subject: [PATCH 069/301] using span in colors removed

tags to prevent new line when attaching an image, the file must exist all tests are passing now --- .../integframework/reporting/Reporter.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java index 4d90bbe..da11118 100644 --- a/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java +++ b/integ-testng/src/main/java/il/co/topq/integframework/reporting/Reporter.java @@ -28,7 +28,7 @@ public class Reporter extends org.testng.Reporter { } public enum Style { - REGULAR(""), BOLD("b"), ITALIC("i"), PLAINTEXT("pre"), EMPHASIZED("em"), STRIKETHROUGH("strike"); + REGULAR(""), BOLD("b"), ITALIC("i"), PLAINTEXT("pre"), EMPHASIZED("em"), STRIKETHROUGH("strike"), CENTER("center"); private final String value; @@ -94,15 +94,12 @@ public static void log(String s, boolean logToStandardOut, Style style, Color co // s = reportDate + s + "\n"; } String newS = s; - if (null == style) { - style = Style.REGULAR; + if (null != style && !Style.REGULAR.equals(style)) { + newS = appendStyleParagraph(newS, style); } if (null != color) { newS = appendColorParagraph(newS, color); } - if (style != Style.REGULAR) { - newS = appendStyleParagraph(newS, style); - } writeToLog(reportDate + newS + ((StringUtils.isEmpty(reportDate)) ? "" : "\n"), logToStandardOut); } @@ -227,13 +224,13 @@ public static void startLogToggle(String title, Color color) { toggleElement.append(" "); - toggleElement.append(title).append("
"); + toggleElement.append(appendColorParagraph(title, color)).append("
"); // Creating body toggleElement.append("