From d050d5b15705d5557b29d7aea8ca419fa51013e3 Mon Sep 17 00:00:00 2001 From: anttil <anttil> Date: Fri, 13 Jul 2012 09:26:23 +0000 Subject: [PATCH] BIS-51 / SP-174: test cleanup SVN: 26104 --- .../AssignDataSetToExperimentTest.java | 5 - .../systemtest/AssignDataSetToSampleTest.java | 4 - .../AssignExperimentToProjectTest.java | 5 - .../systemtest/AssignProjectToSpaceTest.java | 4 - .../AssignSampleToExperimentTest.java | 5 - .../systemtest/AssignSampleToSpaceTest.java | 5 - .../RelationshipServiceAuthorizationTest.java | 7 +- .../UnassignSampleFromExperimentTest.java | 5 - .../UnassignSampleFromSpaceTest.java | 4 - .../UpdateDataSetContainmentTest.java | 4 - .../systemtest/UpdateDataSetParentsTest.java | 6 - .../UpdateSampleContainmentTest.java | 6 - .../systemtest/UpdateSampleParentsTest.java | 6 - .../openbis/systemtest/base/BaseTest.java | 138 +++++++++++++++--- .../systemtest/base/EqualityChecker.java | 25 ---- .../base/ExternalDataEqualityChecker.java | 33 ----- .../base/RefreshingMatcherProxy.java | 85 ----------- .../base/StandardEqualityChecker.java | 31 ---- .../systemtest/base/auth/RuleBuilder.java | 59 -------- .../CollectionContainsExactlyMatcher.java | 81 ---------- 20 files changed, 118 insertions(+), 400 deletions(-) delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/EqualityChecker.java delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/ExternalDataEqualityChecker.java delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/RefreshingMatcherProxy.java delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/StandardEqualityChecker.java delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/auth/RuleBuilder.java delete mode 100644 openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/base/matcher/CollectionContainsExactlyMatcher.java 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 02c9c6adce2..1307e34cceb 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 c8d58c4cff2..2d85de0c6d9 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 63a885bf2e7..e2522c1ce47 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 59df8948873..e44a811afa6 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 105cd684a54..b477606ad29 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 e21dbc42a36..487d4ff6f45 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 3cf6bdb9c5c..2760656cbfe 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 90de4d413c5..0e53fe126e3 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 76ac83db177..87a0faad414 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 897274673a9..ce1eb558858 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 7a8242a6b1b..218c615b5a9 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 bd67f606d6b..edfc5ff3084 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 9972ef457ec..9b237a75772 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 d8a6a9d6c8d..9a8641b0542 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 3ad6681b598..00000000000 --- 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 56520659bdc..00000000000 --- 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 cf7c90e55cd..00000000000 --- 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 b07df0f4e87..00000000000 --- 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 13d4ef2ad43..00000000000 --- 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 a1891e4b653..00000000000 --- 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 -- GitLab