summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid W. Miller2012-05-03 19:11:42 (EDT)
committer Roberto E. Escobar2012-05-03 19:11:42 (EDT)
commitc66946170431321ec20e8746e085718b27e6f391 (patch)
treec42528d5930045170b6e0ea55904103e935b257c
parentf5af88baf1b4d20701f5074fe2cc4e2321c14da3 (diff)
downloadorg.eclipse.osee-c66946170431321ec20e8746e085718b27e6f391.zip
org.eclipse.osee-c66946170431321ec20e8746e085718b27e6f391.tar.gz
org.eclipse.osee-c66946170431321ec20e8746e085718b27e6f391.tar.bz2
feature[ats_MCQKT]: Add branch creation from transaction with test
-rw-r--r--plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/OrcsIntegrationTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java122
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java6
3 files changed, 127 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/OrcsIntegrationTestSuite.java b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/OrcsIntegrationTestSuite.java
index 9041602..3948d77 100644
--- a/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/OrcsIntegrationTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/OrcsIntegrationTestSuite.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.orcs.core;
import org.eclipse.osee.orcs.core.internal.OrcsAttributeLoadingTest;
import org.eclipse.osee.orcs.core.internal.OrcsAttributeSearchTest;
+import org.eclipse.osee.orcs.core.internal.OrcsBranchTest;
import org.eclipse.osee.orcs.core.internal.OrcsQueryTest;
import org.eclipse.osee.orcs.core.internal.OrcsRelationLoadingTest;
import org.junit.runner.RunWith;
@@ -24,6 +25,7 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses({
OrcsAttributeLoadingTest.class,
OrcsAttributeSearchTest.class,
+ OrcsBranchTest.class,
OrcsQueryTest.class,
OrcsRelationLoadingTest.class})
public class OrcsIntegrationTestSuite {
diff --git a/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java
new file mode 100644
index 0000000..a3cba97
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.integration.test/src/org/eclipse/osee/orcs/core/internal/OrcsBranchTest.java
@@ -0,0 +1,122 @@
+/*
+ * Created on Apr 30, 2012
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.orcs.core.internal;
+
+import java.util.concurrent.Callable;
+import org.eclipse.osee.framework.core.data.TokenFactory;
+import org.eclipse.osee.framework.core.enums.BranchType;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.model.ReadableBranch;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.orcs.ApplicationContext;
+import org.eclipse.osee.orcs.OrcsApi;
+import org.eclipse.osee.orcs.OrcsBranch;
+import org.eclipse.osee.orcs.data.CreateBranchData;
+import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.db.mock.OseeDatabase;
+import org.eclipse.osee.orcs.db.mock.OsgiUtil;
+import org.eclipse.osee.orcs.search.QueryFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * @author David Miller
+ */
+
+public class OrcsBranchTest {
+
+ @Rule
+ public OseeDatabase db = new OseeDatabase("osee.demo.h2");
+
+ private OrcsApi orcsApi = null;
+ private OrcsBranch branchInterface = null;
+ private final ApplicationContext context = null; // TODO use real application context
+
+ private final static String ARTIFACT_NAME = "Joe Smith";
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+
+ orcsApi = OsgiUtil.getService(OrcsApi.class);
+
+ branchInterface = orcsApi.getBranchOps(context);
+ }
+
+ @Test
+ public void testCreateBranch() throws Exception {
+ Integer SOURCE_TX_ID = 13; // Chosen starting transaction on Common Branch
+ Integer CHANGED_TX_ID = 14; // Transaction containing tested change
+ Integer MERGE_DESTINATION_ID = -1; // only used on merge branches
+ Integer MERGE_POPULATE_BASE_TX_ID = -1; // only used on merge branches
+
+ // set up the query factory for the test
+ QueryFactory qf = orcsApi.getQueryFactory(context);
+
+ CreateBranchData createData = new CreateBranchData();
+ createData.setGuid(GUID.create());
+ createData.setName("Prior Branch");
+ createData.setBranchType(BranchType.WORKING);
+ createData.setCreationComment("Creation of initial working branch for test");
+ createData.setFromTransaction(TokenFactory.createTransaction(SOURCE_TX_ID));
+
+ ReadableArtifact createdBy =
+ qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne();
+ createData.setUserArtifact(createdBy);
+
+ createData.setAssociatedArtifact(createdBy);
+ createData.setDestinationBranchId(MERGE_DESTINATION_ID);
+
+ createData.setPopulateBaseTxFromAddressingQueryId(MERGE_POPULATE_BASE_TX_ID);
+ Callable<ReadableBranch> callable = branchInterface.createBranch(createData);
+ Assert.assertNotNull(callable);
+ ReadableBranch priorBranch = callable.call();
+
+ // in the database, on the common branch, the users are all created in transaction 14
+ // the common branch will have one user named Joe Smith
+
+ int coreResult = qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getList().size();
+ Assert.assertEquals(1, coreResult);
+
+ // we copied the branch at transaction 13, so, on the copied branch there will not be any
+ // user Joe Smith
+
+ int priorResult = qf.fromBranch(priorBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size();
+ Assert.assertEquals(0, priorResult);
+
+ // finally, we copy another branch at transaction id 14, this is the transaction that added the
+ // user Joe Smith, so if the code is correct, and the copy includes the final
+ // transaction, then this will produce the same result as the query of the common branch
+
+ CreateBranchData createDataNew = new CreateBranchData();
+ createDataNew.setGuid(GUID.create());
+ createDataNew.setName("PostBranch");
+ createDataNew.setBranchType(BranchType.WORKING);
+ createDataNew.setCreationComment("Creation of branch with transaction ID equal to the change test");
+ createDataNew.setFromTransaction(TokenFactory.createTransaction(CHANGED_TX_ID));
+
+ ReadableArtifact createdByNew =
+ qf.fromBranch(CoreBranches.COMMON).andNameEquals(ARTIFACT_NAME).getResults().getExactlyOne();
+ createData.setUserArtifact(createdByNew);
+
+ createData.setAssociatedArtifact(createdByNew);
+ createData.setDestinationBranchId(MERGE_DESTINATION_ID);
+
+ createData.setPopulateBaseTxFromAddressingQueryId(MERGE_POPULATE_BASE_TX_ID);
+ Callable<ReadableBranch> postCallable = branchInterface.createBranch(createDataNew);
+ Assert.assertNotNull(postCallable);
+ ReadableBranch postBranch = postCallable.call();
+
+ int postResult = qf.fromBranch(postBranch).andNameEquals(ARTIFACT_NAME).getResults().getList().size();
+ Assert.assertEquals(1, postResult);
+
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
index 1a02bfe..c382cf3 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/CreateBranchDatabaseTxCallable.java
@@ -49,7 +49,7 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
// descending order is used so that the most recent entry will be used if there are multiple rows with the same gamma (an error case)
private static final String SELECT_ADDRESSING =
- "SELECT gamma_id, mod_type FROM osee_txs txs WHERE txs.tx_current <> ? AND txs.branch_id = ? ORDER BY txs.transaction_id DESC";
+ "SELECT gamma_id, mod_type FROM osee_txs txs WHERE txs.tx_current <> ? AND txs.branch_id = ? AND txs.transaction_id <= ? ORDER BY txs.transaction_id DESC";
private static final String INSERT_ADDRESSING =
"INSERT INTO osee_txs (transaction_id, gamma_id, mod_type, tx_current, branch_id) VALUES (?,?,?,?,?)";
private static final String USER_ID_QUERY = "SELECT art_id FROM osee_artifact WHERE guid = ?";
@@ -223,14 +223,14 @@ public class CreateBranchDatabaseTxCallable extends DatabaseTxCallable<Branch> {
parentBranchId = branch.getParentBranch().getId();
}
int baseTxId = branch.getBaseTransaction().getId();
- if (populateBaseTxFromAddressingQueryId > 0) {
+ if (branch.getBranchType().isMergeBranch()) {
populateAddressingToCopy(connection, data, baseTxId, gammas, SELECT_ATTRIBUTE_ADDRESSING_FROM_JOIN,
parentBranchId, TxChange.NOT_CURRENT.getValue(), populateBaseTxFromAddressingQueryId);
populateAddressingToCopy(connection, data, baseTxId, gammas, SELECT_ARTIFACT_ADDRESSING_FROM_JOIN,
parentBranchId, TxChange.NOT_CURRENT.getValue(), populateBaseTxFromAddressingQueryId);
} else {
populateAddressingToCopy(connection, data, baseTxId, gammas, SELECT_ADDRESSING,
- TxChange.NOT_CURRENT.getValue(), parentBranchId);
+ TxChange.NOT_CURRENT.getValue(), parentBranchId, branch.getSourceTransaction().getId());
}
if (!data.isEmpty()) {
getDatabaseService().runBatchUpdate(connection, INSERT_ADDRESSING, data);