Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/creation/CreateBranchOperation.java8
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java2
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/BranchSuite.java20
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/CreateBranchOperationTest.java113
4 files changed, 140 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/creation/CreateBranchOperation.java b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/creation/CreateBranchOperation.java
index e2a3c06c29b..b8b64643d5e 100644
--- a/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/creation/CreateBranchOperation.java
+++ b/plugins/org.eclipse.osee.framework.branch.management/src/org/eclipse/osee/framework/branch/management/creation/CreateBranchOperation.java
@@ -44,9 +44,11 @@ import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
import org.eclipse.osee.framework.logging.OseeLog;
/**
+ * {@link CreateBranchOperationTest}
+ *
* @author Roberto E. Escobar
*/
-public class CreateBranchOperation extends AbstractDbTxOperation {
+public final class CreateBranchOperation extends AbstractDbTxOperation {
private static final String INSERT_TX_DETAILS =
"INSERT INTO osee_tx_details (branch_id, transaction_id, osee_comment, time, author, tx_type) VALUES (?,?,?,?,?,?)";
@@ -115,8 +117,8 @@ public class CreateBranchOperation extends AbstractDbTxOperation {
if (associatedArtifactId > -1 && associatedArtifactId != systemUserId) {
int count =
getDatabaseService().runPreparedQueryFetchObject(0,
- "select (1) from osee_branch where associated_art_id=? and branch_state <> ?",
- request.getAssociatedArtifactId(), BranchState.DELETED.getValue());
+ "SELECT (1) FROM osee_branch WHERE associated_art_id = ? AND branch_state NOT IN (?, ?)",
+ request.getAssociatedArtifactId(), BranchState.DELETED.getValue(), BranchState.REBASELINED.getValue());
if (count > 0) {
throw new OseeStateException("Existing branch creation detected for [%s]", request.getBranchName());
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java
index 7201000b2af..0467a4a5833 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/FrameworkCore_Demo_Suite.java
@@ -31,6 +31,7 @@ import org.eclipse.osee.framework.skynet.core.artifact.RelationOrderingTest;
import org.eclipse.osee.framework.skynet.core.artifact.ReplaceAttributeWithTest;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactLoaderTest;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQueryTestDemo;
+import org.eclipse.osee.framework.skynet.core.branch.BranchSuite;
import org.eclipse.osee.framework.skynet.core.event.filter.ArtifactEventFiltersTest;
import org.eclipse.osee.framework.skynet.core.event.filter.BranchEventFiltersTest;
import org.eclipse.osee.framework.skynet.core.event.model.ArtifactEventLoopbackTest;
@@ -57,6 +58,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
+ BranchSuite.class,
UserManagerTest.class,
ReplaceAttributeWithTest.class,
AttributePurgeTest.class,
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/BranchSuite.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/BranchSuite.java
new file mode 100644
index 00000000000..f69e19aff8e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/BranchSuite.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.framework.skynet.core.branch;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({CreateBranchOperationTest.class})
+public class BranchSuite {
+ // do nothing
+}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/CreateBranchOperationTest.java b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/CreateBranchOperationTest.java
new file mode 100644
index 00000000000..9420965aa8e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.skynet.core.test/src/org/eclipse/osee/framework/skynet/core/branch/CreateBranchOperationTest.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.framework.skynet.core.branch;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.osee.framework.core.enums.BranchState;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.Branch;
+import org.eclipse.osee.framework.core.operation.Operations;
+import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
+import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
+import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
+import org.eclipse.osee.framework.skynet.core.artifact.DeleteBranchOperation;
+import org.eclipse.osee.support.test.util.DemoSawBuilds;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+/**
+ * {@link CreateBranchOperation}
+ */
+public class CreateBranchOperationTest {
+
+ static final String NAME = CreateBranchOperationTest.class.getSimpleName() + " %s";
+
+ @Rule
+ public TestName testName = new TestName();
+
+ @Test
+ public void test_checkPreconditions_AllowWorkingBranchCreationIfDeleted() throws OseeCoreException {
+ Artifact folder = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1);
+
+ Branch workingBranch =
+ BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_1, String.format(NAME, testName.getMethodName()),
+ folder);
+ workingBranch.setBranchState(BranchState.DELETED);
+ BranchManager.persist(workingBranch);
+
+ BranchManager.createWorkingBranch(workingBranch, workingBranch.getName() + " child", folder);
+
+ Operations.executeWorkAndCheckStatus(new DeleteBranchOperation(workingBranch));
+
+ folder.deleteAndPersist();
+ }
+
+ @Test
+ public void test_checkPreconditions_AllowWorkingBranchCreationIfRebaselined() throws OseeCoreException {
+ Artifact folder = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1);
+
+ Branch workingBranch =
+ BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_1, String.format(NAME, testName.getMethodName()),
+ folder);
+ workingBranch.setBranchState(BranchState.REBASELINED);
+ BranchManager.persist(workingBranch);
+
+ BranchManager.createWorkingBranch(workingBranch, workingBranch.getName() + " child", folder);
+
+ Operations.executeWorkAndCheckStatus(new DeleteBranchOperation(workingBranch));
+
+ folder.deleteAndPersist();
+
+ }
+
+ /**
+ * expecting really an OseeStateException from CreateBranchOperation
+ */
+ @Test
+ public void test_checkPreconditions_DisallowWorkingBranchCreation() throws OseeCoreException {
+ Set<BranchState> subset = new HashSet<BranchState>(Arrays.asList(BranchState.values()));
+
+ Collection<BranchState> allowedStates = Arrays.asList(BranchState.DELETED, BranchState.REBASELINED);
+ subset.removeAll(allowedStates);
+
+ int exceptionsCaught = 0;
+ for (BranchState state : subset) {
+ Artifact folder = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1);
+
+ Branch workingBranch =
+ BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_1, String.format(NAME, testName.getMethodName()),
+ folder);
+
+ workingBranch.setBranchState(state);
+ BranchManager.persist(workingBranch);
+
+ try {
+ BranchManager.createWorkingBranch(workingBranch, workingBranch.getName() + " child", folder);
+ } catch (OseeCoreException ex) {
+ exceptionsCaught++;
+ }
+
+ Operations.executeWorkAndCheckStatus(new DeleteBranchOperation(workingBranch));
+
+ folder.deleteAndPersist();
+ }
+
+ Assert.assertEquals(
+ "CreateBranchOperation.checkPreconditions() should throw " + (subset.size() - allowedStates.size()) + " exceptions",
+ exceptionsCaught, subset.size());
+ }
+}

Back to the top