Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmisinco2015-07-14 12:29:55 -0400
committerAngel Avila2015-09-11 20:56:25 -0400
commitcea7338a732b66baddf39d4669ef87106dd27a0b (patch)
treeacc0454476c1a8797f781f154d0f4868c215a0c1 /plugins/org.eclipse.osee.orcs.db.test
parent91d8f2a68588a6f022d711eace934295ad6b3ed4 (diff)
downloadorg.eclipse.osee-cea7338a732b66baddf39d4669ef87106dd27a0b.tar.gz
org.eclipse.osee-cea7338a732b66baddf39d4669ef87106dd27a0b.tar.xz
org.eclipse.osee-cea7338a732b66baddf39d4669ef87106dd27a0b.zip
feature[ats_ATS213170]: Create console command to purge attributes
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db.test')
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/IntegrationTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java82
2 files changed, 83 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/IntegrationTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/IntegrationTestSuite.java
index 21dfa03488..2089b69baa 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/IntegrationTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/IntegrationTestSuite.java
@@ -17,7 +17,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({LoaderTest.class, OseeInfoDataAccessorTest.class})
+@Suite.SuiteClasses({LoaderTest.class, OseeInfoDataAccessorTest.class, PurgeAttributeTest.class})
public class IntegrationTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java
new file mode 100644
index 0000000000..232c504150
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.db.intergration;
+
+import static org.eclipse.osee.orcs.db.intergration.IntegrationUtil.integrationRule;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.osee.jdbc.JdbcClient;
+import org.eclipse.osee.jdbc.JdbcService;
+import org.eclipse.osee.jdbc.JdbcStatement;
+import org.eclipse.osee.orcs.db.internal.callable.PurgeAttributesDatabaseTxCallable;
+import org.eclipse.osee.orcs.db.internal.sql.join.SqlJoinFactory;
+import org.eclipse.osee.orcs.db.mock.OsgiService;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+
+/**
+ * @author John Misinco
+ */
+public class PurgeAttributeTest {
+
+ @Rule
+ public TestRule db = integrationRule(this);
+
+ @OsgiService
+ public JdbcService jdbcService;
+ @OsgiService
+ public SqlJoinFactory sqlJoinFactory;
+
+ @Test
+ public void testPurgeAttribute() throws Exception {
+ JdbcClient jdbcClient = jdbcService.getClient();
+ JdbcStatement stmt = jdbcClient.getStatement();
+
+ int prePurgeAttributeCount = getCount(jdbcClient, "osee_attribute");
+ int preAttributeRows = getCount(jdbcClient, "osee_attribute where value = 'Software Requirements'");
+
+ Assert.assertTrue(preAttributeRows > 0);
+
+ int prePurgeTxsCount = getCount(jdbcClient, "osee_txs");
+
+ stmt.runPreparedQuery("select attr_id from osee_attribute where value = 'Software Requirements'");
+ List<Long> toPurge = new LinkedList<Long>();
+ while (stmt.next()) {
+ toPurge.add(stmt.getLong("attr_id"));
+ }
+
+ PurgeAttributesDatabaseTxCallable callable =
+ new PurgeAttributesDatabaseTxCallable(null, null, jdbcClient, sqlJoinFactory, toPurge, null);
+
+ callable.call();
+
+ int postPurgeAttributeCount = getCount(jdbcClient, "osee_attribute");
+ int postAttributeRows = getCount(jdbcClient, "osee_attribute where value = 'Software Requirements'");
+ int postPurgeTxsCount = getCount(jdbcClient, "osee_txs");
+
+ Assert.assertEquals(0, postAttributeRows);
+ Assert.assertEquals(prePurgeAttributeCount - preAttributeRows, postPurgeAttributeCount);
+ Assert.assertTrue(postPurgeAttributeCount < prePurgeAttributeCount);
+ Assert.assertTrue(postPurgeTxsCount < prePurgeTxsCount);
+ }
+
+ private int getCount(JdbcClient jdbcClient, String table) {
+ JdbcStatement stmt = jdbcClient.getStatement();
+ int toReturn = -1;
+ stmt.runPreparedQuery("select count(1) from " + table);
+ while (stmt.next()) {
+ toReturn = stmt.getInt(1);
+ }
+ return toReturn;
+ }
+}

Back to the top