diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BehaviourTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BehaviourTest.java deleted file mode 100644 index e77dc8a92f..0000000000 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BehaviourTest.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.module.org_alfresco_module_rm.test.util.bdt; - -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.transaction.RetryingTransactionHelper; - -/** - * Helper class that provides an simple way to write behaviour integration tests. - *

- * Note that initBehaviourTest() must be called before given() is called. - * - * @author Roy Wetherall - * @since 2.5 - */ -public class BehaviourTest -{ - /** retrying transaction helper */ - private static RetryingTransactionHelper retryingTransactionHelper; - - /** current execution user */ - private String asUser = AuthenticationUtil.getAdminUserName(); - - /** - * Initialise behaviour tests for execution with retrying transaction helper - * - * @param retryingTransactionHelper retrying transaction helper - */ - public static void initBehaviourTests(RetryingTransactionHelper retryingTransactionHelper) - { - BehaviourTest.retryingTransactionHelper = retryingTransactionHelper; - } - - /** - * Start a test - * - * @return BehaviourTest new test instance - */ - public static BehaviourTest test() - { - return new BehaviourTest(); - } - - /** - * Helper method to get the retrying transaction helper - * - * @return RetryingTransactionHelper retrying transaction helper - */ - /*package*/ RetryingTransactionHelper getRetryingTransactionHelper() - { - return retryingTransactionHelper; - } - - /** - * Helper method to get the execution user - * - * @return String execution user - */ - /* package*/ String getAsUser() - { - return asUser; - } - - /** - * Helper method to switch the current execution user to admin. - * - * @return BehaviourTest test instance - */ - public BehaviourTest asAdmin() - { - return as(AuthenticationUtil.getAdminUserName()); - } - - /** - * Set execution user - * - * @param asUser execution user - * @return BehaviourTest test instance - */ - public BehaviourTest as(String asUser) - { - this.asUser = asUser; - return this; - } - - /** - * Given. - *

- * Used to group together given conditions. - * - * @return BehaviourTest test instance - */ - public BehaviourTest given() - { - return this; - } - - /** - * Given. - *

- * Performs work. - * - * @param given work to do - * @return BehaviourTest test instance - */ - public BehaviourTest given(Work given) - { - return perform(given); - } - - /** - * When. - *

- * Used to group together when actions. - * - * @return BehaviourTest test instance - */ - public BehaviourTest when() - { - return this; - } - - /** - * When. - *

- * Performs work. - * - * @param when work to do - * @return BehaviourTest test instance - */ - public BehaviourTest when(Work when) - { - return perform(when); - } - - /** - * Then. - *

- * Used to group together then actions. - * - * @return BehaviourTest test instance - */ - public BehaviourTest then() - { - return this; - } - - /** - * Then. - *

- * Performs work. - * - * @param then work to do - * @return BehaviourTest test instance - */ - public BehaviourTest then(Work then) - { - return perform(then); - } - - /** - * Expect a value. - * - * @param value value - * @return ExpectedValue expected value evaluator - */ - public ExpectedValue expect(boolean value) - { - return new ExpectedValue(this, value); - } - - /** - * Expect a value. - * - * @param value value - * @return ExpectedValue expected value evaluator - */ - public ExpectedValue expect(String value) - { - return new ExpectedValue(this, value); - } - - /** - * Expect a value. - * - * @param value value - * @return ExpectedValue expected value evaluator - */ - public ExpectedValue expect(Object value) - { - return new ExpectedValue(this, value); - } - - - /** - * Expect a failure. - * - * @param exceptionClass expected exception - * @return ExpectedFailure expected failure evaluator - */ - public ExpectedFailure expectException(Class exceptionClass) - { - return new ExpectedFailure(this, exceptionClass); - } - - /** - * Perform work a number of times - * - * @param count number of times to perform the work - * @param work work to perform - * @return BehaviourTest test instance - */ - public BehaviourTest perform(int count, Work work) - { - for (int i = 0; i < count; i++) - { - perform(work); - } - - return this; - } - - /** - * Perform work - * - * @param work work to perform - * @return BehaviourTest test instance - */ - public BehaviourTest perform(Work work) - { - return AuthenticationUtil.runAs(() -> - { - return retryingTransactionHelper.doInTransaction(() -> - { - work.doIt(); - return this; - }); - }, - this.asUser); - } - - /** - * Work Interface - */ - public interface Work - { - /** - * Do the work. - */ - void doIt() throws Exception; - } -} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedFailure.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedFailure.java deleted file mode 100644 index 9377402aaf..0000000000 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedFailure.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.module.org_alfresco_module_rm.test.util.bdt; - -import static org.junit.Assert.fail; - -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.Set; -import java.util.stream.Collectors; - -import org.alfresco.module.org_alfresco_module_rm.test.util.bdt.BehaviourTest.Work; - -/** - * Expected failure. - * - * @author Roy Wetherall - * @since 2.5 - */ -public class ExpectedFailure -{ - private static final String MESSAGE = "Expected failure \"{0}\" was not observed."; - - private BehaviourTest test; - private Set> exceptionClasses; - private Work work; - - @SafeVarargs - public ExpectedFailure(BehaviourTest test, Class ...exceptionClasses) - { - this.test = test; - this.exceptionClasses = Arrays.stream(exceptionClasses).collect(Collectors.toSet()); - } - - public ExpectedFailure from(Work work) - { - this.work = work; - return this; - } - - public BehaviourTest because(String message) - { - try - { - test.perform(work); - } - catch(Exception actualException) - { - boolean found = false; - - for (Class exceptionClass : exceptionClasses) - { - if (exceptionClass.isAssignableFrom(actualException.getClass())) - { - found = true; - } - } - - if (!found) - { - fail(MessageFormat.format(MESSAGE, message)); - } - } - - return test; - } - -} diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedValue.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedValue.java deleted file mode 100644 index dd72955d2c..0000000000 --- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/ExpectedValue.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * #%L - * Alfresco Records Management Module - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * - - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ -package org.alfresco.module.org_alfresco_module_rm.test.util.bdt; - -import static org.junit.Assert.assertEquals; - -import java.text.MessageFormat; - -import org.alfresco.repo.security.authentication.AuthenticationUtil; - -/** - * Expected value. - * - * @author Roy Wetherall - * @since 2.5 - */ -public class ExpectedValue -{ - private static final String MESSAGE = "Expected value outcome \"{0}\" was not observed."; - - private T expectedValue; - private Evaluation evaluation; - private BehaviourTest test; - - public ExpectedValue(BehaviourTest test, T value) - { - this.expectedValue = value; - this.test = test; - } - - public ExpectedValue from(Evaluation evaluation) - { - this.evaluation = evaluation; - return this; - } - - public BehaviourTest because(String message) - { - T actualValue = (T)AuthenticationUtil.runAs(() -> - { - return test.getRetryingTransactionHelper().doInTransaction(() -> - { - return evaluation.eval(); - }); - }, - test.getAsUser()); - - if (message != null) - { - message = MessageFormat.format(MESSAGE, message); - } - - assertEquals(message, expectedValue, actualValue); - - return test; - } - - public interface Evaluation - { - T eval() throws Exception; - } -}