Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2018-09-01 12:59:09 -0400
committerRyan D. Brooks2018-09-05 12:26:08 -0400
commit6dd7523428d6587844bc5a612bdbbf6133c53f3e (patch)
tree7812a634e6f7d9c6c1bf8dcf63f5f7e8c80ad39c
parent88c0a112896c72877dbea1904b9b3fad1a3e732d (diff)
downloadorg.eclipse.osee-6dd7523428d6587844bc5a612bdbbf6133c53f3e.tar.gz
org.eclipse.osee-6dd7523428d6587844bc5a612bdbbf6133c53f3e.tar.xz
org.eclipse.osee-6dd7523428d6587844bc5a612bdbbf6133c53f3e.zip
refactor: Make RelationManager tests less fragile
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/OrcsMockUtility.java70
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java59
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java40
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java18
5 files changed, 104 insertions, 89 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/OrcsMockUtility.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/OrcsMockUtility.java
new file mode 100644
index 0000000000..08c40578a0
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/OrcsMockUtility.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.orcs.core;
+
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Name;
+import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.RelationOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.eclipse.osee.framework.core.data.AttributeTypeId;
+import org.eclipse.osee.framework.core.data.AttributeTypeToken;
+import org.eclipse.osee.framework.core.data.BranchId;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.enums.ModificationType;
+import org.eclipse.osee.orcs.core.ds.ArtifactData;
+import org.eclipse.osee.orcs.core.ds.Attribute;
+import org.eclipse.osee.orcs.core.ds.AttributeData;
+import org.eclipse.osee.orcs.core.ds.VersionData;
+import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
+import org.eclipse.osee.orcs.core.internal.artifact.ArtifactImpl;
+import org.eclipse.osee.orcs.core.internal.attribute.AttributeFactory;
+import org.eclipse.osee.orcs.core.internal.graph.GraphData;
+import org.eclipse.osee.orcs.data.ArtifactTypes;
+import org.mockito.Matchers;
+
+/**
+ * @author Ryan D. Brooks
+ */
+public class OrcsMockUtility {
+
+ public static Artifact createTestArtifact(GraphData graph, BranchId branch, IArtifactType artifactType, Long artifactId, String name) {
+ AttributeFactory attributeFactory = mock(AttributeFactory.class);
+ ArtifactTypes artifactTypeCache = mock(ArtifactTypes.class);
+
+ VersionData version = mock(VersionData.class);
+ when(version.getBranch()).thenReturn(branch);
+
+ ArtifactData artifactData = mock(ArtifactData.class);
+ when(artifactData.getVersion()).thenReturn(version);
+ when(artifactData.getTypeUuid()).thenReturn(artifactType.getId());
+ when(artifactData.getId()).thenReturn(artifactId);
+ when(artifactData.getModType()).thenReturn(ModificationType.NEW);
+
+ when(artifactTypeCache.get(artifactType.getId())).thenReturn(artifactType);
+ Artifact artifact = new ArtifactImpl(artifactTypeCache, artifactData, attributeFactory);
+ artifact.setGraph(graph);
+
+ when(attributeFactory.getMaxOccurrenceLimit(Matchers.any(AttributeTypeId.class))).thenReturn(1);
+
+ addAttribute(artifact, Name, name);
+ addAttribute(artifact, RelationOrder, "");
+ artifact.getBranch();
+ return artifact;
+ }
+
+ public static void addAttribute(Artifact artifact, AttributeTypeToken attributeType, String value) {
+ Attribute<Object> attribute = mock(Attribute.class);
+ AttributeData attributeData = mock(AttributeData.class);
+ when(attribute.getOrcsData()).thenReturn(attributeData);
+ when(attribute.getValue()).thenReturn(value);
+ artifact.add(attributeType, attribute);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
index 9be89e8aa4..c5c3b2b4cd 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/attribute/ArtifactTest.java
@@ -158,12 +158,6 @@ public class ArtifactTest {
}
@Test
- public void testGetLocalId() {
- artifact.getLocalId();
- verify(artifactData).getLocalId();
- }
-
- @Test
public void testGetGuid() {
artifact.getGuid();
verify(artifactData).getGuid();
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
index 575396ddff..261d62a341 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/RelationManagerTest.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.relation;
+import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.SoftwareRequirement;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.DEFAULT_HIERARCHY;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.IS_CHILD;
@@ -43,6 +44,7 @@ import org.eclipse.osee.framework.jdk.core.type.ResultSets;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.OrcsMockUtility;
import org.eclipse.osee.orcs.core.ds.RelationData;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
import org.eclipse.osee.orcs.core.internal.graph.GraphData;
@@ -85,13 +87,6 @@ public class RelationManagerTest {
@Mock private OrcsSession session;
@Mock private GraphData graph;
- @Mock private Artifact node1;
- @Mock private Artifact node2;
- @Mock private Artifact node3;
- @Mock private Artifact node4;
- @Mock private Artifact node5;
- @Mock private Artifact node6;
-
@Mock private RelationNodeAdjacencies adjancies1;
@Mock private RelationNodeAdjacencies adjancies2;
@@ -110,6 +105,12 @@ public class RelationManagerTest {
private RelationManager manager;
private Map<Integer, Artifact> mockDb;
+ private Artifact node1;
+ private Artifact node2;
+ private Artifact node3;
+ private Artifact node4;
+ private Artifact node5;
+ private Artifact node6;
@SuppressWarnings({"unchecked", "rawtypes"})
@Before
@@ -119,49 +120,20 @@ public class RelationManagerTest {
String sessionId = GUID.create();
when(session.getGuid()).thenReturn(sessionId);
+ node1 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 11L, "z");
+ node2 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 22L, "y");
+ node3 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 33L, "x");
+ node4 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 44L, "w");
+ node5 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 55L, "v");
+ node6 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 66L, "u");
+
manager = RelationManagerFactory.createRelationManager(logger, types, relationFactory, loader, provider);
when(loader.loadNodes(eq(session), eq(graph), anyCollectionOf(Integer.class), eq(LoadLevel.ALL))).thenAnswer(
new LoaderAnswer());
- when(node1.getLocalId()).thenReturn(11);
- when(node2.getLocalId()).thenReturn(22);
- when(node3.getLocalId()).thenReturn(33);
- when(node4.getLocalId()).thenReturn(44);
- when(node5.getLocalId()).thenReturn(55);
- when(node6.getLocalId()).thenReturn(66);
-
- when(node1.getBranch()).thenReturn(COMMON);
- when(node2.getBranch()).thenReturn(COMMON);
- when(node3.getBranch()).thenReturn(COMMON);
- when(node4.getBranch()).thenReturn(COMMON);
- when(node5.getBranch()).thenReturn(COMMON);
- when(node6.getBranch()).thenReturn(COMMON);
-
- when(node1.getName()).thenReturn("z");
- when(node2.getName()).thenReturn("y");
- when(node3.getName()).thenReturn("x");
- when(node4.getName()).thenReturn("w");
- when(node5.getName()).thenReturn("v");
- when(node6.getName()).thenReturn("u");
-
- when(node1.getGraph()).thenReturn(graph);
- when(node2.getGraph()).thenReturn(graph);
- when(node3.getGraph()).thenReturn(graph);
- when(node4.getGraph()).thenReturn(graph);
- when(node5.getGraph()).thenReturn(graph);
- when(node6.getGraph()).thenReturn(graph);
-
when(graph.getTransaction()).thenReturn(TransactionId.SENTINEL);
- when(node1.getArtifactTypeId()).thenReturn(CoreArtifactTypes.SoftwareRequirement);
- when(node2.getArtifactTypeId()).thenReturn(CoreArtifactTypes.SoftwareRequirement);
- when(node3.getArtifactTypeId()).thenReturn(CoreArtifactTypes.SoftwareRequirement);
-
- when(node1.getOrderData()).thenReturn("");
- when(node2.getOrderData()).thenReturn("");
- when(node3.getOrderData()).thenReturn("");
-
mockDb = new HashMap<>();
mockDb.put(11, node1);
mockDb.put(22, node2);
@@ -217,7 +189,6 @@ public class RelationManagerTest {
private void setupAdjacencies(Artifact node, Relation... relations) {
RelationNodeAdjacencies adjacents = new RelationNodeAdjacencies();
- graph.addAdjacencies(node, adjacents);
when(graph.getAdjacencies(node)).thenReturn(adjacents);
for (Relation relation : relations) {
adjacents.add(relation.getRelationType(), relation);
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java
index bf59c1427d..a5e842cb56 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/relation/impl/RelationManagerImplTest.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.relation.impl;
+import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.SoftwareRequirement;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.eclipse.osee.framework.core.enums.CoreBranches.SYSTEM_ROOT;
import static org.eclipse.osee.framework.core.enums.CoreRelationTypes.DEFAULT_HIERARCHY;
@@ -55,6 +56,7 @@ import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
+import org.eclipse.osee.orcs.core.OrcsMockUtility;
import org.eclipse.osee.orcs.core.internal.artifact.Artifact;
import org.eclipse.osee.orcs.core.internal.graph.GraphData;
import org.eclipse.osee.orcs.core.internal.relation.Relation;
@@ -105,13 +107,6 @@ public class RelationManagerImplTest {
@Mock private GraphData graph;
- @Mock private Artifact node1;
- @Mock private Artifact node2;
- @Mock private Artifact node3;
- @Mock private Artifact node4;
- @Mock private Artifact node5;
- @Mock private Artifact node6;
-
@Mock private RelationNodeAdjacencies container1;
@Mock private RelationNodeAdjacencies container2;
@@ -137,6 +132,12 @@ public class RelationManagerImplTest {
private final RelationTypes relationTypes = new RelationTypesImpl(null);
private RelationManager manager;
+ private Artifact node1;
+ private Artifact node2;
+ private Artifact node3;
+ private Artifact node4;
+ private Artifact node5;
+ private Artifact node6;
@Before
public void setUp() {
@@ -147,23 +148,12 @@ public class RelationManagerImplTest {
String sessionId = GUID.create();
when(session.getGuid()).thenReturn(sessionId);
- when(node1.getLocalId()).thenReturn(11);
- when(node2.getLocalId()).thenReturn(22);
- when(node3.getLocalId()).thenReturn(33);
- when(node4.getLocalId()).thenReturn(44);
- when(node5.getLocalId()).thenReturn(55);
- when(node6.getLocalId()).thenReturn(66);
-
- when(node1.getGraph()).thenReturn(graph);
- when(node2.getGraph()).thenReturn(graph);
- when(node3.getGraph()).thenReturn(graph);
- when(node4.getGraph()).thenReturn(graph);
- when(node5.getGraph()).thenReturn(graph);
- when(node6.getGraph()).thenReturn(graph);
-
- when(node1.getBranch()).thenReturn(COMMON);
- when(node2.getBranch()).thenReturn(COMMON);
- when(node3.getBranch()).thenReturn(SYSTEM_ROOT);
+ node1 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 11L, "z");
+ node2 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 22L, "y");
+ node3 = OrcsMockUtility.createTestArtifact(graph, SYSTEM_ROOT, SoftwareRequirement, 33L, "x");
+ node4 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 44L, "w");
+ node5 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 55L, "v");
+ node6 = OrcsMockUtility.createTestArtifact(graph, COMMON, SoftwareRequirement, 66L, "u");
when(graph.getTransaction()).thenReturn(TransactionId.SENTINEL);
@@ -726,7 +716,6 @@ public class RelationManagerImplTest {
List<Artifact> children = Arrays.asList(node2);
when(relation1.getRelationType()).thenReturn(DEFAULT_HIERARCHY);
- when(node1.isDeleteAllowed()).thenReturn(true);
when(container1.getList(EXCLUDE_DELETED)).thenReturn(allRelations);
when(container1.getList(DEFAULT_HIERARCHY, EXCLUDE_DELETED, node1, IS_PARENT)).thenReturn(allRelations);
when(container1.getList(DEFAULT_HIERARCHY, EXCLUDE_DELETED, node1, IS_PARENT)).thenReturn(asAParent);
@@ -744,7 +733,6 @@ public class RelationManagerImplTest {
verify(container1).getList(EXCLUDE_DELETED);
verify(resolver).resolve(session, graph, allRelations, SIDE_A, SIDE_B);
verify(container1).getList(DEFAULT_HIERARCHY, EXCLUDE_DELETED, node1, IS_PARENT);
- verify(node1).delete();
verify(relation1).getIdForSide(SIDE_A);
verify(relation1).delete();
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java
index eb2e221bbf..a91f706260 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/artifact/ArtifactImpl.java
@@ -77,7 +77,7 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact {
@Override
public Integer getLocalId() {
- return getOrcsData().getLocalId();
+ return getId().intValue();
}
@Override
@@ -102,13 +102,9 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact {
return artifactData.getVersion().getBranch();
}
- private IArtifactType getArtifactType() {
- return artifactTypeCache.get(getOrcsData().getTypeUuid());
- }
-
@Override
public IArtifactType getArtifactTypeId() {
- return getArtifactType();
+ return artifactTypeCache.get(getOrcsData().getTypeUuid());
}
@Override
@@ -165,7 +161,7 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact {
@Override
public String getExceptionString() {
try {
- return String.format("artifact type[%s] id[%s] on branch[%s]", getArtifactType(), getId(), getBranch());
+ return String.format("artifact type[%s] id[%s] on branch[%s]", getArtifactTypeId(), getId(), getBranch());
} catch (OseeCoreException ex) {
return Lib.exceptionToString(ex);
}
@@ -218,18 +214,14 @@ public class ArtifactImpl extends AttributeManagerImpl implements Artifact {
@Override
public String toString() {
try {
- return String.format("artifact [type=[%s] guid=[%s] branch=[%s]]", getArtifactType(), getGuid(), getBranch());
+ return String.format("artifact [type=[%s] guid=[%s] branch=[%s]]", getArtifactTypeId(), getGuid(),
+ getBranch());
} catch (OseeCoreException ex) {
return Lib.exceptionToString(ex);
}
}
@Override
- public Long getId() {
- return Long.valueOf(getLocalId());
- }
-
- @Override
public Iterable<Collection<? extends AttributeReadable<Object>>> getAttributeIterable() {
return null;
}

Back to the top