Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Barbin2017-07-24 07:38:24 +0000
committerLaurent Fasani2017-08-04 14:19:57 +0000
commit1d84b063132e8896a141b730c8ad55081cf88ab6 (patch)
treebd2ae8458ed13b535f035b6bceade623a979e50d
parent85f6183981e19ff0d57031cc90d7bdb83a2aa9ed (diff)
downloadorg.eclipse.sirius-1d84b063132e8896a141b730c8ad55081cf88ab6.tar.gz
org.eclipse.sirius-1d84b063132e8896a141b730c8ad55081cf88ab6.tar.xz
org.eclipse.sirius-1d84b063132e8896a141b730c8ad55081cf88ab6.zip
[516669] Adds a JUnit test to check the DRepresentationLocationManager
This test checks the DRepresentationLocationManager independently with the CreateRepresentationInSeparateResource option activated or not. It also checks if the DRepresentationLocationManager is properly integrated when creating a new representation from API. Bug: 516669 Change-Id: I286eab96aba5b6514671e996ac325c71409b3cbd Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/TestsUtil.java118
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java2
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/representation/DRepresentationLocationManagerTest.java209
4 files changed, 270 insertions, 60 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/TestsUtil.java b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/TestsUtil.java
index 98780814f5..36c5c71a76 100644
--- a/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/TestsUtil.java
+++ b/plugins/org.eclipse.sirius.tests.junit.support/src/org/eclipse/sirius/tests/support/api/TestsUtil.java
@@ -48,7 +48,9 @@ public final class TestsUtil {
private static final String UI_WORKBENCH_LUNA_START = "3.106";
private static final String UI_WORKBENCH_OXYGEN_START = "3.110";
-
+
+ private static final String CREATE_REPRESENTATATION_IN_SEPARATE_RESOURCE = "createLocalRepresentationInSeparateResource";
+
/**
* Constructor.
*/
@@ -57,9 +59,8 @@ public final class TestsUtil {
}
/**
- * Wait the end of the asynchronous calls in UI Thread and ignore the
- * Exception. <B>Use this exclusively</B> in the setup method to ensure a
- * clean environment.
+ * Wait the end of the asynchronous calls in UI Thread and ignore the Exception. <B>Use this exclusively</B> in the
+ * setup method to ensure a clean environment.
*/
public static void emptyEventsFromUIThread() {
boolean shouldRetry = false;
@@ -85,10 +86,9 @@ public final class TestsUtil {
}
/**
- * Tests whether the environment is configured to skip non-critical tests
- * which take a long time. This possibility to skip some tests should only
- * be used on developer machines to get faster feedback, and never on a
- * continuous integration server.
+ * Tests whether the environment is configured to skip non-critical tests which take a long time. This possibility
+ * to skip some tests should only be used on developer machines to get faster feedback, and never on a continuous
+ * integration server.
*
* @return <code>true</code> if the environment is setup to skip long tests.
*/
@@ -97,8 +97,7 @@ public final class TestsUtil {
}
/**
- * Tests whether unreliable tests should be run. See
- * {@link #shouldSkipUnreliableTests()}. Can be used in tests as:
+ * Tests whether unreliable tests should be run. See {@link #shouldSkipUnreliableTests()}. Can be used in tests as:
*
* <pre>
* Assume.assumeTrue(TestUtil.shouldRunUnreliableTests())
@@ -113,19 +112,17 @@ public final class TestsUtil {
}
/**
- * Tests whether the environment is configured to skip tests which are known
- * to be unreliable (i.e. they sometimes work, sometimes fail).
+ * Tests whether the environment is configured to skip tests which are known to be unreliable (i.e. they sometimes
+ * work, sometimes fail).
*
- * @return <code>true</code> if the environment is setup to skip unreliable
- * tests.
+ * @return <code>true</code> if the environment is setup to skip unreliable tests.
*/
public static boolean shouldSkipUnreliableTests() {
return "true".equals(System.getProperty("org.eclipse.sirius.tests.skipUnreliableTests"));
}
/**
- * Tests whether long running tests should be run. See
- * {@link #shouldSkipLongTests()}. Can be used in tests as:
+ * Tests whether long running tests should be run. See {@link #shouldSkipLongTests()}. Can be used in tests as:
*
* <pre>
* Assume.assumeTrue(TestUtil.shouldRunLongTests())
@@ -140,10 +137,31 @@ public final class TestsUtil {
}
/**
+ * Whether the createLocalRepresentationInSeparateResource system property is set at true or not.
+ *
+ * @return true if createLocalRepresentationInSeparateResource property is set at true, otherwise false.
+ */
+ public static boolean isCreateRepresentationInSeparateResource() {
+ return Boolean.getBoolean(CREATE_REPRESENTATATION_IN_SEPARATE_RESOURCE);
+ }
+
+ /**
+ * Change the createLocalRepresentationInSeparateResource system property.
+ *
+ * @param value
+ * the value
+ *
+ * @return the previous value
+ */
+ public static boolean setCreateRepresentationInSeparateResource(boolean value) {
+ String property = System.setProperty(CREATE_REPRESENTATATION_IN_SEPARATE_RESOURCE, String.valueOf(value));
+ return Boolean.valueOf(property);
+ }
+
+ /**
* Tests if the EEF-based properties view support is installed.
*
- * @return <code>true</code> if the EEF-based properties view support is
- * installed.
+ * @return <code>true</code> if the EEF-based properties view support is installed.
*/
public static boolean isEEFBasedPropertiesViewsSupportInstalled() {
return Platform.getBundle("org.eclipse.sirius.ui.properties") != null;
@@ -152,8 +170,7 @@ public final class TestsUtil {
/**
* Tells if the current platform corresponds to juno3 (i.e. Eclipse 3.8).
*
- * @return true if the current platform corresponds to juno3 (i.e. Eclipse
- * 3.8), false else
+ * @return true if the current platform corresponds to juno3 (i.e. Eclipse 3.8), false else
*/
public static boolean isJuno3Platform() {
boolean isJuno3Platform = false;
@@ -165,11 +182,9 @@ public final class TestsUtil {
}
/**
- * Tells if the current platform corresponds to Juno, Kepler, Luna, .. (i.e.
- * Eclipse 4.x).
+ * Tells if the current platform corresponds to Juno, Kepler, Luna, .. (i.e. Eclipse 4.x).
*
- * @return true if the current platform corresponds to eclipse 4.x, false
- * otherwise.
+ * @return true if the current platform corresponds to eclipse 4.x, false otherwise.
*/
public static boolean isEclipse4xPlatform() {
Version junoStart = Version.parseVersion(UI_WORKBENCH_JUNO_START);
@@ -179,8 +194,7 @@ public final class TestsUtil {
/**
* Tells if the current platform corresponds to Juno (i.e. Eclipse 4.x).
*
- * @return true if the current platform corresponds to Juno 4.x, false
- * otherwise.
+ * @return true if the current platform corresponds to Juno 4.x, false otherwise.
*/
public static boolean isJuno4Platform() {
Version junoStart = Version.parseVersion(UI_WORKBENCH_JUNO_START);
@@ -190,8 +204,8 @@ public final class TestsUtil {
private static boolean checkUiWorkbenchVersion(Version versiontStart, Version versionEnd) {
/*
- * Juno/Kepler Core Runtime plugins version are 3.8/3.9 and not 4.x. So
- * the "org.eclipse.ui.workbench" is used instead.
+ * Juno/Kepler Core Runtime plugins version are 3.8/3.9 and not 4.x. So the "org.eclipse.ui.workbench" is used
+ * instead.
*/
Bundle uiWorkbenchBundle = Platform.getBundle("org.eclipse.ui.workbench");
if (uiWorkbenchBundle != null) {
@@ -203,8 +217,7 @@ public final class TestsUtil {
/**
* Tells if the current platform corresponds to Kepler.
*
- * @return true if the current platform corresponds to Kepler, false
- * otherwise.
+ * @return true if the current platform corresponds to Kepler, false otherwise.
*/
public static boolean isKeplerPlatform() {
Version keplerStart = Version.parseVersion(UI_WORKBENCH_KEPLER_START);
@@ -215,32 +228,26 @@ public final class TestsUtil {
/**
* Tells if the current platform corresponds to Luna.
*
- * @return true if the current platform corresponds to Luna, false
- * otherwise.
+ * @return true if the current platform corresponds to Luna, false otherwise.
*/
public static boolean isLunaPlatform() {
return checkUiWorkbenchVersion(Version.parseVersion(UI_WORKBENCH_LUNA_START), null);
}
-
+
/**
* Tells if the current platform corresponds to Oxygen or later.
*
- * @return true if the current platform corresponds to Oxygen or later, false
- * otherwise.
+ * @return true if the current platform corresponds to Oxygen or later, false otherwise.
*/
public static boolean isOxygenPlatform() {
return checkUiWorkbenchVersion(Version.parseVersion(UI_WORKBENCH_OXYGEN_START), null);
}
-
/**
- * Copied and adapted from
- * org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long,
- * long)
+ * Copied and adapted from org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long, long)
*
- * Waits until the condition has been meet, or the timeout is reached. The
- * interval is the delay between evaluating the condition after it has
- * failed.
+ * Waits until the condition has been meet, or the timeout is reached. The interval is the delay between evaluating
+ * the condition after it has failed.
*
* @param condition
* the condition to be evaluated.
@@ -276,13 +283,10 @@ public final class TestsUtil {
}
/**
- * Copied and adapted from
- * org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long,
- * long)
+ * Copied and adapted from org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long, long)
*
- * Waits until the condition has been meet, or the timeout is reached. The
- * interval is the delay between evaluating the condition after it has
- * failed.
+ * Waits until the condition has been meet, or the timeout is reached. The interval is the delay between evaluating
+ * the condition after it has failed.
*
* Interval : 500
*
@@ -296,13 +300,10 @@ public final class TestsUtil {
}
/**
- * Copied and adapted from
- * org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long,
- * long)
+ * Copied and adapted from org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntil(ICondition, long, long)
*
- * Waits until the condition has been meet, or the timeout is reached. The
- * interval is the delay between evaluating the condition after it has
- * failed.
+ * Waits until the condition has been meet, or the timeout is reached. The interval is the delay between evaluating
+ * the condition after it has failed.
*
* Timeout: 5000 Interval : 500
*
@@ -314,15 +315,12 @@ public final class TestsUtil {
}
/**
- * Sets a target platform in the test platform to get workspace builds OK
- * with PDE.<BR>
- * Copied and adpated from
- * http://git.eclipse.org/c/gmf-tooling/org.eclipse.gmf-tooling.git/tree/
+ * Sets a target platform in the test platform to get workspace builds OK with PDE.<BR>
+ * Copied and adpated from http://git.eclipse.org/c/gmf-tooling/org.eclipse.gmf-tooling.git/tree/
* tests/org.eclipse.gmf.tests/src/org/eclipse/gmf/tests/Utils.java
*
* @throws CoreException
- * In case of problem to retrieve current target platform or to
- * save the new one.
+ * In case of problem to retrieve current target platform or to save the new one.
* @throws InterruptedException
* if the loading platform job is interrupted while waiting
*/
diff --git a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
index 07c9058d55..86cad65a35 100644
--- a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
@@ -110,6 +110,7 @@ Export-Package: org.eclipse.sirius.tests,
org.eclipse.sirius.tests.unit.api.modelingproject,
org.eclipse.sirius.tests.unit.api.navigator,
org.eclipse.sirius.tests.unit.api.refresh,
+ org.eclipse.sirius.tests.unit.api.representation,
org.eclipse.sirius.tests.unit.api.resource,
org.eclipse.sirius.tests.unit.api.routing,
org.eclipse.sirius.tests.unit.api.semantic,
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
index 2d766c1f8f..6c0139c14d 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
@@ -37,6 +37,7 @@ import org.eclipse.sirius.tests.unit.api.modelingproject.SemanticResourcesManage
import org.eclipse.sirius.tests.unit.api.navigator.GroupingContentProviderByContainingTest;
import org.eclipse.sirius.tests.unit.api.navigator.GroupingContentProviderTest;
import org.eclipse.sirius.tests.unit.api.refresh.ModifyHeaderLabelExpressionTest;
+import org.eclipse.sirius.tests.unit.api.representation.DRepresentationLocationManagerTest;
import org.eclipse.sirius.tests.unit.api.resource.ResourceStrategyForUmlTests;
import org.eclipse.sirius.tests.unit.api.resource.ResourceStrategyTests;
import org.eclipse.sirius.tests.unit.api.resource.SemanticResourceURIInAirdTests;
@@ -331,6 +332,7 @@ public class AllCommonPluginTests extends TestCase {
suite.addTestSuite(ResourceStrategyForUmlTests.class);
suite.addTestSuite(OpenSessionTest.class);
suite.addTestSuite(ModelAccessorLifecycleTest.class);
+ suite.addTestSuite(DRepresentationLocationManagerTest.class);
suite.addTestSuite(SubMenusPrioritiesTest.class);
suite.addTestSuite(ZombieViewpointsTest.class);
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/representation/DRepresentationLocationManagerTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/representation/DRepresentationLocationManagerTest.java
new file mode 100644
index 0000000000..15b9dad35a
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/representation/DRepresentationLocationManagerTest.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.unit.api.representation;
+
+import java.util.Collections;
+import java.util.function.Predicate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.sirius.business.internal.representation.DRepresentationLocationManager;
+import org.eclipse.sirius.business.internal.resource.SiriusRepresentationXMIResourceImpl;
+import org.eclipse.sirius.diagram.DDiagram;
+import org.eclipse.sirius.diagram.DiagramFactory;
+import org.eclipse.sirius.diagram.description.DescriptionFactory;
+import org.eclipse.sirius.diagram.description.DiagramDescription;
+import org.eclipse.sirius.table.metamodel.table.DTable;
+import org.eclipse.sirius.table.metamodel.table.TableFactory;
+import org.eclipse.sirius.table.metamodel.table.description.TableDescription;
+import org.eclipse.sirius.tests.SiriusTestsPlugin;
+import org.eclipse.sirius.tests.support.api.SiriusTestCase;
+import org.eclipse.sirius.tests.support.api.TestsUtil;
+import org.eclipse.sirius.tests.unit.diagram.GenericTestCase;
+import org.eclipse.sirius.tree.DTree;
+import org.eclipse.sirius.tree.TreeFactory;
+import org.eclipse.sirius.tree.description.TreeDescription;
+import org.eclipse.sirius.viewpoint.DRepresentation;
+
+/**
+ * Test class to check the {@link DRepresentationLocationManager} behavior with the DRepLocationRuleForLocalResource
+ * extension.
+ *
+ * @author fbarbin
+ *
+ */
+public class DRepresentationLocationManagerTest extends GenericTestCase {
+
+ private boolean oldPropertyValue;
+
+ private static final String EXPECTED_SRM_PATH = SiriusTestCase.TEMPORARY_PROJECT_NAME + "/.representations/";
+
+ private static final String PATH = "/data/unit/session/open/";
+
+ private static final String SEMANTIC_MODEL_FILENAME = "test.ecore";
+
+ private static final String SEMANTIC_MODEL_FILENAME_PATH = TEMPORARY_PROJECT_NAME + "/" + SEMANTIC_MODEL_FILENAME;
+
+ protected static final String MODELER_PATH = "org.eclipse.sirius.sample.ecore.design/description/ecore.odesign";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, PATH, SEMANTIC_MODEL_FILENAME);
+ genericSetUp(SEMANTIC_MODEL_FILENAME_PATH, Collections.emptyList());
+ oldPropertyValue = TestsUtil.isCreateRepresentationInSeparateResource();
+ }
+
+ /**
+ * Test the LocationManager With representations in the aird resource.
+ */
+ public void testDRepresentationLocationManagerWithSplitDeactivated() {
+ TestsUtil.setCreateRepresentationInSeparateResource(false);
+
+ // We test that even with forbidden URI characters in the description name, the URI will be properly normalized.
+ String descriptionName = "desc?-|ri ption";
+ Predicate<Resource> predicate = (r) -> {
+ return session.getSessionResource().equals(r);
+ };
+ checkDRepresentationLocationManager(descriptionName, DDiagram.class, predicate, session.getSessionResource());
+ checkDRepresentationLocationManager(descriptionName, DTable.class, predicate, session.getSessionResource());
+ checkDRepresentationLocationManager(descriptionName, DTree.class, predicate, session.getSessionResource());
+ }
+
+ /**
+ * Test the LocationManager With representations separates in different resources.
+ */
+ public void testDRepresentationLocationManagerWithSplitActivated() {
+ TestsUtil.setCreateRepresentationInSeparateResource(true);
+
+ // We test that even with forbidden URI characters in the description name, the URI will be properly normalized.
+ String descriptionName = "desc?-|ri ption";
+ String pattern = URI.createPlatformResourceURI(EXPECTED_SRM_PATH + descriptionName, true) + "_.*.srm";
+
+ // We create several representations to make sure they have a different Resource URI from the previous one.
+ URI previousURI = checkDRepresentationLocationManager(descriptionName, DDiagram.class, new ResourceNamePredicate(pattern, null, SiriusRepresentationXMIResourceImpl.class),
+ session.getSessionResource());
+ previousURI = checkDRepresentationLocationManager(descriptionName, DTable.class, new ResourceNamePredicate(pattern, previousURI, SiriusRepresentationXMIResourceImpl.class),
+ session.getSessionResource());
+ previousURI = checkDRepresentationLocationManager(descriptionName, DDiagram.class, new ResourceNamePredicate(pattern, previousURI, SiriusRepresentationXMIResourceImpl.class),
+ session.getSessionResource());
+ checkDRepresentationLocationManager(descriptionName, DTree.class, new ResourceNamePredicate(pattern, previousURI, SiriusRepresentationXMIResourceImpl.class), session.getSessionResource());
+
+ }
+
+ /**
+ * Test that the {@link DRepresentationLocationManager} is properly integrated in the context of the creation of a
+ * representation by using Sirius API.
+ *
+ * @throws Exception
+ * if an error occurs while trying to load the VSM.
+ */
+ public void testDRepresentationLocationManagerIntegration() throws Exception {
+ TestsUtil.setCreateRepresentationInSeparateResource(true);
+ loadModeler(toURI(MODELER_PATH, ResourceURIType.RESOURCE_PLUGIN_URI), session.getTransactionalEditingDomain());
+ initViewpoint("Design");
+ Resource semanticResource = session.getSemanticResources().iterator().next();
+ DRepresentation dRepresentation = createRepresentation("Entities", semanticResource.getContents().get(0));
+ String pattern = URI.createPlatformResourceURI(EXPECTED_SRM_PATH + "Entities_" + dRepresentation.getUid() + ".srm", true).toString();
+ Predicate<Resource> predicate = new ResourceNamePredicate(pattern, null, SiriusRepresentationXMIResourceImpl.class);
+ assertTrue("Unexpected resource URI for the new created representation", predicate.test(dRepresentation.eResource()));
+ }
+
+ /**
+ * Create a new sample representation of type "representationType" with a Description "descriptionName". Test the
+ * DRepresentationLocationManager with this representation in the context of the given sessionResource.
+ *
+ * @param descriptionName
+ * the description name.
+ * @param representationType
+ * the type of the representation to create.
+ * @param expectedResult
+ * the predicate that will check the result of the location manager.
+ * @param sessionResource
+ * the main session resource.
+ * @return the resource URI that hold the created representation.
+ */
+ public static URI checkDRepresentationLocationManager(String descriptionName, Class<? extends DRepresentation> representationType, Predicate<Resource> expectedResult, Resource sessionResource) {
+ DRepresentationLocationManager locationManager = new DRepresentationLocationManager();
+ DRepresentation dRepresentation = createSampleDRepresentation(descriptionName, DDiagram.class);
+ Resource resource = locationManager.getOrCreateRepresentationResource(dRepresentation, sessionResource);
+ assertTrue("Unexpected resource location (" + resource.getURI() + ") for representation of type " + descriptionName, expectedResult.test(resource));
+ return resource.getURI();
+
+ }
+
+ private static DRepresentation createSampleDRepresentation(String descriptionName, Class<? extends DRepresentation> clazz) {
+ DRepresentation representation = null;
+ if (DDiagram.class.equals(clazz)) {
+ representation = DiagramFactory.eINSTANCE.createDSemanticDiagram();
+ DiagramDescription description = DescriptionFactory.eINSTANCE.createDiagramDescription();
+ description.setName(descriptionName);
+ ((DDiagram) representation).setDescription(description);
+
+ } else if (DTree.class.equals(clazz)) {
+ representation = TreeFactory.eINSTANCE.createDTree();
+ TreeDescription description = org.eclipse.sirius.tree.description.DescriptionFactory.eINSTANCE.createTreeDescription();
+ description.setName(descriptionName);
+ ((DTree) representation).setDescription(description);
+ } else if (DTable.class.equals(clazz)) {
+ representation = TableFactory.eINSTANCE.createDTable();
+ TableDescription description = org.eclipse.sirius.table.metamodel.table.description.DescriptionFactory.eINSTANCE.createCrossTableDescription();
+ description.setName(descriptionName);
+ ((DTable) representation).setDescription(description);
+ }
+ return representation;
+ }
+
+ /**
+ * This predicate tests whether the resource URI matches the given pattern and is different from the previous one.
+ *
+ * @author fbarbin
+ *
+ */
+ public class ResourceNamePredicate implements Predicate<Resource> {
+
+ private String patternString;
+
+ private URI previousURI;
+
+ private Class<? extends Resource> resourceType;
+
+ public ResourceNamePredicate(String pattern, URI previousURI, Class<? extends Resource> resourceType) {
+ this.previousURI = previousURI;
+ this.patternString = pattern;
+ this.resourceType = resourceType;
+ }
+
+ @Override
+ public boolean test(Resource r) {
+
+ boolean value = this.resourceType.isInstance(r);
+ if (value) {
+ Pattern pattern = Pattern.compile(patternString);
+ Matcher matcher = pattern.matcher(r.getURI().toString());
+ value = matcher.matches();
+ }
+ if (value && previousURI != null) {
+ value = !r.getURI().toString().equals(previousURI.toString());
+ }
+ return value;
+ }
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ TestsUtil.setCreateRepresentationInSeparateResource(oldPropertyValue);
+ }
+}

Back to the top