Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.osee.orcs.db.test')
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java57
2 files changed, 55 insertions, 5 deletions
diff --git a/plugins/org.eclipse.osee.orcs.db.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.db.test/META-INF/MANIFEST.MF
index 80cfc5b799c..e6ebb1c67ad 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.db.test/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Import-Package: org.eclipse.osee.framework.core.data,
org.eclipse.osee.framework.resource.management.exception,
org.eclipse.osee.framework.resource.management.util,
org.eclipse.osee.orcs.core.ds,
- org.eclipse.osee.orcs.db.mock
+ org.eclipse.osee.orcs.db.mock,
+ org.eclipse.osee.orcs.transaction
Require-Bundle: org.eclipse.osee.framework.core,
org.junit,
org.mockito;bundle-version="1.9.0",
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
index d9612a2c206..0a379256dff 100644
--- 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
@@ -13,13 +13,23 @@ 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.framework.core.data.ArtifactId;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTokens;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcService;
import org.eclipse.osee.jdbc.JdbcStatement;
+import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.data.ArtifactReadable;
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.eclipse.osee.orcs.transaction.TransactionBuilder;
+import org.junit.After;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
@@ -29,27 +39,65 @@ import org.junit.rules.TestRule;
*/
public class PurgeAttributeTest {
+ private static final ArtifactId Joe_Smith = ArtifactId.valueOf(61106791L);
+
+ private static final String UNIQUE_ATTR_VALUE = "AEqvcQoyRV8zNDZSBVAA";
+
@Rule
public TestRule db = integrationRule(this);
@OsgiService
+ public OrcsApi orcsApi;
+
+ @OsgiService
public JdbcService jdbcService;
@OsgiService
public SqlJoinFactory sqlJoinFactory;
+ @After
+ @Before
+ public void setupAndTeardown() {
+ TransactionBuilder tx = null;
+ for (ArtifactReadable art : orcsApi.getQueryFactory().fromBranch(CoreBranches.COMMON_ID).and(
+ CoreAttributeTypes.Annotation, UNIQUE_ATTR_VALUE).getResults()) {
+ if (tx != null) {
+ tx = orcsApi.getTransactionFactory().createTransaction(CoreBranches.COMMON_ID, Joe_Smith,
+ getClass().getSimpleName());
+ }
+ tx.deleteArtifact(art);
+ }
+ if (tx != null) {
+ tx.commit();
+ }
+ }
+
@Test
public void testPurgeAttribute() throws Exception {
JdbcClient jdbcClient = jdbcService.getClient();
+
+ if (jdbcClient.getConfig().isProduction()) {
+ throw new OseeStateException("Test should not be run against a Production Database");
+ }
+
+ // Setup test
+ TransactionBuilder tx = orcsApi.getTransactionFactory().createTransaction(CoreBranches.COMMON_ID, Joe_Smith,
+ getClass().getSimpleName());
+ tx.createAttribute(CoreArtifactTokens.UserGroups, CoreAttributeTypes.Annotation, UNIQUE_ATTR_VALUE);
+ tx.createAttribute(CoreArtifactTokens.Everyone, CoreAttributeTypes.Annotation, UNIQUE_ATTR_VALUE);
+ tx.createAttribute(CoreArtifactTokens.OseeAdmin, CoreAttributeTypes.Annotation, UNIQUE_ATTR_VALUE);
+ tx.commit();
+
JdbcStatement stmt = jdbcClient.getStatement();
int prePurgeAttributeCount = getCount(jdbcClient, "osee_attribute");
- int preAttributeRows = getCount(jdbcClient, "osee_attribute where value = 'Software Requirements'");
+ int preAttributeRows =
+ getCount(jdbcClient, String.format("osee_attribute where value = '%s'", UNIQUE_ATTR_VALUE));
- Assert.assertTrue(preAttributeRows > 0);
+ Assert.assertTrue(preAttributeRows == 3);
int prePurgeTxsCount = getCount(jdbcClient, "osee_txs");
- stmt.runPreparedQuery("select attr_id from osee_attribute where value = 'Software Requirements'");
+ stmt.runPreparedQuery(String.format("select attr_id from osee_attribute where value = '%s'", UNIQUE_ATTR_VALUE));
List<Long> toPurge = new LinkedList<>();
while (stmt.next()) {
toPurge.add(stmt.getLong("attr_id"));
@@ -61,7 +109,8 @@ public class PurgeAttributeTest {
callable.call();
int postPurgeAttributeCount = getCount(jdbcClient, "osee_attribute");
- int postAttributeRows = getCount(jdbcClient, "osee_attribute where value = 'Software Requirements'");
+ int postAttributeRows =
+ getCount(jdbcClient, String.format("osee_attribute where value = '%s'", UNIQUE_ATTR_VALUE));
int postPurgeTxsCount = getCount(jdbcClient, "osee_txs");
Assert.assertEquals(0, postAttributeRows);

Back to the top