Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonald.g.dunne2016-12-19 12:33:32 -0500
committerdonald.g.dunne2016-12-21 10:39:41 -0500
commit55b8eb5e99364c3276cf7f927977f83bf8ebce8c (patch)
tree55a3c07a652317584747d37f628a1425b735a278
parentfe65bf69167a5d176b9136ce118b2e8ba31eae87 (diff)
downloadorg.eclipse.osee-55b8eb5e99364c3276cf7f927977f83bf8ebce8c.tar.gz
org.eclipse.osee-55b8eb5e99364c3276cf7f927977f83bf8ebce8c.tar.xz
org.eclipse.osee-55b8eb5e99364c3276cf7f927977f83bf8ebce8c.zip
bug[ats_ATS329812]: Fix AtsChangeSet.setRelations to unrelate first
-rw-r--r--plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/util/AtsChangeSet.java10
-rw-r--r--plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AbstractAtsChangeSet.java6
-rw-r--r--plugins/org.eclipse.osee.ats.rest.test/README_BEFORE_RUNNING_TESTS.txt1
-rw-r--r--plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSetTest.java77
-rw-r--r--plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java6
6 files changed, 83 insertions, 37 deletions
diff --git a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/util/AtsChangeSet.java b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/util/AtsChangeSet.java
index eea4191769..dc1edf9fb3 100644
--- a/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/util/AtsChangeSet.java
+++ b/plugins/org.eclipse.osee.ats.core.client/src/org/eclipse/osee/ats/core/client/util/AtsChangeSet.java
@@ -11,7 +11,6 @@
package org.eclipse.osee.ats.core.client.util;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -298,15 +297,6 @@ public class AtsChangeSet extends AbstractAtsChangeSet {
}
@Override
- public void setRelation(Object object1, IRelationTypeSide relationType, Object object2) {
- Artifact artifact = getArtifact(object1);
- Artifact artifact2 = getArtifact(object2);
- artifact.setRelations(relationType, Collections.singleton(artifact2));
- add(artifact);
- add(artifact2);
- }
-
- @Override
public void setRelations(Object object, IRelationTypeSide relationSide, Collection<? extends Object> objects) {
Artifact artifact = getArtifact(object);
Set<Artifact> artifacts = new HashSet<>(objects.size());
diff --git a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AbstractAtsChangeSet.java b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AbstractAtsChangeSet.java
index 60678c02cc..ae1b5505e8 100644
--- a/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AbstractAtsChangeSet.java
+++ b/plugins/org.eclipse.osee.ats.core/src/org/eclipse/osee/ats/core/util/AbstractAtsChangeSet.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.ats.core.util;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
@@ -166,4 +167,9 @@ public abstract class AbstractAtsChangeSet implements IAtsChangeSet {
setSoleAttributeFromString(atsObject.getStoreObject(), attributeType, value);
}
+ @Override
+ public void setRelation(Object object1, IRelationTypeSide relationSide, Object object2) {
+ setRelations(object1, relationSide, Collections.singleton(object2));
+ }
+
}
diff --git a/plugins/org.eclipse.osee.ats.rest.test/README_BEFORE_RUNNING_TESTS.txt b/plugins/org.eclipse.osee.ats.rest.test/README_BEFORE_RUNNING_TESTS.txt
index 665ed9ddae..dae7c0aabd 100644
--- a/plugins/org.eclipse.osee.ats.rest.test/README_BEFORE_RUNNING_TESTS.txt
+++ b/plugins/org.eclipse.osee.ats.rest.test/README_BEFORE_RUNNING_TESTS.txt
@@ -3,3 +3,4 @@ Database files will be copied out to users home directory for tests that require
If schema or breaking db changes are made, update database from instructions in that plugin.
It does not require running an separate application server.
+Launch using AtsServer_Integration_TestSuite launch config.
diff --git a/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSetTest.java b/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSetTest.java
index 69b3af192a..a28b2eacdc 100644
--- a/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSetTest.java
+++ b/plugins/org.eclipse.osee.ats.rest.test/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSetTest.java
@@ -16,6 +16,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
+import org.eclipse.osee.ats.api.data.AtsRelationTypes;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.api.version.IAtsVersion;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
@@ -30,6 +31,7 @@ import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
@@ -52,8 +54,7 @@ public class AtsChangeSetTest {
@Test
public void testCreateArtifact() {
String className = getClass().getSimpleName();
- IAtsChangeSet changes =
- atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ IAtsChangeSet changes = createAtsChangeSet();
Long uuid = Lib.generateArtifactIdAsInt();
String guid = GUID.create();
String name = "Ver 1 " + className;
@@ -74,8 +75,7 @@ public class AtsChangeSetTest {
@Test
public void testCreateRelationsAndUnrelateAll() {
String className = getClass().getSimpleName();
- IAtsChangeSet changes =
- atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ IAtsChangeSet changes = createAtsChangeSet();
ArtifactId folderArt = changes.createArtifact(CoreArtifactTypes.Folder, "Folder 2 " + className);
ArtifactId verArt = changes.createArtifact(AtsArtifactTypes.Version, "Ver 2 " + className);
changes.execute();
@@ -86,7 +86,7 @@ public class AtsChangeSetTest {
assertNotNull(version);
// add relation from folder to version
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.relate(folder, CoreRelationTypes.SupportingInfo_SupportingInfo, version);
changes.execute();
@@ -99,7 +99,7 @@ public class AtsChangeSetTest {
assertFalse(verArt2.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, folderArt2));
// unrelate all on folder
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.unrelateAll(folderArt2, CoreRelationTypes.SupportingInfo_SupportingInfo);
changes.execute();
@@ -116,7 +116,7 @@ public class AtsChangeSetTest {
assertNotNull(folder);
version = atsServer.getConfigItemFactory().getVersion(atsServer.getArtifact(verArt.getUuid()));
assertNotNull(version);
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.relate(version, CoreRelationTypes.SupportingInfo_SupportedBy, folder);
changes.execute();
@@ -129,7 +129,7 @@ public class AtsChangeSetTest {
assertFalse(verArt22.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, folderArt22));
// unrelate all on version
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.unrelateAll(verArt22, CoreRelationTypes.SupportingInfo_SupportedBy);
changes.execute();
@@ -145,8 +145,7 @@ public class AtsChangeSetTest {
@Test
public void testUnrelate() {
String className = getClass().getSimpleName();
- IAtsChangeSet changes =
- atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ IAtsChangeSet changes = createAtsChangeSet();
ArtifactId folderArt = changes.createArtifact(CoreArtifactTypes.Folder, "Folder 3 " + className);
ArtifactId verArt = changes.createArtifact(AtsArtifactTypes.Version, "Ver 3 " + className);
changes.relate(folderArt, CoreRelationTypes.SupportingInfo_SupportingInfo, verArt);
@@ -161,7 +160,7 @@ public class AtsChangeSetTest {
assertFalse(verArt2.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, folderArt2));
// unrelate folder from version
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.unrelate(folderArt2, CoreRelationTypes.SupportingInfo_SupportingInfo, verArt2);
changes.execute();
@@ -176,8 +175,7 @@ public class AtsChangeSetTest {
@Test
public void testSetRelationAndRelations() {
String className = getClass().getSimpleName();
- IAtsChangeSet changes =
- atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ IAtsChangeSet changes = createAtsChangeSet();
ArtifactId folderArt = changes.createArtifact(CoreArtifactTypes.Folder, "Folder 4 " + className);
ArtifactId ver1ArtId = changes.createArtifact(AtsArtifactTypes.Version, "Ver 4.1 " + className);
changes.relate(folderArt, CoreRelationTypes.SupportingInfo_SupportingInfo, ver1ArtId);
@@ -196,7 +194,7 @@ public class AtsChangeSetTest {
assertFalse(folderArt2.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, verArt3));
// setRelations to 2 and 3
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.setRelations(folderArt2, CoreRelationTypes.SupportingInfo_SupportingInfo,
Arrays.asList(verArt2, verArt3));
changes.execute();
@@ -211,7 +209,7 @@ public class AtsChangeSetTest {
assertTrue(folderArt21.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, verArt31));
// setRelations to 1 and 2
- changes = atsServer.getStoreService().createAtsChangeSet(className, atsServer.getUserService().getCurrentUser());
+ changes = createAtsChangeSet();
changes.setRelations(folderArt21, CoreRelationTypes.SupportingInfo_SupportingInfo,
Arrays.asList(verArt11, verArt21));
changes.execute();
@@ -224,6 +222,55 @@ public class AtsChangeSetTest {
assertTrue(folderArt211.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, verArt111));
assertTrue(folderArt211.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, verArt211));
assertFalse(folderArt211.areRelated(CoreRelationTypes.SupportingInfo_SupportingInfo, verArt311));
+ }
+
+ /**
+ * Verify that if relation validity is many to one, setRelation/setRelations will successfully remove one and add
+ * another
+ */
+ @Test
+ public void testSetRelationAndRelations_OneToMany() {
+ String className = getClass().getSimpleName();
+ IAtsChangeSet changes = createAtsChangeSet();
+ ArtifactId ver1 = changes.createArtifact(AtsArtifactTypes.Version, "Version 1 " + className);
+ ArtifactId ver2 = changes.createArtifact(AtsArtifactTypes.Version, "Version 2 " + className);
+ ArtifactId teamWf = changes.createArtifact(AtsArtifactTypes.TeamWorkflow, "Workflow " + className);
+ changes.execute();
+
+ // setRelation/setRelations - teamWf to version
+ changes = createAtsChangeSet();
+ changes.setRelation(teamWf, AtsRelationTypes.TeamWorkflowTargetedForVersion_Version, ver1);
+ changes.execute();
+ // reload artifacts to get latest stripe
+ ver1 = atsServer.getArtifact(ver1.getId());
+ ver2 = atsServer.getArtifact(ver2.getId());
+ teamWf = atsServer.getArtifact(teamWf.getId());
+
+ // ensure that teamWf is related to ver1
+ Assert.assertEquals(ver1.getId(),
+ atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)).getUuid());
+
+ // setRelation/setRelations - replace ver1 with ver2
+ changes = createAtsChangeSet();
+ changes.setRelation(teamWf, AtsRelationTypes.TeamWorkflowTargetedForVersion_Version, ver2);
+ changes.execute();
+
+ // reload artifacts to get latest stripe
+ ver1 = atsServer.getArtifact(ver1.getId());
+ ver2 = atsServer.getArtifact(ver2.getId());
+ teamWf = atsServer.getArtifact(teamWf.getId());
+
+ // ensure teamWf is related to ver2 and not related to ver1
+ Assert.assertEquals(ver2.getId(),
+ atsServer.getVersionService().getTargetedVersion(atsServer.getWorkItemFactory().getTeamWf(teamWf)).getUuid());
+ Assert.assertEquals(0,
+ ((ArtifactReadable) ver1).getRelated(AtsRelationTypes.TeamWorkflowTargetedForVersion_Workflow).size());
+ }
+
+ private IAtsChangeSet createAtsChangeSet() {
+ return atsServer.getStoreService().createAtsChangeSet(getClass().getSimpleName(),
+ atsServer.getUserService().getCurrentUser());
}
+
}
diff --git a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java
index 4d3ab0ea62..d2b7efa478 100644
--- a/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java
+++ b/plugins/org.eclipse.osee.ats.rest/src/org/eclipse/osee/ats/rest/internal/util/AtsChangeSet.java
@@ -11,7 +11,6 @@
package org.eclipse.osee.ats.rest.internal.util;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.ats.api.IAtsObject;
@@ -240,11 +239,6 @@ public class AtsChangeSet extends AbstractAtsChangeSet {
}
@Override
- public void setRelation(Object object1, IRelationTypeSide relationSide, Object object2) {
- setRelations(object1, relationSide, Collections.singleton(object2));
- }
-
- @Override
public void setRelations(Object object, IRelationTypeSide relationSide, Collection<? extends Object> objects) {
ArtifactReadable artifact = getArtifact(object);
List<ArtifactReadable> artifacts = new LinkedList<>();
@@ -255,6 +249,13 @@ public class AtsChangeSet extends AbstractAtsChangeSet {
}
}
+ // unrelate all objects that are not in set
+ for (ArtifactReadable art : artifact.getRelated(relationSide)) {
+ if (!artifacts.contains(art)) {
+ unrelate(artifact, relationSide, art);
+ }
+ }
+
// add all relations that do not exist
for (Object obj : objects) {
ArtifactReadable art = getArtifact(obj);
@@ -262,12 +263,7 @@ public class AtsChangeSet extends AbstractAtsChangeSet {
relate(object, relationSide, obj);
}
}
- // unrelate all objects that are not in set
- for (ArtifactReadable art : artifact.getRelated(relationSide)) {
- if (!artifacts.contains(art)) {
- unrelate(artifact, relationSide, art);
- }
- }
+
}
public void unrelate(Object object1, IRelationTypeSide relationType, Object object2) {
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java
index ba279f387e..2389b30ff0 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/proxy/impl/ArtifactReadOnlyImpl.java
@@ -283,4 +283,10 @@ public class ArtifactReadOnlyImpl extends AbstractProxied<Artifact> implements A
public Long getUuid() {
return Long.valueOf(getLocalId());
}
+
+ @Override
+ public String toString() {
+ return String.format("Artifact: Id [%s] Type [%s] Name [%s]", getId().toString(), getArtifactType().getName(),
+ getName());
+ }
}

Back to the top