diff options
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db.test')
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 21dfa034886..2089b69baae 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 00000000000..232c5041503 --- /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; + } +} |