diff options
5 files changed, 196 insertions, 4 deletions
diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/ConflictIntroduceTest.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/ConflictIntroduceTest.java new file mode 100644 index 00000000000..accc4607ff4 --- /dev/null +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/ConflictIntroduceTest.java @@ -0,0 +1,191 @@ +/******************************************************************************* + * Copyright (c) 2014 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.client.integration.tests.integration.skynet.core; + +import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.util.Collection; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.osee.client.demo.DemoBranches; +import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule; +import org.eclipse.osee.client.test.framework.OseeLogMonitorRule; +import org.eclipse.osee.framework.core.data.IOseeBranch; +import org.eclipse.osee.framework.core.data.TokenFactory; +import org.eclipse.osee.framework.core.enums.CoreArtifactTypes; +import org.eclipse.osee.framework.core.enums.CoreAttributeTypes; +import org.eclipse.osee.framework.core.model.Branch; +import org.eclipse.osee.framework.core.operation.Operations; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts; +import org.eclipse.osee.framework.skynet.core.artifact.Artifact; +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.conflict.Conflict; +import org.eclipse.osee.framework.skynet.core.conflict.ConflictManagerExternal; +import org.eclipse.osee.framework.skynet.core.revision.ConflictManagerInternal; +import org.eclipse.osee.framework.ui.skynet.update.InterArtifactExplorerDropHandlerOperation; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; + +/** + * @author Megumi Telles + */ +public class ConflictIntroduceTest { + + @Rule + public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_CLIENT_DEMO); + + @Rule + public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule(); + + private static IOseeBranch sourceBranch; + private static IOseeBranch destinationBranch; + private static IOseeBranch updateBranch; + + private static Artifact artifactToDelete; + + private static String TESTNAME = "ConflictIntroduceTest"; + + @BeforeClass + public static void setUp() throws Exception { + sourceBranch = createBranchToken("Source"); + destinationBranch = createBranchToken("Destination"); + updateBranch = createBranchToken("Update"); + + // set up destination branch + BranchManager.createWorkingBranch(DemoBranches.SAW_Bld_1, destinationBranch); + artifactToDelete = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.SoftwareRequirement, "Read-only Robots", + DemoBranches.SAW_Bld_1); + + // Delete artifact and commit to destination branch + BranchManager.createWorkingBranch(destinationBranch, updateBranch); + Artifact art = ArtifactQuery.getArtifactFromId(artifactToDelete.getArtId(), updateBranch); + art.deleteAndPersist(); + + ConflictManagerExternal conflictManager = new ConflictManagerExternal(destinationBranch, updateBranch); + BranchManager.commitBranch(null, conflictManager, false, false); + + // create source branch + BranchManager.createWorkingBranch(destinationBranch, sourceBranch); + + } + + @Test + public void testIntroduceNoConflict() { + // Introduce the artifact + InterArtifactExplorerDropHandlerOperation dropHandler = + new InterArtifactExplorerDropHandlerOperation( + OseeSystemArtifacts.getDefaultHierarchyRootArtifact(sourceBranch), new Artifact[] {artifactToDelete}, false); + Operations.executeWork(dropHandler); + // Acquire the introduced artifact + Artifact destArtifact = ArtifactQuery.getArtifactFromId(artifactToDelete.getArtId(), sourceBranch); + Assert.assertNotNull(destArtifact); + + // check for conflicts....there should be no conflict in this case. + Collection<Conflict> conflicts = null; + Branch sBranch = BranchManager.getBranch(sourceBranch); + Branch dBranch = BranchManager.getBranch(destinationBranch); + try { + conflicts = + ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch), + new NullProgressMonitor()); + } catch (Exception ex) { + fail(Lib.exceptionToString(ex)); + } + assertTrue("Unexpected conflict found", conflicts.size() == 0); + } + + @Test + public void testModifiedButDeletedConflict() { + + Artifact artifactToModify = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Cognitive_Decision_Aiding", + destinationBranch); + assertNotNull(artifactToModify); + artifactToModify.setSoleAttributeFromString(CoreAttributeTypes.Name, "Cognitive_Decision_Aiding2"); + artifactToModify.persist(TESTNAME); + + Artifact dArtifact = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Cognitive_Decision_Aiding", + sourceBranch); + assertNotNull(dArtifact); + dArtifact.deleteAndPersist(); + + // check for conflict....this should be a conflict + Collection<Conflict> conflicts = null; + Branch sBranch = BranchManager.getBranch(sourceBranch); + Branch dBranch = BranchManager.getBranch(destinationBranch); + try { + conflicts = + ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch), + new NullProgressMonitor()); + } catch (Exception ex) { + fail(Lib.exceptionToString(ex)); + } + assertTrue("Expected conflict not found", conflicts.size() == 2); + } + + @Test + public void testDeletedButModifiedConflict() { + Artifact dArtifact = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Chassis", sourceBranch); + assertNotNull(dArtifact); + dArtifact.deleteAndPersist(); + + Artifact artifactToModify = + ArtifactQuery.getArtifactFromTypeAndName(CoreArtifactTypes.Component, "Chassis", destinationBranch); + assertNotNull(artifactToModify); + artifactToModify.setSoleAttributeFromString(CoreAttributeTypes.Name, "Chassis2"); + artifactToModify.persist(TESTNAME); + + // check for conflict....this should be a conflict + Collection<Conflict> conflicts = null; + Branch sBranch = BranchManager.getBranch(sourceBranch); + Branch dBranch = BranchManager.getBranch(destinationBranch); + try { + conflicts = + ConflictManagerInternal.getConflictsPerBranch(sBranch, dBranch, BranchManager.getBaseTransaction(sBranch), + new NullProgressMonitor()); + } catch (Exception ex) { + fail(Lib.exceptionToString(ex)); + } + assertTrue("Expected conflict not found", conflicts.size() == 1); + } + + @AfterClass + public static void tearDown() throws Exception { + BranchManager.refreshBranches(); + Branch mBranch = null; + if (sourceBranch != null && destinationBranch != null) { + mBranch = BranchManager.getMergeBranch(sourceBranch, destinationBranch); + } + + BranchManager.purgeBranch(mBranch); + Thread.sleep(10000); + BranchManager.purgeBranch(updateBranch); + Thread.sleep(10000); + BranchManager.purgeBranch(sourceBranch); + Thread.sleep(10000); + BranchManager.purgeBranch(destinationBranch); + } + + private static IOseeBranch createBranchToken(String name) { + String branchName = String.format("%s__%s", TESTNAME, name); + return TokenFactory.createBranch(branchName); + } + +} diff --git a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/XSkynetCoreIntegrationTestSuite.java b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/XSkynetCoreIntegrationTestSuite.java index 6ac19969dcf..b19f3bffdcd 100644 --- a/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/XSkynetCoreIntegrationTestSuite.java +++ b/plugins/org.eclipse.osee.client.integration.tests/src/org/eclipse/osee/client/integration/tests/integration/skynet/core/XSkynetCoreIntegrationTestSuite.java @@ -33,6 +33,7 @@ import org.junit.runners.Suite; BranchStateTest.class, ChangeManagerTest.class, ConflictDeletionTest.class, + ConflictIntroduceTest.class, ConflictTest.class, CreateBranchOperationTest.class, CrossBranchRelationLinkTest.class, diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItemUtil.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItemUtil.java index dc3b938e61a..79cf7dd2a02 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItemUtil.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/change/ChangeItemUtil.java @@ -120,7 +120,7 @@ public final class ChangeItemUtil { isAlreadyOnDestination(changeItem) || // isDeletedAndDoesNotExistInDestination(changeItem) || // (hasBeenDeletedInDestination(changeItem) && !isResurrected(changeItem)) || // - hasBeenReplacedWithVersion(changeItem); + (hasBeenReplacedWithVersion(changeItem) && !isResurrected(changeItem)); } public static boolean wasCreatedAndDeleted(ChangeItem changeItem) { diff --git a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeSql.java b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeSql.java index 92d8ba300cc..7673092c306 100644 --- a/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeSql.java +++ b/plugins/org.eclipse.osee.framework.database/src/org/eclipse/osee/framework/database/core/OseeSql.java @@ -32,8 +32,8 @@ public enum OseeSql { MERGE_GET_ATTRIBUTES_FOR_BRANCH("SELECT atr.art_id, atr.attr_id FROM osee_txs txs, osee_attribute atr WHERE txs.branch_id = ? and txs.gamma_id = atr.gamma_id"), MERGE_GET_RELATIONS_FOR_BRANCH("SELECT rel.a_art_id, rel.b_art_id FROM osee_txs txs, osee_relation_link rel WHERE txs.branch_id = ? and txs.gamma_id = rel.gamma_id"), - CONFLICT_GET_ARTIFACTS_DEST("SELECT%s art2.art_type_id, art1.art_id, txs1.mod_type AS source_mod_type, txs1.gamma_id AS source_gamma, txs2.mod_type AS dest_mod_type, txs2.gamma_id AS dest_gamma FROM osee_txs txs1, osee_attribute art1, osee_artifact art2, osee_txs txs2 WHERE txs1.branch_id = ? AND txs1.transaction_id <> ? AND txs1.tx_current in (1,2) AND txs1.gamma_id = art1.gamma_id AND art1.art_id = art2.art_id AND art2.gamma_id = txs2.gamma_id AND txs2.branch_id = ? AND ((txs2.tx_current = 1 AND txs2.gamma_id not in (SELECT txs.gamma_id FROM osee_txs txs WHERE branch_id = ? AND txs.transaction_id = ?)) OR txs2.tx_current = 2) ORDER BY art2.art_id", Strings.HINTS__ORDERED__INDEX__ARTIFACT_CONFLICT), - CONFLICT_GET_ARTIFACTS_SRC("SELECT%s art1.art_type_id, art1.art_id, txs1.mod_type AS source_mod_type, txs1.gamma_id AS source_gamma, txs2.mod_type AS dest_mod_type, txs2.gamma_id AS dest_gamma FROM osee_txs txs1, osee_artifact art1, osee_attribute art2, osee_txs txs2 WHERE txs1.branch_id = ? AND txs1.transaction_id <> ? AND txs1.tx_current in (1,2) AND txs1.gamma_id = art1.gamma_id AND art1.art_id = art2.art_id AND art2.gamma_id = txs2.gamma_id AND txs2.branch_id = ? AND ((txs2.tx_current = 1 AND txs2.gamma_id not in (SELECT txs.gamma_id FROM osee_txs txs WHERE txs.branch_id = ? AND txs.transaction_id = ?)) OR txs2.tx_current = 2) ORDER BY art1.art_id", Strings.HINTS__ORDERED__INDEX__ARTIFACT_CONFLICT), + CONFLICT_GET_ARTIFACTS_DEST("SELECT%s art2.art_type_id, art1.art_id, txs1.mod_type AS source_mod_type, txs1.gamma_id AS source_gamma, txs2.mod_type AS dest_mod_type, txs2.gamma_id AS dest_gamma FROM osee_txs txs1, osee_attribute art1, osee_artifact art2, osee_txs txs2 WHERE txs1.branch_id = ? AND txs1.transaction_id <> ? AND txs1.tx_current in (1,2) AND txs1.gamma_id = art1.gamma_id AND art1.art_id = art2.art_id AND art2.gamma_id = txs2.gamma_id AND txs2.branch_id = ? AND ((txs2.tx_current = 1 AND txs2.gamma_id not in (SELECT txs.gamma_id FROM osee_txs txs WHERE branch_id = ? AND txs.transaction_id = ?)) OR (txs2.tx_current = 2 and txs2.transaction_id > ?)) ORDER BY art2.art_id", Strings.HINTS__ORDERED__INDEX__ARTIFACT_CONFLICT), + CONFLICT_GET_ARTIFACTS_SRC("SELECT%s art1.art_type_id, art1.art_id, txs1.mod_type AS source_mod_type, txs1.gamma_id AS source_gamma, txs2.mod_type AS dest_mod_type, txs2.gamma_id AS dest_gamma FROM osee_txs txs1, osee_artifact art1, osee_attribute art2, osee_txs txs2 WHERE txs1.branch_id = ? AND txs1.transaction_id <> ? AND txs1.tx_current in (1,2) AND txs1.gamma_id = art1.gamma_id AND art1.art_id = art2.art_id AND art2.gamma_id = txs2.gamma_id AND txs2.branch_id = ? AND ((txs2.tx_current = 1 AND txs2.gamma_id not in (SELECT txs.gamma_id FROM osee_txs txs WHERE txs.branch_id = ? AND txs.transaction_id = ?)) OR (txs2.tx_current = 2 and txs2.transaction_id > ?)) ORDER BY art1.art_id", Strings.HINTS__ORDERED__INDEX__ARTIFACT_CONFLICT), CONFLICT_GET_ATTRIBUTES("SELECT%s atr1.art_id, txs1.mod_type, atr1.attr_type_id, atr1.attr_id, atr1.gamma_id AS source_gamma, atr1.value AS source_value, atr2.gamma_id AS dest_gamma, atr2.value as dest_value, txs2.mod_type AS dest_mod_type FROM osee_txs txs1, osee_attribute atr1, osee_attribute atr2, osee_txs txs2 WHERE txs1.branch_id = ? AND txs1.transaction_id <> ? AND txs1.tx_current in (1,2) AND txs1.gamma_id = atr1.gamma_id AND atr1.attr_id = atr2.attr_id AND atr2.gamma_id = txs2.gamma_id AND txs2.branch_id = ? AND txs2.tx_current in (1,2) AND NOT EXISTS (SELECT 1 FROM osee_txs txs WHERE txs.branch_id = ? AND txs.transaction_id = ? AND ((txs1.gamma_id = txs.gamma_id and txs1.mod_type = txs.mod_type) OR (txs2.gamma_id = txs.gamma_id and txs2.mod_type = txs.mod_type))) ORDER BY attr_id", Strings.HINTS__ORDERED__INDEX__ATTRIBUTE_CONFLICT), CONFLICT_GET_HISTORICAL_ATTRIBUTES("SELECT%s atr.attr_id, atr.art_id, source_gamma_id, dest_gamma_id, attr_type_id, mer.merge_branch_id, mer.dest_branch_id, value as source_value, status FROM osee_merge mer, osee_conflict con, osee_attribute atr Where mer.commit_transaction_id = ? AND mer.merge_branch_id = con.merge_branch_id And con.source_gamma_id = atr.gamma_id AND con.status in (" + ConflictStatus.COMMITTED.getValue() + ", " + ConflictStatus.INFORMATIONAL.getValue() + " ) order by attr_id", getHintsOrderedFirstRows()), diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ConflictManagerInternal.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ConflictManagerInternal.java index fdc5e607ded..843345fdd5e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ConflictManagerInternal.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/revision/ConflictManagerInternal.java @@ -179,7 +179,7 @@ public class ConflictManagerInternal { long commonBranchId = transactionId != null ? transactionId.getBranchId() : 0; chStmt.runPreparedQuery(sql, sourceBranch.getUuid(), sourceBranch.getBaseTransaction().getId(), - destinationBranch.getUuid(), commonBranchId, commonTransactionNumber); + destinationBranch.getUuid(), commonBranchId, commonTransactionNumber, commonTransactionNumber); ArtifactConflictBuilder artifactConflictBuilder; int artId = 0; |