From 6c7cb83d931dfa3cb8d0377b5fc51e4a944ca80c Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Tue, 10 Nov 2009 21:32:52 +0000 Subject: [PATCH] [LMS-1257] simplified system tests RemoteConsole and some tests SVN: 13296 --- .../application/FileFormatTypeGridTest.java | 4 +- .../web/client/application/SearchTest.java | 13 ++-- .../AbstractDefaultTestCommand.java | 64 +++--------------- .../testframework/FailureExpectation.java | 34 +++------- .../client/testframework/ITestCommand.java | 35 +++------- .../testframework/PiggyBackCommand.java | 67 ------------------- .../client/testframework/RemoteConsole.java | 57 +++++----------- .../sample/GenericSampleViewerTest.java | 23 +------ 8 files changed, 59 insertions(+), 238 deletions(-) delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/PiggyBackCommand.java diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/FileFormatTypeGridTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/FileFormatTypeGridTest.java index 33187361dfd..9769a920c13 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/FileFormatTypeGridTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/FileFormatTypeGridTest.java @@ -29,7 +29,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.Abstract import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.AbstractGWTTestCase; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.CheckTableCommand; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.GWTTestUtil; -import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.PiggyBackCommand; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.Row; /** @@ -52,7 +51,8 @@ public class FileFormatTypeGridTest extends AbstractGWTTestCase loginAndInvokeAction(ActionMenuKind.DATA_SET_MENU_FILE_FORMATS); CheckTableCommand table = new CheckTableCommand(FileFormatTypeGrid.GRID_ID); table.expectedSize(8); - remoteConsole.prepare(new PiggyBackCommand(table, addNewTypeCommand())); + remoteConsole.prepare(table); + remoteConsole.prepare(addNewTypeCommand()); table = new CheckTableCommand(FileFormatTypeGrid.GRID_ID); table.expectedRow(new Row().withCell(TypeColDefKind.CODE.id(), "MY-TYPE").withCell( TypeColDefKind.DESCRIPTION.id(), "hello")); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SearchTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SearchTest.java index 041e2faf434..ba6ceeb1cfc 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SearchTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/SearchTest.java @@ -24,7 +24,6 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.Abstract import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.AbstractGWTTestCase; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.CheckTableCommand; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.GWTTestUtil; -import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.PiggyBackCommand; import ch.systemsx.cisd.openbis.generic.client.web.client.testframework.Row; /** @@ -85,8 +84,8 @@ public class SearchTest extends AbstractGWTTestCase final CheckTableCommand checkDatasetsTableCommand = createCheckMatchingEntitiesTableCommand(SAMPLE_T1, SAMPLE_T2, SAMPLE_T3); - remoteConsole.prepare(new PiggyBackCommand(checkDatasetsTableCommand, - showDatasetsRelatedToAllDisplayedEntities())); + remoteConsole.prepare(checkDatasetsTableCommand); + remoteConsole.prepare(showDatasetsRelatedToAllDisplayedEntities()); remoteConsole.prepare(createCheckRelatedDatasetsTableCommand(DS_LOC1, DS_LOC2, DS_LOC3)); launchTest(20000); @@ -99,8 +98,8 @@ public class SearchTest extends AbstractGWTTestCase final CheckTableCommand checkDatasetsTableCommand = createCheckMatchingEntitiesTableCommand(EXP_T1, EXP_T2, EXP_T3); - remoteConsole.prepare(new PiggyBackCommand(checkDatasetsTableCommand, - showDatasetsRelatedToAllDisplayedEntities())); + remoteConsole.prepare(checkDatasetsTableCommand); + remoteConsole.prepare(showDatasetsRelatedToAllDisplayedEntities()); remoteConsole.prepare(createCheckRelatedDatasetsTableCommand(DS_LOC1, DS_LOC2, DS_LOC3)); launchTest(20000); @@ -114,8 +113,8 @@ public class SearchTest extends AbstractGWTTestCase final CheckTableCommand checkDatasetsTableCommand = createCheckMatchingEntitiesTableCommand(15, SAMPLE_T1, SAMPLE_T2, SAMPLE_T3, EXP_T1, EXP_T2, EXP_T3); - remoteConsole.prepare(new PiggyBackCommand(checkDatasetsTableCommand, - showDatasetsRelatedToAllDisplayedEntities())); + remoteConsole.prepare(checkDatasetsTableCommand); + remoteConsole.prepare(showDatasetsRelatedToAllDisplayedEntities()); // all datasets from EXP-REUSED are also in results remoteConsole.prepare(createCheckRelatedDatasetsTableCommand(DS_LOC1, DS_LOC2, DS_LOC3, "xml/result-8", "xml/result-9", "xml/result-10", "xml/result-11", "xml/result-12")); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/AbstractDefaultTestCommand.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/AbstractDefaultTestCommand.java index b7ede7ac1bb..dbaab5d212b 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/AbstractDefaultTestCommand.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/AbstractDefaultTestCommand.java @@ -23,16 +23,18 @@ import junit.framework.Assert; import com.google.gwt.user.client.rpc.AsyncCallback; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; - /** - * Abstract super class of all test commands which are executed if the set of classes of recent - * callback objects includes all classes specified in the constructor. + * Abstract super class of all test commands which are executed if there are no active callbacks + * (all callbacks were detected by {@link RemoteConsole}). + * <p> + * NOTE: Expected callbacks are now completely ignored. * * @author Franz-Josef Elmer + * @author Piotr Buczek */ public abstract class AbstractDefaultTestCommand extends Assert implements ITestCommand { + // TODO 2009-11-10, Piotr Buczek: expected callbacks are now completely ignored - cleanup protected final List<String> expectedCallbackIds = new ArrayList<String>(); /** @@ -74,60 +76,14 @@ public abstract class AbstractDefaultTestCommand extends Assert implements ITest return string.replace("$", "\\$"); } - public List<AbstractAsyncCallback<Object>> tryValidOnFailure( - final List<AbstractAsyncCallback<Object>> callbackObjects, final String failureMessage, - final Throwable throwable) - { - return null; - } - - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - final List<AbstractAsyncCallback<Object>> callbackObjects, final Object result) + public boolean isValidOnSucess(Object result) { - return tryGetUnmatchedCallbacks(callbackObjects); + return true; // if previous command succeeded this command should be executed } - /** - * If all expected callbacks can be found among specified callbacks, returns the list of - * callbacks which were not expected. Otherwise returns null; - */ - protected List<AbstractAsyncCallback<Object>> tryGetUnmatchedCallbacks( - final List<AbstractAsyncCallback<Object>> callbackObjects) + public boolean isValidOnFailure(final String failureMessage, final Throwable throwable) { - List<String> expectedIds = new ArrayList<String>(expectedCallbackIds); - List<AbstractAsyncCallback<Object>> unmatched = - new ArrayList<AbstractAsyncCallback<Object>>(); - for (final AbstractAsyncCallback<Object> asyncCallback : callbackObjects) - { - String id = asyncCallback.getCallbackId(); - String matched = getMatchedRegexp(expectedIds, id); - if (matched != null) - { - expectedIds.remove(matched); - } else - { - unmatched.add(asyncCallback); - } - } - if (expectedIds.size() == 0) - { - return unmatched; // all expected callbacks are present - } else - { - return null; - } + return false; // if previous command failed this command shouldn't be executed } - /** @return regular expression from <var>regexps</var> list that given <var>id</var> matches */ - private String getMatchedRegexp(List<String> regexps, String id) - { - for (String regexp : regexps) - { - if (id.matches(regexp)) - { - return regexp; - } - } - return null; - } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/FailureExpectation.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/FailureExpectation.java index 4af4e14dc15..a3873909a65 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/FailureExpectation.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/FailureExpectation.java @@ -16,16 +16,13 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.testframework; -import java.util.List; - import com.google.gwt.user.client.rpc.AsyncCallback; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; - /** * Failure expectation. * * @author Franz-Josef Elmer + * @author Piotr Buczek */ public class FailureExpectation extends AbstractDefaultTestCommand { @@ -68,36 +65,27 @@ public class FailureExpectation extends AbstractDefaultTestCommand } @Override - public List<AbstractAsyncCallback<Object>> tryValidOnFailure( - List<AbstractAsyncCallback<Object>> callbackObjects, String failureMessage, - Throwable throwable) + public boolean isValidOnSucess(Object result) + { + return false; // failure is expected + } + + @Override + public boolean isValidOnFailure(String failureMessage, Throwable throwable) { - List<AbstractAsyncCallback<Object>> unmatchedCallbacks = - tryGetUnmatchedCallbacks(callbackObjects); - if (unmatchedCallbacks == null) - { - return null; - } messageValidator.assertValid(failureMessage); if (expectedThrowableClassOrNull == null || expectedThrowableClassOrNull.equals(throwable.getClass())) { - return unmatchedCallbacks; + return true; } else { - return null; + return false; } } - @Override - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - List<AbstractAsyncCallback<Object>> callbackObjects, Object result) - { - return null; - } - public void execute() { + // nothing to do } - } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/ITestCommand.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/ITestCommand.java index 5f573e73437..7fc1d6de836 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/ITestCommand.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/ITestCommand.java @@ -16,46 +16,33 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.testframework; -import java.util.List; - import com.google.gwt.user.client.rpc.AsyncCallback; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; - /** * A command which will be executed after a successful invocation of * {@link AsyncCallback#onSuccess(Object)}. * * @author Franz-Josef Elmer + * @author Piotr Buczek */ public interface ITestCommand { /** - * If the specified callback objects, failureMessage, and throwable should trigger this command - * in case of an invocation of {@link AsyncCallback#onFailure(Throwable)} then the result is the - * list of callbacks which were not expected by the command. Otherwise <code>null</code> is - * returned. - * - * @param callbackObjects List of callback objects since the last successful match of a test - * command. Contains at least one element. + * Executes this command. */ - public List<AbstractAsyncCallback<Object>> tryValidOnFailure( - List<AbstractAsyncCallback<Object>> callbackObjects, String failureMessage, - Throwable throwable); + public void execute(); /** - * If the specified callback objects and result should trigger this command in case of an - * invocation of {@link AsyncCallback#onSuccess(Object)} then the result is the list of - * callbacks which were not expected by the command. Otherwise <code>null</code> is returned. - * - * @param callbackObjects List of callback objects since the last successful match of a test - * command. Contains at least one element. + * @return <tt>true</tt> if the specified result should trigger this command in case of an + * invocation of {@link AsyncCallback#onSuccess(Object)}, otherwise <tt>false</tt> */ - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - List<AbstractAsyncCallback<Object>> callbackObjects, Object result); + public boolean isValidOnSucess(Object result); /** - * Executes this command. + * @return <tt>true</tt> if the specified <var>failureMessage</var> and <var>throwable</var> + * should trigger this command in case of an invocation of + * {@link AsyncCallback#onFailure(Throwable)}, otherwise <tt>false</tt> */ - public void execute(); + public boolean isValidOnFailure(String failureMessage, Throwable throwable); + } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/PiggyBackCommand.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/PiggyBackCommand.java deleted file mode 100644 index a91c878253f..00000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/PiggyBackCommand.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2009 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.openbis.generic.client.web.client.testframework; - -import java.util.List; - -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; - -/** - * A {@link ITestCommand} which wraps two other test command. All validation calls are delegated to - * the first command. The method {@link #execute()} executes the second command right after the - * first one. Thus, a piggy-back command behaves like the first command with an additional execution - * of a carried-on command (i.e. the second command). - * - * @author Franz-Josef Elmer - */ -public class PiggyBackCommand extends AbstractDefaultTestCommand -{ - - private final ITestCommand firstCommand; - - private final ITestCommand secondCommand; - - public PiggyBackCommand(AbstractDefaultTestCommand firstCommand, ITestCommand secondCommand) - { - this.firstCommand = firstCommand; - this.secondCommand = secondCommand; - } - - @Override - public List<AbstractAsyncCallback<Object>> tryValidOnFailure( - List<AbstractAsyncCallback<Object>> callbackObjects, String failureMessage, - Throwable throwable) - { - return firstCommand.tryValidOnFailure(callbackObjects, failureMessage, throwable); - } - - @Override - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - List<AbstractAsyncCallback<Object>> callbackObjects, Object result) - { - return firstCommand.tryValidOnSucess(callbackObjects, result); - } - - public void execute() - { - System.out.println("EXECUTE: " + firstCommand); - firstCommand.execute(); - System.out.println("EXECUTE: " + secondCommand); - secondCommand.execute(); - } - -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/RemoteConsole.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/RemoteConsole.java index cd459226b10..45959282cfb 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/RemoteConsole.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/testframework/RemoteConsole.java @@ -36,6 +36,7 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IMess * independent whether all commands have been executed or not. In the later case the test fails. * * @author Franz-Josef Elmer + * @author Piotr Buczek */ public class RemoteConsole { @@ -44,9 +45,6 @@ public class RemoteConsole private final List<ITestCommand> commands; - private List<AbstractAsyncCallback<Object>> lastCallbackObjects = - new ArrayList<AbstractAsyncCallback<Object>>(); - private int entryIndex; private Timer timer; @@ -92,20 +90,6 @@ public class RemoteConsole buffer.append(numberOfUnexcutedCommands == 1 ? "command has" : numberOfUnexcutedCommands + " commands have"); buffer.append(" not been executed. "); - if (lastCallbackObjects.size() == 0) - { - buffer.append("No unmatched callback objects."); - } else - { - buffer.append("Unmatched callback objects:"); - for (final AbstractAsyncCallback<?> callback : lastCallbackObjects) - { - buffer.append('\n'); - buffer.append(callback.getClass().getName()); - buffer.append(" with id "); - buffer.append(callback.getCallbackId()); - } - } Assert.fail(buffer.toString()); } } @@ -137,6 +121,11 @@ public class RemoteConsole { } + private boolean areAllCallbacksFinished() + { + return activeCallbacksCounter == 0; + } + private final void executeCommand() { final ITestCommand testCommand = commands.get(entryIndex++); @@ -152,51 +141,39 @@ public class RemoteConsole // ICallbackListener // - public final void onFailureOf(final IMessageProvider messageProvider, - final AbstractAsyncCallback<Object> callback, final String failureMessage, - final Throwable throwable) + public final void finishOnSuccessOf(final AbstractAsyncCallback<Object> callback, + final Object result) { detectCallback(callback); if (entryIndex < commands.size()) { ITestCommand cmd = commands.get(entryIndex); - // TODO 2009-11-09, Piotr Buczek: just validate failure message - List<AbstractAsyncCallback<Object>> unmatchedCallbacks = - cmd.tryValidOnFailure(lastCallbackObjects, failureMessage, throwable); - if (unmatchedCallbacks != null) - { - lastCallbackObjects = unmatchedCallbacks; - } - if (activeCallbacksCounter == 0) + if (cmd.isValidOnSucess(result) && areAllCallbacksFinished()) { executeCommand(); return; } } - Assert.fail("Failed callback " + callback + ": " + failureMessage + "[" - + throwable.getClass() + "]"); } - public final void finishOnSuccessOf(final AbstractAsyncCallback<Object> callback, - final Object result) + public final void onFailureOf(final IMessageProvider messageProvider, + final AbstractAsyncCallback<Object> callback, final String failureMessage, + final Throwable throwable) { detectCallback(callback); if (entryIndex < commands.size()) { ITestCommand cmd = commands.get(entryIndex); - // TODO 2009-11-09, Piotr Buczek: remove tryValidOnSuccess from command interface - List<AbstractAsyncCallback<Object>> unmatchedCallbacks = - cmd.tryValidOnSucess(lastCallbackObjects, result); - if (unmatchedCallbacks != null) - { - lastCallbackObjects = unmatchedCallbacks; - } - if (activeCallbacksCounter == 0) + // It doesn't need to be the last callbacks that fails, + // and it should rather be the last command. + if (cmd.isValidOnFailure(failureMessage, throwable)) { executeCommand(); return; } } + Assert.fail("Failed callback " + callback + ": " + failureMessage + "[" + + throwable.getClass() + "]"); } public void registerCallback(final AbstractAsyncCallback<?> callback) diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewerTest.java index 26fc3a55408..c6354ad4b35 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/plugin/generic/client/web/client/application/sample/GenericSampleViewerTest.java @@ -16,12 +16,9 @@ package ch.systemsx.cisd.openbis.plugin.generic.client.web.client.application.sample; -import java.util.List; - import com.extjs.gxt.ui.client.widget.grid.Grid; import com.google.gwt.user.client.ui.Widget; -import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback; import ch.systemsx.cisd.openbis.generic.client.web.client.application.menu.TopMenu.ActionMenuKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.data.CommonExternalDataColDefKind; import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.columns.specific.sample.CommonSampleColDefKind; @@ -131,19 +128,11 @@ public class GenericSampleViewerTest extends AbstractGWTTestCase final String commentColIdent = GridTestUtils.getPropertyColumnIdentifier("COMMENT", false); dataTable.expectedColumnHidden(commentColIdent, true); + remoteConsole.prepare(checkSample); remoteConsole.prepare(new AbstractDefaultTestCommand() { - @Override - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - List<AbstractAsyncCallback<Object>> callbackObjects, Object result) - { - return checkSample.tryValidOnSucess(callbackObjects, result); - } - public void execute() { - checkSample.execute(); - // show DataSet TechId wildcard = TechId.createWildcardTechId(); final Widget widget = @@ -179,19 +168,11 @@ public class GenericSampleViewerTest extends AbstractGWTTestCase dataTable.expectedRow(new DataSetRow(DIRECTLY_CONNECTED_DATA_SET_CODE).invalid() .withFileFormatType("TIFF").withSample(CELL_PLATE_EXAMPLE_ID).withExperiment( CELL_PLATE_EXAMPLE_EXPERIMENT_ID)); + remoteConsole.prepare(checkSample); remoteConsole.prepare(new AbstractDefaultTestCommand() { - @Override - public List<AbstractAsyncCallback<Object>> tryValidOnSucess( - List<AbstractAsyncCallback<Object>> callbackObjects, Object result) - { - return checkSample.tryValidOnSucess(callbackObjects, result); - } - public void execute() { - checkSample.execute(); - // show indirectly connected datasets TechId wildcard = TechId.createWildcardTechId(); -- GitLab