Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4415b631d8925220a65b6e1297511f379a6f9c47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (c) 2011 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.branch.management.test.purge;

import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osee.framework.branch.management.purge.BranchOperation;
import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchOperationFactory;
import org.eclipse.osee.framework.branch.management.test.mocks.MockBranchProvider;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.operation.NullOperationLogger;
import org.eclipse.osee.framework.core.operation.OperationLogger;
import org.eclipse.osee.framework.core.operation.Operations;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author John Misinco
 */
public final class BranchOperationTest {

   private void runTest(boolean nullFactory, boolean nullProvider, boolean nullLogger, boolean expectedResult) throws OseeCoreException {
      OperationLogger logger = NullOperationLogger.getSingleton();

      MockBranchOperationFactory mbo = new MockBranchOperationFactory();
      MockBranchProvider mbp = new MockBranchProvider();

      if (nullFactory) {
         mbo = null;
      }
      if (nullProvider) {
         mbp = null;
      }
      if (nullLogger) {
         logger = null;
      }

      BranchOperation bo = new BranchOperation(logger, mbo, mbp);
      IStatus status = Operations.executeWork(bo);

      if (expectedResult) {
         Assert.assertEquals(Status.OK_STATUS, status);
         Assert.assertTrue(mbo.getCalled() == expectedResult);
         Assert.assertTrue(verifyCallOrder(mbo.getCallOrder()));
      } else {
         Assert.assertFalse(Status.OK_STATUS == status);
      }

   }

   private boolean verifyCallOrder(List<Branch> callOrder) throws OseeCoreException {
      boolean result = true;
      for (Branch cur : callOrder) {
         int idxCur = callOrder.indexOf(cur);
         Branch parent = cur.getParentBranch();
         if (parent != null) {
            int idxParent = callOrder.indexOf(parent);
            if (idxCur > idxParent) {
               result = false;
               break;
            }
         }
      }
      return result;
   }

   @Test
   public void testBranchOperation() throws OseeCoreException {
      runTest(false, false, false, true);
   }

   @Test
   public void testBranchOperationException__nullFactory() throws OseeCoreException {
      runTest(true, false, false, false);
   }

   @Test
   public void testBranchOperationException__nullProvider() throws OseeCoreException {
      runTest(false, true, false, false);
   }

   @Test
   public void testBranchOperationException__nullLogger() throws OseeCoreException {
      runTest(false, false, true, false);
   }

   @Test
   public void testBranchOperationException__allNull() throws OseeCoreException {
      runTest(true, true, true, false);
   }
}

Back to the top