Skip to main content
summaryrefslogtreecommitdiffstats
blob: f1df9a11ec48567b8321bc98a11314c977ed2a5e (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
102
103
104
105
106
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.artifact;

import static org.junit.Assert.assertFalse;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.httpRequests.PurgeBranchHttpRequestOperation;
import org.eclipse.osee.framework.skynet.core.mocks.DbTestUtil;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.util.FrameworkTestUtil;
import org.eclipse.osee.support.test.util.DemoSawBuilds;
import org.eclipse.osee.support.test.util.TestUtil;
import org.junit.After;
import org.junit.Before;

/**
 * This test is intended to be run against a demo database. It tests the branch purge logic by counting the rows of the
 * version and txs tables, creating a branch, making changes and then purging the branch. If it works properly, all rows
 * should be equal.
 * 
 * @author Donald G. Dunne
 */
public class BranchPurgeTest {

   private final Map<String, Integer> preCreateCount = new HashMap<String, Integer>();
   private final Map<String, Integer> postCreateBranchCount = new HashMap<String, Integer>();
   private final Map<String, Integer> postPurgeCount = new HashMap<String, Integer>();
   List<String> tables = Arrays.asList("osee_attribute", "osee_artifact", "osee_relation_link", "osee_tx_details",
      "osee_txs");

   @Before
   public void setUp() throws Exception {
      // This test should only be run on test db
      assertFalse(TestUtil.isProductionDb());
      cleanup();
   }

   @org.junit.Test
   public void testPurgeBranch() throws Exception {
      // Count rows in tables prior to purge
      DbTestUtil.getTableRowCounts(preCreateCount, tables);

      // create a new working branch
      Branch branch =
         BranchManager.createWorkingBranch(DemoSawBuilds.SAW_Bld_2, getClass().getSimpleName(),
            UserManager.getUser(SystemUser.OseeSystem));

      TestUtil.sleep(4000);

      // create some software artifacts
      SkynetTransaction transaction = new SkynetTransaction(branch, "Test purge branch");
      Collection<Artifact> softArts =
         FrameworkTestUtil.createSimpleArtifacts(CoreArtifactTypes.SoftwareRequirement, 10, getClass().getSimpleName(),
            branch);
      for (Artifact softArt : softArts) {
         softArt.persist(transaction);
      }
      transaction.execute();

      // make more changes to artifacts
      for (Artifact softArt : softArts) {
         softArt.addAttribute(CoreAttributeTypes.StaticId, getClass().getSimpleName());
         softArt.persist();
      }

      // Count rows and check that increased
      DbTestUtil.getTableRowCounts(postCreateBranchCount, tables);
      TestUtil.checkThatIncreased(preCreateCount, postCreateBranchCount);

      Operations.executeWorkAndCheckStatus(new PurgeBranchHttpRequestOperation(branch, false));
      TestUtil.sleep(4000);

      // Count rows and check that same as when began
      DbTestUtil.getTableRowCounts(postPurgeCount, tables);
      // TODO looks like artifacts are not being removed when purge a branch
      TestUtil.checkThatEqual(preCreateCount, postPurgeCount);

   }

   @After
   public void testCleanupPost() throws Exception {
      cleanup();
   }

   private static void cleanup() throws Exception {
      FrameworkTestUtil.purgeWorkingBranches(Arrays.asList(BranchPurgeTest.class.getSimpleName()));
   }
}

Back to the top