diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToExperimentTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToExperimentTest.java index 02c9c6adce2ea722fbbd197ca3a23aa813530248..1307e34cceb84c0ebe540df5e34ad40b2e12d21d 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToExperimentTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToExperimentTest.java @@ -16,12 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToSampleTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToSampleTest.java index c8d58c4cff2ccf981fe5f7019cb65c9ffc2e35ba..2d85de0c6d928a05e48c22fd3470bee2b39df0ee 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToSampleTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignDataSetToSampleTest.java @@ -16,11 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignExperimentToProjectTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignExperimentToProjectTest.java index 63a885bf2e70f9ce141a786a85ec9af29daf6b37..e2522c1ce473c7ef27c87c151fe128626f27f950 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignExperimentToProjectTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignExperimentToProjectTest.java @@ -16,12 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignProjectToSpaceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignProjectToSpaceTest.java index 59df894887380594cd3488fc9b15c25534404d78..e44a811afa69e70bdf0d08b7141b62f1791cda26 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignProjectToSpaceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignProjectToSpaceTest.java @@ -16,11 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToExperimentTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToExperimentTest.java index 105cd684a54a5cb40a340e4f0031ba6e087bd57d..b477606ad2912bf0a686780e187d4a4d093af879 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToExperimentTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToExperimentTest.java @@ -16,12 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToSpaceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToSpaceTest.java index e21dbc42a36374fb10df7c30885e211134d685b7..487d4ff6f458f02c2d3e58a37aed6cc78927439f 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToSpaceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/AssignSampleToSpaceTest.java @@ -16,12 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/RelationshipServiceAuthorizationTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/RelationshipServiceAuthorizationTest.java index 3cf6bdb9c5c2bc1785ed22f62a9d4dc11d4443ae..2760656cbfeedeed4f8990010c1b7fdfc1a76f14 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/RelationshipServiceAuthorizationTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/RelationshipServiceAuthorizationTest.java @@ -16,11 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; - import org.springframework.test.context.ContextConfiguration; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; @@ -211,7 +206,7 @@ public class RelationshipServiceAuthorizationTest extends BaseTest } @Test(dataProvider = "rolesNotAllowedToShareSample", expectedExceptions = - { AuthorizationFailureException.class }) + { AuthorizationFailureException.class }, groups = "authorization") public void sharingSampleIsNotAuthorizedFor(RoleWithHierarchy spaceRole, RoleWithHierarchy instanceRole) throws Exception { diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromExperimentTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromExperimentTest.java index 90de4d413c5d384b11937f8eb1e9f46e2642ea9c..0e53fe126e31c7808f5441732da0e66041161254 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromExperimentTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromExperimentTest.java @@ -16,12 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromSpaceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromSpaceTest.java index 76ac83db177455721dcfa6355c9645b0efff5e18..87a0faad4141f5eae5d50ac42e5ab7a105f718b3 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromSpaceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UnassignSampleFromSpaceTest.java @@ -16,11 +16,7 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetContainmentTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetContainmentTest.java index 897274673a9de867bbe8de0a773e40058ebac0d8..ce1eb558858939b1dde1e7c7774d2bfae42c35fb 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetContainmentTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetContainmentTest.java @@ -16,10 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; -import static org.hamcrest.MatcherAssert.assertThat; - import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetParentsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetParentsTest.java index 7a8242a6b1bce0e7de20ded7a4e40a1a033c2687..218c615b5a9fab296b2cc447764544059b7e8ca5 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetParentsTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateDataSetParentsTest.java @@ -16,12 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; -import static org.hamcrest.MatcherAssert.assertThat; - import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleContainmentTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleContainmentTest.java index bd67f606d6b240b58daabd058150681ee23dd2b2..edfc5ff308469360d3ce62545f6e926f54829326 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleContainmentTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleContainmentTest.java @@ -16,12 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; -import static org.hamcrest.MatcherAssert.assertThat; - import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleParentsTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleParentsTest.java index 9972ef457ec24bd0c5181da93d75e8c1d70b9965..9b237a757727c43d22c7a151723121f215b686c2 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleParentsTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/UpdateSampleParentsTest.java @@ -16,12 +16,6 @@ package ch.systemsx.cisd.openbis.systemtest; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.and; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.not; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.or; -import static ch.systemsx.cisd.openbis.systemtest.base.auth.RuleBuilder.rule; -import static org.hamcrest.MatcherAssert.assertThat; - import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java index d8a6a9d6c8d18eebb6c59c6fcbecc783a1642f71..9a8641b0542e4bdfbc406fddfbed94939db53f03 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/BaseTest.java @@ -42,6 +42,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseInstance; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleParentWithDerived; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Space; @@ -54,6 +55,12 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier; import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SpaceIdentifier; import ch.systemsx.cisd.openbis.plugin.generic.client.web.client.IGenericClientService; import ch.systemsx.cisd.openbis.plugin.generic.shared.IGenericServer; +import ch.systemsx.cisd.openbis.systemtest.base.auth.AndAuthorizationRule; +import ch.systemsx.cisd.openbis.systemtest.base.auth.AuthorizationRule; +import ch.systemsx.cisd.openbis.systemtest.base.auth.BasicAuthorizationRule; +import ch.systemsx.cisd.openbis.systemtest.base.auth.GuardedDomain; +import ch.systemsx.cisd.openbis.systemtest.base.auth.NotAuthorizationRule; +import ch.systemsx.cisd.openbis.systemtest.base.auth.OrAuthorizationRule; import ch.systemsx.cisd.openbis.systemtest.base.builder.Builder; import ch.systemsx.cisd.openbis.systemtest.base.builder.DataSetUpdateBuilder; import ch.systemsx.cisd.openbis.systemtest.base.builder.ExperimentBuilder; @@ -293,87 +300,82 @@ public abstract class BaseTest extends AbstractTransactionalTestNGSpringContextT protected Matcher<Object> inSpace(Space space) { - return RefreshingMatcherProxy.newInstance(new InSpaceMatcher(space), this); + return new InSpaceMatcher(refresh(space)); } protected Matcher<Object> hasNoSpace() { - return RefreshingMatcherProxy.newInstance(new InSpaceMatcher(), this); + return new InSpaceMatcher(); } protected Matcher<Object> inExperiment(Experiment experiment) { - return RefreshingMatcherProxy.newInstance(new InExperimentMatcher(refresh(experiment)), - this); + return new InExperimentMatcher(refresh(experiment)); } protected Matcher<Object> hasNoExperiment() { - return RefreshingMatcherProxy.newInstance(new InExperimentMatcher(), this); + return new InExperimentMatcher(); } protected Matcher<Experiment> inProject(Project project) { - return RefreshingMatcherProxy.newInstance(new InProjectMatcher(refresh(project)), this); + return new InProjectMatcher(refresh(project)); } protected Matcher<ExternalData> inSample(Sample sample) { - return RefreshingMatcherProxy.newInstance(new InSampleMatcher(refresh(sample)), this); + return new InSampleMatcher(refresh(sample)); } protected Matcher<ExternalData> hasParents(ExternalData first, ExternalData... rest) { - return RefreshingMatcherProxy.newInstance(new ExternalDataHasParentsMatcher(first, rest), - this); + return new ExternalDataHasParentsMatcher(refresh(first), refresh(rest)); } protected Matcher<ExternalData> hasChildren(ExternalData first, ExternalData... rest) { - return RefreshingMatcherProxy.newInstance(new ExternalDataHasChildrenMatcher(first, rest), - this); + return new ExternalDataHasChildrenMatcher(refresh(first), refresh(rest)); } protected Matcher<Object> hasNoParents() { - return RefreshingMatcherProxy.newInstance(new HasNoParentMatcher(), this); + return new HasNoParentMatcher(); } protected Matcher<ExternalData> hasNoChildren() { - return RefreshingMatcherProxy.newInstance(new HasNoChildrenMatcher(), this); + return new HasNoChildrenMatcher(); } protected Matcher<ExternalData> hasNoSample() { - return RefreshingMatcherProxy.newInstance(new ExternalDataHasNoSampleMatcher(), this); + return new ExternalDataHasNoSampleMatcher(); } protected Matcher<Sample> hasParents(Sample first, Sample... rest) { - return RefreshingMatcherProxy.newInstance(new SampleHasParentsMatcher(first, rest), this); + return new SampleHasParentsMatcher(refresh(first), refresh(rest)); } protected Matcher<Object> hasNoParent() { - return RefreshingMatcherProxy.newInstance(new HasNoParentMatcher(), this); + return new HasNoParentMatcher(); } protected Matcher<Sample> hasContainer(Sample container) { - return RefreshingMatcherProxy.newInstance( - new SampleHasContainerMatcher(refresh(container)), this); + return new SampleHasContainerMatcher(refresh(container)); } protected Matcher<ExternalData> hasContainer(ExternalData container) { - return RefreshingMatcherProxy.newInstance(new ExternalDataHasContainerMatcher( - refresh(container)), this); + return new ExternalDataHasContainerMatcher(refresh(container)); } protected Matcher<Object> hasNoContainer() { - return RefreshingMatcherProxy.newInstance(new HasNoContainerMatcher(), this); + return new HasNoContainerMatcher(); } protected Experiment refresh(Experiment experiment) @@ -393,11 +395,48 @@ public abstract class BaseTest extends AbstractTransactionalTestNGSpringContextT return result.getParent(); } + protected Sample[] refresh(Sample[] samples) + { + Sample[] result = new Sample[samples.length]; + int i = 0; + for (Sample sample : samples) + { + result[i] = refresh(sample); + i++; + } + return result; + } + + protected ExternalData[] refresh(ExternalData[] dataSets) + { + ExternalData[] result = new ExternalData[dataSets.length]; + int i = 0; + for (ExternalData data : dataSets) + { + result[i] = refresh(data); + i++; + } + return result; + } + protected ExternalData refresh(ExternalData data) { return etlService.tryGetDataSet(systemSessionToken, data.getCode()); } + protected Space refresh(Space space) + { + for (Space refreshed : commonServer.listSpaces(systemSessionToken, + new DatabaseInstanceIdentifier("CISD"))) + { + if (space.getId() == refreshed.getId()) + { + return space; + } + } + throw new IllegalArgumentException("Space not found: " + space.getCode()); + } + public static ExperimentIdentifier id(Experiment experiment) { return new ExperimentIdentifier(id(experiment.getProject()), experiment.getCode()); @@ -428,4 +467,61 @@ public abstract class BaseTest extends AbstractTransactionalTestNGSpringContextT return new SampleIdentifier(id(sample.getSpace()), sample.getCode()); } } + + @SuppressWarnings("unchecked") + @Test(enabled = false) + public <T> void assertThat(T actual, Matcher<T> matcher) + { + T refreshed = actual; + if (actual instanceof ExternalData) + { + refreshed = (T) refresh((ExternalData) actual); + } else if (actual instanceof Sample) + { + refreshed = (T) refresh((Sample) actual); + } else if (actual instanceof Experiment) + { + refreshed = (T) refresh((Experiment) actual); + } else if (actual instanceof Project) + { + refreshed = (T) refresh((Project) actual); + } else if (actual instanceof Space) + { + refreshed = (T) refresh((Space) actual); + } + + org.hamcrest.MatcherAssert.assertThat(refreshed, matcher); + } + + public static AuthorizationRule rule(GuardedDomain domain, RoleWithHierarchy role) + { + return new BasicAuthorizationRule(domain, role); + } + + public static AuthorizationRule and(AuthorizationRule rule1, AuthorizationRule rule2, + AuthorizationRule... rest) + { + AuthorizationRule main = new AndAuthorizationRule(rule1, rule2); + for (AuthorizationRule rule : rest) + { + main = new AndAuthorizationRule(main, rule); + } + return main; + } + + public static AuthorizationRule or(AuthorizationRule rule1, AuthorizationRule rule2, + AuthorizationRule... rest) + { + AuthorizationRule main = new OrAuthorizationRule(rule1, rule2); + for (AuthorizationRule rule : rest) + { + main = new OrAuthorizationRule(main, rule); + } + return main; + } + + public static AuthorizationRule not(AuthorizationRule rule) + { + return new NotAuthorizationRule(rule); + } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/EqualityChecker.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/EqualityChecker.java deleted file mode 100644 index 3ad6681b59823956f7f46fd41c59a41603a05aa7..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/EqualityChecker.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base; - -/** - * @author anttil - */ -public interface EqualityChecker<T> -{ - public boolean equals(T a, T b); -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/ExternalDataEqualityChecker.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/ExternalDataEqualityChecker.java deleted file mode 100644 index 56520659bdc59a9f6b6d5c5bd1618d085ca03083..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/ExternalDataEqualityChecker.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base; - -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; - -/** - * @author anttil - */ -public class ExternalDataEqualityChecker implements EqualityChecker<ExternalData> -{ - - @Override - public boolean equals(ExternalData a, ExternalData b) - { - return a.getCode().equals(b.getCode()); - } - -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/RefreshingMatcherProxy.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/RefreshingMatcherProxy.java deleted file mode 100644 index cf7c90e55cd0e16b31f97d46a5112c216cbdc521..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/RefreshingMatcherProxy.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.HashSet; - -import org.hamcrest.Matcher; - -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Experiment; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ExternalData; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Project; -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; - -/** - * @author anttil - */ -public class RefreshingMatcherProxy implements InvocationHandler -{ - - @SuppressWarnings("unchecked") - static <T extends Matcher<?>> T newInstance(T actualMatcher, BaseTest b) - { - - Collection<Class<?>> interfaces = new HashSet<Class<?>>(); - interfaces.add(Matcher.class); - return (T) java.lang.reflect.Proxy.newProxyInstance( - actualMatcher.getClass().getClassLoader(), - interfaces.toArray(new Class<?>[0]), - new RefreshingMatcherProxy(actualMatcher, b)); - } - - private Matcher<?> matcher; - - private BaseTest b; - - public RefreshingMatcherProxy(Matcher<?> matcher, BaseTest b) - { - this.matcher = matcher; - this.b = b; - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable - { - if (method.getName().equals("matches") && args.length == 1) - { - Object arg = args[0]; - if (arg instanceof ExternalData) - { - args[0] = b.refresh((ExternalData) arg); - } else if (arg instanceof Sample) - { - args[0] = b.refresh((Sample) arg); - } else if (arg instanceof Experiment) - { - args[0] = b.refresh((Experiment) arg); - } else if (arg instanceof Project) - { - args[0] = b.refresh((Project) arg); - } else - { - throw new IllegalArgumentException("Illegal matching: " + arg); - } - } - - return method.invoke(this.matcher, args); - } -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/StandardEqualityChecker.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/StandardEqualityChecker.java deleted file mode 100644 index b07df0f4e87efebafb3780ccd0db5562ac37afab..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/StandardEqualityChecker.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base; - -/** - * @author anttil - */ -public class StandardEqualityChecker<T> implements EqualityChecker<T> -{ - - @Override - public boolean equals(T a, T b) - { - return a.equals(b); - } - -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/auth/RuleBuilder.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/auth/RuleBuilder.java deleted file mode 100644 index 13d4ef2ad43ba2bba596ca9e87f7280627427279..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/auth/RuleBuilder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base.auth; - -import ch.systemsx.cisd.openbis.generic.shared.basic.dto.RoleWithHierarchy; - -/** - * @author anttil - */ -public class RuleBuilder -{ - - public static AuthorizationRule rule(GuardedDomain domain, RoleWithHierarchy role) - { - return new BasicAuthorizationRule(domain, role); - } - - public static AuthorizationRule and(AuthorizationRule rule1, AuthorizationRule rule2, - AuthorizationRule... rest) - { - AuthorizationRule main = new AndAuthorizationRule(rule1, rule2); - for (AuthorizationRule rule : rest) - { - main = new AndAuthorizationRule(main, rule); - } - return main; - } - - public static AuthorizationRule or(AuthorizationRule rule1, AuthorizationRule rule2, - AuthorizationRule... rest) - { - AuthorizationRule main = new OrAuthorizationRule(rule1, rule2); - for (AuthorizationRule rule : rest) - { - main = new OrAuthorizationRule(main, rule); - } - return main; - } - - public static AuthorizationRule not(AuthorizationRule rule) - { - return new NotAuthorizationRule(rule); - } - -} diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/matcher/CollectionContainsExactlyMatcher.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/matcher/CollectionContainsExactlyMatcher.java deleted file mode 100644 index a1891e4b6536895b9e0761d5a972c0c67832d27b..0000000000000000000000000000000000000000 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/matcher/CollectionContainsExactlyMatcher.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2012 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.systemtest.base.matcher; - -import java.util.Collection; -import java.util.HashSet; - -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; - -import ch.systemsx.cisd.openbis.systemtest.base.EqualityChecker; - -public class CollectionContainsExactlyMatcher<T> extends TypeSafeMatcher<Collection<T>> -{ - - private EqualityChecker<T> equalityChecker; - - private Collection<T> expected; - - public CollectionContainsExactlyMatcher(EqualityChecker<T> equalityChecker, T... elements) - { - this.equalityChecker = equalityChecker; - expected = new HashSet<T>(); - for (T t : elements) - { - expected.add(t); - } - } - - @Override - public void describeTo(Description description) - { - description.appendText("A collection containing exactly these elements: " + expected); - } - - @Override - public boolean matchesSafely(Collection<T> actual) - { - if (actual == null) - { - return false; - } - - if (actual.size() != expected.size()) - { - return false; - } - - for (T t : actual) - { - int count = 0; - for (T e : this.expected) - { - if (this.equalityChecker.equals(t, e)) - { - count++; - } - } - if (count != 1) - { - return false; - } - } - return true; - } - -} \ No newline at end of file