Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkwilk2011-06-17 02:11:34 -0400
committerRyan D. Brooks2011-06-17 02:11:34 -0400
commitd9660c717c3ae4213efac1e48314400cdb40a20a (patch)
tree3e99bc056be8dcf56e6440fea32d5022b03bd683 /plugins/org.eclipse.osee.framework.skynet.core.test
parentc8f3fdb89e4a3af16c8848e8ded9c8401945f452 (diff)
downloadorg.eclipse.osee-d9660c717c3ae4213efac1e48314400cdb40a20a.tar.gz
org.eclipse.osee-d9660c717c3ae4213efac1e48314400cdb40a20a.tar.xz
org.eclipse.osee-d9660c717c3ae4213efac1e48314400cdb40a20a.zip
bug: Fixes for test failures on 0.9.9_dev
Diffstat (limited to 'plugins/org.eclipse.osee.framework.skynet.core.test')
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/DirtyArtifactCacheTest.java23
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/NativeArtifactTest.java39
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationDeletionTest.java22
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationOrderingTest.java8
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/ArtifactEventTest.java2
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/BranchEventTest.java188
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtilityTest.java10
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/rule/OseeHousekeepingRule.java59
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/utility/CsvArtifactTest.java20
10 files changed, 230 insertions, 142 deletions
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF
index ec64248373..c48a2f6ddb 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/META-INF/MANIFEST.MF
@@ -20,6 +20,7 @@ Export-Package: org.eclipse.osee.framework.skynet.core,
org.eclipse.osee.framework.skynet.core.relation.order,
org.eclipse.osee.framework.skynet.core.relation.sorters,
org.eclipse.osee.framework.skynet.core.revision,
+ org.eclipse.osee.framework.skynet.core.rule,
org.eclipse.osee.framework.skynet.core.transaction,
org.eclipse.osee.framework.skynet.core.util,
org.eclipse.osee.framework.skynet.core.utility,
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/DirtyArtifactCacheTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/DirtyArtifactCacheTest.java
index e09976e299..d2a86c8bd5 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/DirtyArtifactCacheTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/DirtyArtifactCacheTest.java
@@ -1,11 +1,19 @@
-/*
- * Created on May 17, 2011
+/*******************************************************************************
+ * Copyright (c) 2011 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
*
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
package org.eclipse.osee.framework.skynet.core.artifact;
+import java.util.Collection;
+import java.util.logging.Level;
import junit.framework.Assert;
+import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.utility.Artifacts;
/**
@@ -17,8 +25,13 @@ public class DirtyArtifactCacheTest {
@org.junit.Test
public void testArtifactCacheNotDirty() {
+ final Collection<Artifact> dirtyArtifacts = ArtifactCache.getDirtyArtifacts();
Assert.assertTrue(String.format(
"After all tests are run, there should be no dirty artifacts in Artifact Cache; Found [%s]",
- Artifacts.getNames(ArtifactCache.getDirtyArtifacts())), ArtifactCache.getDirtyArtifacts().isEmpty());
+ Artifacts.getNames(dirtyArtifacts)), dirtyArtifacts.isEmpty());
+ for (Artifact artifact : dirtyArtifacts) {
+ OseeLog.format(getClass(), Level.WARNING, "Name: %s Type: %s ", artifact.getName(),
+ artifact.getArtifactTypeName());
+ }
}
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/NativeArtifactTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/NativeArtifactTest.java
index f87a8515f7..22641c927b 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/NativeArtifactTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/NativeArtifactTest.java
@@ -11,19 +11,19 @@
package org.eclipse.osee.framework.skynet.core.artifact;
-import static org.eclipse.osee.framework.core.enums.DeletionFlag.EXCLUDE_DELETED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.plugin.core.util.OseeData;
-import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.utility.CsvArtifact;
import org.eclipse.osee.support.test.util.DemoSawBuilds;
import org.junit.AfterClass;
@@ -34,18 +34,24 @@ import org.junit.BeforeClass;
*/
public class NativeArtifactTest {
+ private final static String ARTIFACT_NAME = NativeArtifactTest.class.getSimpleName();
+ private final static Set<Artifact> testArtifacts = new HashSet<Artifact>();
+
@BeforeClass
@AfterClass
public static void cleanup() throws Exception {
- Collection<Artifact> arts =
- ArtifactQuery.getArtifactListFromName(NativeArtifactTest.class.getSimpleName(), DemoSawBuilds.SAW_Bld_2,
- EXCLUDE_DELETED);
- new PurgeArtifacts(arts).execute();
+ new PurgeArtifacts(testArtifacts).execute();
+ }
+
+ @org.junit.Test
+ public void testGetFileExtension() throws Exception {
+ Artifact nativeArtifact = getNativeArtifact();
+ assertTrue(nativeArtifact.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("csv"));
}
@org.junit.Test
public void testNativeArtifact() throws Exception {
- CsvArtifact csvArtifact = CsvArtifact.getCsvArtifact(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_2, true);
+ CsvArtifact csvArtifact = getCsvArtifact(true);
assertNotNull(csvArtifact);
Artifact artifact = csvArtifact.getArtifact();
assertTrue(artifact.isAttributeTypeValid(CoreAttributeTypes.NativeContent));
@@ -53,12 +59,6 @@ public class NativeArtifactTest {
}
@org.junit.Test
- public void testGetFileExtension() throws Exception {
- Artifact nativeArtifact = getNativeArtifact();
- assertTrue(nativeArtifact.getSoleAttributeValue(CoreAttributeTypes.Extension, "").equals("csv"));
- }
-
- @org.junit.Test
public void testSetAndGetValueAsString() throws Exception {
Artifact nativeArtifact = getNativeArtifact();
nativeArtifact.setSoleAttributeFromString(CoreAttributeTypes.NativeContent, "hello world");
@@ -84,8 +84,13 @@ public class NativeArtifactTest {
}
}
- private Artifact getNativeArtifact() throws Exception {
- return CsvArtifact.getCsvArtifact(getClass().getSimpleName(), DemoSawBuilds.SAW_Bld_2, false).getArtifact();
+ private Artifact getNativeArtifact() throws OseeCoreException {
+ return getCsvArtifact(false).getArtifact();
}
-}
+ private CsvArtifact getCsvArtifact(boolean create) throws OseeCoreException {
+ CsvArtifact csvArtifact = CsvArtifact.getCsvArtifact(ARTIFACT_NAME, DemoSawBuilds.SAW_Bld_2, create);
+ testArtifacts.add(csvArtifact.getArtifact());
+ return csvArtifact;
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationDeletionTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationDeletionTest.java
index 3484d46cdc..18b8e8a500 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationDeletionTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationDeletionTest.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.skynet.core.artifact;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.data.IArtifactType;
@@ -21,20 +22,35 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
+import org.eclipse.osee.framework.skynet.core.rule.OseeHousekeepingRule;
+import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.MethodRule;
/**
* @author Andrew M. Finkbeiner
*/
public class RelationDeletionTest {
+ private final List<Artifact> artifacts = new ArrayList<Artifact>();
+
+ @Rule
+ public MethodRule oseeHousekeepingRule = new OseeHousekeepingRule();
+
@Before
public void setUp() throws Exception {
// This test should only be run on test db
assertFalse(ClientSessionManager.isProductionDataStore());
}
- @org.junit.Test
+ @After
+ public void cleanUp() throws OseeCoreException {
+ new PurgeArtifacts(artifacts).execute();
+ }
+
+ @Test
public void testDeleteRelationPersistsBothSides() throws Exception {
SevereLoggingMonitor monitor = new SevereLoggingMonitor();
OseeLog.registerLoggerListener(monitor);
@@ -72,6 +88,8 @@ public class RelationDeletionTest {
}
private Artifact createArtifact(IArtifactType artifactType, Branch branch) throws OseeCoreException {
- return ArtifactTypeManager.addArtifact(artifactType, branch);
+ Artifact newArtifact = ArtifactTypeManager.addArtifact(artifactType, branch);
+ artifacts.add(newArtifact);
+ return newArtifact;
}
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationOrderingTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationOrderingTest.java
index 9357ceb194..bd6a3d16c2 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationOrderingTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/artifact/RelationOrderingTest.java
@@ -81,10 +81,10 @@ public class RelationOrderingTest {
@After
public void cleanupArtifacts() throws Exception {
- // parent.deleteAndPersist();
- // child1.deleteAndPersist();
- // child2.deleteAndPersist();
- // child3.deleteAndPersist();
+ for (Artifact artifact : new Artifact[] {parent, child1, child2, child3}) {
+ ArtifactCache.deCache(artifact);
+ artifact.deleteAndPersist();
+ }
}
@org.junit.Test
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/ArtifactEventTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/ArtifactEventTest.java
index e984a0b604..ae73b1e37e 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/ArtifactEventTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/ArtifactEventTest.java
@@ -189,7 +189,7 @@ public class ArtifactEventTest {
newArt.persist(getClass().getSimpleName());
Assert.assertEquals(2, resultEventArtifacts.size());
- Assert.assertEquals("No relations events should be sent", 0, resultEventRelations.size());
+ Assert.assertTrue("No relations events should be sent", resultEventRelations.isEmpty());
if (isRemoteTest()) {
Assert.assertTrue(resultSender.isRemote());
} else {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/BranchEventTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/BranchEventTest.java
index 4411f692d3..12a2c6ffcb 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/BranchEventTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/event/model/BranchEventTest.java
@@ -25,7 +25,9 @@ import org.eclipse.osee.framework.core.exception.BranchDoesNotExist;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.operation.Operations;
+import org.eclipse.osee.framework.jdk.core.type.Pair;
import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
@@ -38,18 +40,20 @@ import org.eclipse.osee.framework.skynet.core.event.filter.IEventFilter;
import org.eclipse.osee.framework.skynet.core.event.listener.IBranchEventListener;
import org.eclipse.osee.framework.skynet.core.httpRequests.PurgeBranchHttpRequestOperation;
import org.eclipse.osee.support.test.util.TestUtil;
+import org.junit.AfterClass;
/**
* @author Donald G. Dunne
*/
public class BranchEventTest {
- private BranchEvent resultBranchEvent = null;
- private Sender resultSender = null;
public static List<String> ignoreLogging = Arrays.asList("");
private static String BRANCH_NAME_PREFIX = "BranchEventManagerTest";
+ private static String TOP_LEVEL_BRANCH_NAME = String.format("%s - top level branch", BRANCH_NAME_PREFIX);
private static Branch topLevel;
+ private final BranchEventListener branchEventListener = new BranchEventListener();
+
@org.junit.Test
public void testRegistration() throws Exception {
SevereLoggingMonitor monitorLog = TestUtil.severeLoggingStart();
@@ -66,7 +70,10 @@ public class BranchEventTest {
TestUtil.severeLoggingEnd(monitorLog);
}
- @org.junit.Test
+ /**
+ * If all branch tests take longer than 10seconds, fail test, something went wrong.
+ */
+ @org.junit.Test(timeout = 10000)
public void testEvents() throws Exception {
SevereLoggingMonitor monitorLog = TestUtil.severeLoggingStart();
OseeEventManager.removeAllListeners();
@@ -89,12 +96,12 @@ public class BranchEventTest {
TestUtil.severeLoggingEnd(monitorLog, (isRemoteTest() ? ignoreLogging : new ArrayList<String>()));
} finally {
OseeEventManager.getPreferences().setPendRunning(false);
+ OseeEventManager.removeListener(branchEventListener);
}
-
}
private Branch testEvents__changeArchiveState(Branch committedBranch) throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
Assert.assertNotNull(committedBranch);
final String guid = committedBranch.getGuid();
@@ -102,21 +109,16 @@ public class BranchEventTest {
BranchManager.updateBranchArchivedState(null, committedBranch.getId(), committedBranch.getGuid(),
BranchArchivedState.UNARCHIVED);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.ArchiveStateUpdated, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.ArchiveStateUpdated, guid);
+
Assert.assertEquals(BranchArchivedState.UNARCHIVED, committedBranch.getArchiveState());
Assert.assertFalse(committedBranch.isEditable());
return committedBranch;
}
private Branch testEvents__committed() throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
Branch workingBranch =
BranchManager.createWorkingBranch(topLevel, BRANCH_NAME_PREFIX + " - to commit", UserManager.getUser());
@@ -129,21 +131,16 @@ public class BranchEventTest {
ConflictManagerExternal conflictManager = new ConflictManagerExternal(topLevel, workingBranch);
BranchManager.commitBranch(null, conflictManager, true, true);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Committed, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.Committed, guid);
+
Assert.assertEquals(BranchState.COMMITTED, workingBranch.getBranchState());
Assert.assertFalse(workingBranch.isEditable());
return workingBranch;
}
private Branch testEvents__purged() throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
Branch workingBranch =
BranchManager.createWorkingBranch(topLevel, BRANCH_NAME_PREFIX + " - to purge", UserManager.getUser());
@@ -154,14 +151,8 @@ public class BranchEventTest {
Operations.executeWorkAndCheckStatus(new PurgeBranchHttpRequestOperation(workingBranch, false));
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Purged, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.Purged, guid);
+
Assert.assertEquals(BranchState.CREATED, workingBranch.getBranchState());
Assert.assertEquals(StorageState.PURGED, workingBranch.getStorageState());
Assert.assertFalse(workingBranch.isEditable());
@@ -175,150 +166,143 @@ public class BranchEventTest {
}
private Branch testEvents__deleted(Branch workingBranch) throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
final String guid = workingBranch.getGuid();
Assert.assertNotNull(workingBranch);
Assert.assertNotSame(BranchState.DELETED, workingBranch.getBranchState());
Operations.executeWork(new DeleteBranchOperation(workingBranch));
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Deleted, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.Deleted, guid);
+
Assert.assertEquals(BranchState.DELETED, workingBranch.getBranchState());
return workingBranch;
}
private Branch testEvents__stateChange(Branch workingBranch) throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
final String guid = workingBranch.getGuid();
Assert.assertNotNull(workingBranch);
Assert.assertEquals(BranchState.CREATED, workingBranch.getBranchState());
BranchManager.updateBranchState(null, workingBranch.getId(), workingBranch.getGuid(), BranchState.MODIFIED);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.StateUpdated, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.StateUpdated, guid);
+
Assert.assertEquals(BranchState.MODIFIED, workingBranch.getBranchState());
return workingBranch;
}
private Branch testEvents__typeChange(Branch workingBranch) throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
final String guid = workingBranch.getGuid();
Assert.assertNotNull(workingBranch);
Assert.assertEquals(BranchType.WORKING, workingBranch.getBranchType());
BranchManager.updateBranchType(null, workingBranch.getId(), workingBranch.getGuid(), BranchType.BASELINE);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.TypeUpdated, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.TypeUpdated, guid);
+
Assert.assertEquals(BranchType.BASELINE, workingBranch.getBranchType());
return workingBranch;
}
private Branch testEvents__workingRenamed(Branch workingBranch) throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
final String guid = workingBranch.getGuid();
Assert.assertNotNull(workingBranch);
String newName = BRANCH_NAME_PREFIX + " - working renamed";
workingBranch.setName(newName);
BranchManager.persist(workingBranch);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Renamed, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
+ verifyReceivedBranchStates(BranchEventType.Renamed, guid);
+
Assert.assertEquals(newName, workingBranch.getName());
Assert.assertNotNull(BranchManager.getBranchesByName(newName));
return workingBranch;
}
private Branch testEvents__workingAdded() throws Exception {
- clearEventCollections();
+ branchEventListener.reset();
+
Branch workingBranch =
BranchManager.createWorkingBranch(topLevel, BRANCH_NAME_PREFIX + " - working", UserManager.getUser());
Assert.assertNotNull(workingBranch);
- Thread.sleep(4000);
+ verifyReceivedBranchStates(BranchEventType.Added, null);
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Added, resultBranchEvent.getEventType());
- if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
- } else {
- Assert.assertTrue(resultSender.isLocal());
- }
return workingBranch;
}
private Branch testEvents__topLevelAdded() throws Exception {
- clearEventCollections();
- final String guid = GUID.create();
- final String branchName = String.format("%s - top level branch", BRANCH_NAME_PREFIX);
+ branchEventListener.reset();
+
+ String guid = GUID.create();
+ String branchName = TOP_LEVEL_BRANCH_NAME;
IOseeBranch branchToken = TokenFactory.createBranch(guid, branchName);
topLevel = BranchManager.createTopLevelBranch(branchToken);
Assert.assertNotNull(topLevel);
- Thread.sleep(2000);
+ verifyReceivedBranchStates(BranchEventType.Added, guid);
+
+ return topLevel;
+ }
- Assert.assertNotNull(resultBranchEvent);
- Assert.assertEquals(BranchEventType.Added, resultBranchEvent.getEventType());
+ private void verifyReceivedBranchStates(BranchEventType expectedEnumState, String expectedBranchGuid) throws InterruptedException {
+ Pair<Sender, BranchEvent> update = branchEventListener.getResults();
+ Sender receivedSender = update.getFirst();
+ BranchEvent receivedBranchEvent = update.getSecond();
+
+ Assert.assertEquals(expectedEnumState, receivedBranchEvent.getEventType());
if (isRemoteTest()) {
- Assert.assertTrue(resultSender.isRemote());
+ Assert.assertTrue(receivedSender.isRemote());
} else {
- Assert.assertTrue(resultSender.isLocal());
+ Assert.assertTrue(receivedSender.isLocal());
+ }
+
+ if (Strings.isValid(expectedBranchGuid)) {
+ Assert.assertEquals(expectedBranchGuid, receivedBranchEvent.getBranchGuid());
}
- Assert.assertEquals(guid, resultBranchEvent.getBranchGuid());
- return topLevel;
}
protected boolean isRemoteTest() {
return false;
}
- public class BranchEventListener implements IBranchEventListener {
+ @AfterClass
+ public static void cleanUp() throws OseeCoreException {
+ Operations.executeWorkAndCheckStatus(new PurgeBranchHttpRequestOperation(topLevel, true));
+ }
+
+ private class BranchEventListener implements IBranchEventListener {
+ private BranchEvent branchEvent;
+ private Sender sender;
+ private boolean receivedUpdate = false;
- @Override
- public void handleBranchEvent(Sender sender, BranchEvent branchEvent) {
- resultBranchEvent = branchEvent;
- resultSender = sender;
+ public synchronized void reset() {
+ receivedUpdate = false;
}
@Override
public List<? extends IEventFilter> getEventFilters() {
return null;
}
- }
- @org.junit.AfterClass
- public static void cleanUpAfter() throws OseeCoreException {
- Operations.executeWorkAndCheckStatus(new PurgeBranchHttpRequestOperation(topLevel, true));
- }
-
- // artifact listener create for use by all tests to just capture result eventArtifacts for query
- private final BranchEventListener branchEventListener = new BranchEventListener();
+ @Override
+ public synchronized void handleBranchEvent(Sender sender, BranchEvent branchEvent) {
+ this.branchEvent = branchEvent;
+ this.sender = sender;
+ receivedUpdate = true;
+ notify();
+ }
- public void clearEventCollections() {
- resultBranchEvent = null;
- }
+ public synchronized Pair<Sender, BranchEvent> getResults() throws InterruptedException {
+ while (!receivedUpdate) {
+ wait();
+ }
+ receivedUpdate = false;
+ return new Pair<Sender, BranchEvent>(sender, branchEvent);
+ }
+ };
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtilityTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtilityTest.java
index f644bb237f..66c99ac784 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtilityTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/relation/order/RelationOrderMergeUtilityTest.java
@@ -27,16 +27,23 @@ import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.skynet.core.relation.RelationTypeManager;
+import org.eclipse.osee.framework.skynet.core.rule.OseeHousekeepingRule;
import org.eclipse.osee.framework.skynet.core.util.FrameworkTestUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.MethodRule;
/**
* @author Ryan Schmitt
*/
public class RelationOrderMergeUtilityTest {
+
+ @Rule
+ public final MethodRule oseeHousekeeping = new OseeHousekeepingRule();
+
private final IRelationTypeSide defaultHierarchy = CoreRelationTypes.Default_Hierarchical__Child;
private final IRelationSorterId ascOrder = RelationOrderBaseTypes.LEXICOGRAPHICAL_ASC;
private final IRelationSorterId descOrder = RelationOrderBaseTypes.LEXICOGRAPHICAL_DESC;
@@ -48,8 +55,7 @@ public class RelationOrderMergeUtilityTest {
@Before
public void createBranch() throws OseeCoreException {
- String branchName = GUID.create();
- destBranch = BranchManager.createWorkingBranch(BranchManager.getSystemRootBranch(), branchName, null);
+ destBranch = BranchManager.createWorkingBranch(BranchManager.getSystemRootBranch(), GUID.create(), null);
hierType = RelationTypeManager.getType(defaultHierarchy);
hierSide = defaultHierarchy.getSide();
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/rule/OseeHousekeepingRule.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/rule/OseeHousekeepingRule.java
new file mode 100644
index 0000000000..b1803f4eb3
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/rule/OseeHousekeepingRule.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.framework.skynet.core.rule;
+
+import java.util.Collection;
+import junit.framework.Assert;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * <p>
+ * Not related to {@link Rule}.
+ * </p>
+ * <p>
+ * Checks Artifact Cache for dirty artifacts. Executes after a passing test. Fails tests that have passed but left dirty
+ * artifacts in the cache.
+ * </p>
+ * <p>
+ * In the future the behavior of this class could be modified to clean up after a test, regardless of test's context.
+ * </p>
+ */
+public class OseeHousekeepingRule implements MethodRule {
+
+ @Override
+ public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ base.evaluate();
+ verify(method, target);
+ }
+ };
+ }
+
+ private void verify(FrameworkMethod method, Object target) throws Throwable {
+ final Collection<Artifact> dirtyArtifacts = ArtifactCache.getDirtyArtifacts();
+
+ if (!dirtyArtifacts.isEmpty()) {
+ StringBuilder entireMessage = new StringBuilder();
+ entireMessage.append("Dirty artifacts in Artifact Cache:");
+ for (Artifact artifact : dirtyArtifacts) {
+ entireMessage.append(String.format("\n[%s] of type [%s] found while executing: %s.%s()",
+ artifact.getName(), artifact.getArtifactType(), target.getClass().getSimpleName(), method.getName()));
+ }
+ Assert.fail(entireMessage.toString());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/utility/CsvArtifactTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/utility/CsvArtifactTest.java
index c2cd97ed1b..2caf239464 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/utility/CsvArtifactTest.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/utility/CsvArtifactTest.java
@@ -31,16 +31,20 @@ public class CsvArtifactTest {
private static String csvData = "Name, Value1, Value2\narf,1,3\nbarn,3,5";
private static String appendData = "snarf,6,3";
+ private static CsvArtifact csv;
+
@BeforeClass
@AfterClass
public static void cleanup() throws Exception {
+ if (csv == null) {
+ csv = CsvArtifact.getCsvArtifact(id, DemoSawBuilds.SAW_Bld_2, true);
+ }
Collection<Artifact> arts = ArtifactQuery.getArtifactListFromName(id, DemoSawBuilds.SAW_Bld_2, EXCLUDE_DELETED);
new PurgeArtifacts(arts).execute();
}
@org.junit.Test
public void testCreateCsvArtifact() throws Exception {
- CsvArtifact csv = CsvArtifact.getCsvArtifact(id, DemoSawBuilds.SAW_Bld_2, true);
assertEquals(csv.getCsvData(), "");
csv.getArtifact().setName(id);
csv.setCsvData(csvData);
@@ -49,18 +53,16 @@ public class CsvArtifactTest {
@org.junit.Test
public void testgetCsvArtifactAndAppendData() throws Exception {
- CsvArtifact csvArt = CsvArtifact.getCsvArtifact(id, DemoSawBuilds.SAW_Bld_2, false);
- assertNotNull(csvArt);
- assertEquals(csvData, csvArt.getCsvData());
- csvArt.appendData(appendData);
- csvArt.getArtifact().persist(getClass().getSimpleName());
+ assertNotNull(csv);
+ assertEquals(csvData, csv.getCsvData());
+ csv.appendData(appendData);
+ csv.getArtifact().persist(getClass().getSimpleName());
}
@org.junit.Test
public void testCsvGetData() throws Exception {
- CsvArtifact csvArt = CsvArtifact.getCsvArtifact(id, DemoSawBuilds.SAW_Bld_2, false);
- assertNotNull(csvArt);
- assertEquals(csvData + "\n" + appendData, csvArt.getCsvData());
+ assertNotNull(csv);
+ assertEquals(csvData + "\n" + appendData, csv.getCsvData());
}
}

Back to the top