Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2009-05-28 19:34:03 +0000
committerddunne2009-05-28 19:34:03 +0000
commiteaa8043a131c44db6652a3805150e49bec484107 (patch)
treeabaed97f37045258839a9baf54de3e8eb1aaced3
parent29c42026cb616c05554375e9f0ded83e5e380212 (diff)
downloadorg.eclipse.osee-eaa8043a131c44db6652a3805150e49bec484107.tar.gz
org.eclipse.osee-eaa8043a131c44db6652a3805150e49bec484107.tar.xz
org.eclipse.osee-eaa8043a131c44db6652a3805150e49bec484107.zip
PurgeBranchTest
-rw-r--r--org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/FrameworkCore_Demo_Suite.java2
-rw-r--r--org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/ArtifactPurgeTest.java42
-rw-r--r--org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/BranchPurgeTest.java111
-rw-r--r--org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/util/FrameworkTestUtil.java33
4 files changed, 171 insertions, 17 deletions
diff --git a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/FrameworkCore_Demo_Suite.java b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/FrameworkCore_Demo_Suite.java
index ea73fa730c0..8f0bda4e13f 100644
--- a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/FrameworkCore_Demo_Suite.java
+++ b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/FrameworkCore_Demo_Suite.java
@@ -14,6 +14,7 @@ import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.osee.framework.skynet.core.test2.cases.ArtifactPurgeTest;
import org.eclipse.osee.framework.skynet.core.test2.cases.Artifact_setAttributeValues;
+import org.eclipse.osee.framework.skynet.core.test2.cases.BranchPurgeTest;
import org.eclipse.osee.framework.skynet.core.test2.cases.CsvArtifactTest;
import org.eclipse.osee.framework.skynet.core.test2.cases.NativeArtifactTest;
@@ -26,6 +27,7 @@ public class FrameworkCore_Demo_Suite extends TestSuite {
TestSuite suite = new TestSuite("FrameworkCore_Demo_Suite");
//$JUnit-BEGIN$
suite.addTestSuite(ArtifactPurgeTest.class);
+ suite.addTestSuite(BranchPurgeTest.class);
suite.addTestSuite(Artifact_setAttributeValues.class);
suite.addTestSuite(CsvArtifactTest.class);
suite.addTestSuite(NativeArtifactTest.class);
diff --git a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/ArtifactPurgeTest.java b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/ArtifactPurgeTest.java
index a735c730f02..9e1ebcb5170 100644
--- a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/ArtifactPurgeTest.java
+++ b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/ArtifactPurgeTest.java
@@ -19,6 +19,7 @@ import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.eclipse.osee.framework.db.connection.OseeDbConnection;
+import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactPersistenceManager;
import org.eclipse.osee.framework.skynet.core.artifact.Branch;
@@ -33,18 +34,17 @@ import org.eclipse.osee.support.test.util.TestUtil;
/**
* This test is intended to be run against a demo database. It tests the purge logic by counting the rows of the version
- * and txs tables, then adds an Action, Workflow and 30 Tasks, deletes these objects and compares the row count. If
- * purge works properly, all rows should be equal. This test is intended to be run against a demo database. It tests the
- * purge logic by counting the rows of the version and txs tables, createing artifacts, changing them and then purging
- * them. If it works properly, all rows should be equal.
+ * and txs tables, createing artifacts, changing them and then purging them. If it works properly, all rows should be
+ * equal.
*
* @author Donald G. Dunne
*/
public class ArtifactPurgeTest extends TestCase {
- private final Map<String, Integer> preCreateActionCount = new HashMap<String, Integer>();
- private final Map<String, Integer> postCreateActionCount = new HashMap<String, Integer>();
+ private final Map<String, Integer> preCreateArtifactsCount = new HashMap<String, Integer>();
+ private final Map<String, Integer> postCreateArtifactsCount = new HashMap<String, Integer>();
private final Map<String, Integer> postPurgeCount = new HashMap<String, Integer>();
+ private static SevereLoggingMonitor monitorLog;
List<String> tables =
Arrays.asList("osee_attribute", "osee_artifact", "osee_relation_link", "osee_tx_details", "osee_txs",
"osee_artifact_version");
@@ -58,9 +58,13 @@ public class ArtifactPurgeTest extends TestCase {
assertFalse(TestUtil.isProductionDb());
}
+ public void testInitialize() throws Exception {
+ monitorLog = TestUtil.severeLoggingStart();
+ }
+
public void testPurgeArtifacts() throws Exception {
// Count rows in tables prior to purge
- DbUtil.getTableRowCounts(preCreateActionCount, tables);
+ DbUtil.getTableRowCounts(preCreateArtifactsCount, tables);
Set<Artifact> artsToPurge = new HashSet<Artifact>();
@@ -78,26 +82,26 @@ public class ArtifactPurgeTest extends TestCase {
// make more changes to artifacts
for (Artifact softArt : softArts) {
softArt.addAttribute(StaticIdManager.STATIC_ID_ATTRIBUTE, getClass().getSimpleName());
- softArt.persistAttributesAndRelations(transaction);
+ softArt.persistAttributesAndRelations();
}
// Count rows and check that increased
- DbUtil.getTableRowCounts(postCreateActionCount, tables);
- TestUtil.checkThatIncreased(preCreateActionCount, postCreateActionCount);
+ DbUtil.getTableRowCounts(postCreateArtifactsCount, tables);
+ TestUtil.checkThatIncreased(preCreateArtifactsCount, postCreateArtifactsCount);
- // Purge Action, Workflow and Tasks
+ // Purge
ArtifactPersistenceManager.purgeArtifacts(artsToPurge);
// Count rows and check that same as when began
DbUtil.getTableRowCounts(postPurgeCount, tables);
// TODO Looks like attributes created after initial artifact creation are not getting purged. Needs Fix.
- TestUtil.checkThatEqual(preCreateActionCount, postPurgeCount);
+ TestUtil.checkThatEqual(preCreateArtifactsCount, postPurgeCount);
}
public void testPurgeArtifactFromBranch() throws Exception {
// Count rows in tables prior to purge
- DbUtil.getTableRowCounts(preCreateActionCount, tables);
+ DbUtil.getTableRowCounts(preCreateArtifactsCount, tables);
// Create some software artifacts
Branch branch = BranchManager.getKeyedBranch(DemoSawBuilds.SAW_Bld_2.name());
@@ -110,11 +114,11 @@ public class ArtifactPurgeTest extends TestCase {
// make more changes to artifact
softArt.addAttribute(StaticIdManager.STATIC_ID_ATTRIBUTE, getClass().getSimpleName());
- softArt.persistAttributesAndRelations(transaction);
+ softArt.persistAttributesAndRelations();
// Count rows and check that increased
- DbUtil.getTableRowCounts(postCreateActionCount, tables);
- TestUtil.checkThatIncreased(preCreateActionCount, postCreateActionCount);
+ DbUtil.getTableRowCounts(postCreateArtifactsCount, tables);
+ TestUtil.checkThatIncreased(preCreateArtifactsCount, postCreateArtifactsCount);
// Purge artifact
ArtifactPersistenceManager.purgeArtifactFromBranch(OseeDbConnection.getConnection(), branch.getBranchId(),
@@ -123,7 +127,11 @@ public class ArtifactPurgeTest extends TestCase {
// Count rows and check that same as when began
DbUtil.getTableRowCounts(postPurgeCount, tables);
// TODO Looks like attributes created after initial artifact creation are not getting purged. Needs Fix.
- TestUtil.checkThatEqual(preCreateActionCount, postPurgeCount);
+ TestUtil.checkThatEqual(preCreateArtifactsCount, postPurgeCount);
+ }
+
+ public void testCleanup() throws Exception {
+ TestUtil.severeLoggingEnd(monitorLog);
}
}
diff --git a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/BranchPurgeTest.java b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/BranchPurgeTest.java
new file mode 100644
index 00000000000..a9edecd38a4
--- /dev/null
+++ b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/cases/BranchPurgeTest.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 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.test2.cases;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.eclipse.osee.framework.core.data.SystemUser;
+import org.eclipse.osee.framework.skynet.core.UserManager;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.Branch;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
+import org.eclipse.osee.framework.skynet.core.artifact.StaticIdManager;
+import org.eclipse.osee.framework.skynet.core.test2.util.FrameworkTestUtil;
+import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
+import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
+import org.eclipse.osee.framework.skynet.core.utility.Requirements;
+import org.eclipse.osee.support.test.util.DemoSawBuilds;
+import org.eclipse.osee.support.test.util.TestUtil;
+
+/**
+ * This test is intended to be run against a demo database. It tests the branch purge logic by counting the rows of the
+ * version and txs tables, creating a branch, making changes and then purging the branch. If it works properly, all rows
+ * should be equal.
+ *
+ * @author Donald G. Dunne
+ */
+public class BranchPurgeTest extends TestCase {
+
+ private final Map<String, Integer> preCreateCount = new HashMap<String, Integer>();
+ private final Map<String, Integer> postCreateBranchCount = new HashMap<String, Integer>();
+ private final Map<String, Integer> postPurgeCount = new HashMap<String, Integer>();
+ List<String> tables =
+ Arrays.asList("osee_attribute", "osee_artifact", "osee_relation_link", "osee_tx_details", "osee_txs",
+ "osee_artifact_version");
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ // This test should only be run on test db
+ assertFalse(TestUtil.isProductionDb());
+ }
+
+ public void testCleanupPre() throws Exception {
+ cleanup();
+ }
+
+ public void testPurgeBranch() throws Exception {
+ // Count rows in tables prior to purge
+ DbUtil.getTableRowCounts(preCreateCount, tables);
+
+ // create a new working branch
+ Branch branch =
+ BranchManager.createWorkingBranch(BranchManager.getKeyedBranch(DemoSawBuilds.SAW_Bld_2.name()),
+ getClass().getSimpleName(), UserManager.getUser(SystemUser.OseeSystem));
+
+ TestUtil.sleep(4000);
+
+ // create some software artifacts
+ SkynetTransaction transaction = new SkynetTransaction(branch);
+ Collection<Artifact> softArts =
+ FrameworkTestUtil.createSimpleArtifacts(Requirements.SOFTWARE_REQUIREMENT, 10, getClass().getSimpleName(),
+ branch);
+ for (Artifact softArt : softArts) {
+ softArt.persistAttributesAndRelations(transaction);
+ }
+ transaction.execute();
+
+ // make more changes to artifacts
+ for (Artifact softArt : softArts) {
+ softArt.addAttribute(StaticIdManager.STATIC_ID_ATTRIBUTE, getClass().getSimpleName());
+ softArt.persistAttributesAndRelations();
+ }
+
+ // Count rows and check that increased
+ DbUtil.getTableRowCounts(postCreateBranchCount, tables);
+ TestUtil.checkThatIncreased(preCreateCount, postCreateBranchCount);
+
+ // Purge branch
+ BranchManager.purgeBranch(branch);
+
+ TestUtil.sleep(4000);
+
+ // Count rows and check that same as when began
+ DbUtil.getTableRowCounts(postPurgeCount, tables);
+ // TODO looks like artifacts are not being removed when purge a branch
+ TestUtil.checkThatEqual(preCreateCount, postPurgeCount);
+
+ }
+
+ public void testCleanupPost() throws Exception {
+ cleanup();
+ }
+
+ private void cleanup() throws Exception {
+ FrameworkTestUtil.purgeWorkingBranches(Arrays.asList(getClass().getSimpleName()));
+ }
+}
diff --git a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/util/FrameworkTestUtil.java b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/util/FrameworkTestUtil.java
index b9b66ba2882..8477326e9be 100644
--- a/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/util/FrameworkTestUtil.java
+++ b/org.eclipse.osee.framework.skynet.core.test2/src/org/eclipse/osee/framework/skynet/core/test2/util/FrameworkTestUtil.java
@@ -8,12 +8,18 @@ package org.eclipse.osee.framework.skynet.core.test2.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.db.connection.exception.BranchDoesNotExist;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.Branch;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchArchivedState;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchControlled;
+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.CoreRelationEnumeration;
import org.eclipse.osee.support.test.util.DemoSubsystems;
+import org.eclipse.osee.support.test.util.TestUtil;
/**
* @author Donald G. Dunne
@@ -44,4 +50,31 @@ public class FrameworkTestUtil {
}
return arts;
}
+
+ public static void purgeBranch(Branch branch) throws Exception {
+ try {
+ BranchManager.purgeBranchInJob(branch);
+ TestUtil.sleep(2000);
+ } catch (BranchDoesNotExist ex) {
+ // do nothing
+ }
+ }
+
+ public static void purgeWorkingBranches(Collection<String> branchNamesContain) throws Exception {
+ try {
+ // delete working branches
+ for (Branch workingBranch : BranchManager.getBranches(BranchArchivedState.ALL, BranchControlled.ALL,
+ BranchType.WORKING)) {
+ for (String branchName : branchNamesContain) {
+ if (workingBranch.getBranchName().contains(branchName)) {
+ BranchManager.purgeBranchInJob(workingBranch);
+ TestUtil.sleep(2000);
+ }
+ }
+ }
+ } catch (BranchDoesNotExist ex) {
+ // do nothing
+ }
+ }
+
}

Back to the top