Skip to main content
summaryrefslogtreecommitdiffstats
blob: a843ff135b8d633c2c78a8c69c3fd2230815d41e (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * 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.test.cases;

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.model.Branch;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
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.PurgeArtifacts;
import org.eclipse.osee.framework.skynet.core.test.util.FrameworkTestUtil;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
import org.eclipse.osee.support.test.util.DemoSawBuilds;
import org.eclipse.osee.support.test.util.TestUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

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

   private static SevereLoggingMonitor monitorLog;
   private Map<String, Integer> preCreateArtifactsCount;
   private Map<String, Integer> postCreateArtifactsCount;
   private Map<String, Integer> postPurgeCount;

   private static final List<String> tables = Arrays.asList("osee_attribute", "osee_artifact", "osee_relation_link",
      "osee_tx_details", "osee_txs");

   @BeforeClass
   public static void testInitialize() throws Exception {
      monitorLog = TestUtil.severeLoggingStart();
   }

   /**
    * @throws java.lang.Exception
    */
   @Before
   public void setUp() throws Exception {
      // This test should only be run on test db
      assertFalse(TestUtil.isProductionDb());
      preCreateArtifactsCount = new HashMap<String, Integer>();
      postCreateArtifactsCount = new HashMap<String, Integer>();
      postPurgeCount = new HashMap<String, Integer>();
   }

   /**
    * @throws java.lang.Exception
    */
   @After
   public void tearDown() throws Exception {
      if (preCreateArtifactsCount != null) {
         preCreateArtifactsCount.clear();
         preCreateArtifactsCount = null;
      }
      if (postCreateArtifactsCount != null) {
         postCreateArtifactsCount.clear();
         postCreateArtifactsCount = null;
      }
      if (postPurgeCount != null) {
         postPurgeCount.clear();
         postPurgeCount = null;
      }
   }

   @AfterClass
   public static void testCleanup() throws Exception {
      TestUtil.severeLoggingEnd(monitorLog);
   }

   @org.junit.Test
   public void testPurgeArtifacts() throws Exception {
      // Count rows in tables prior to purge
      DbUtil.getTableRowCounts(preCreateArtifactsCount, tables);

      // Create some software artifacts
      Branch branch = BranchManager.getBranch(DemoSawBuilds.SAW_Bld_2.getName());
      SkynetTransaction transaction = new SkynetTransaction(branch, "Test purge artifacts");
      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.STATIC_ID, getClass().getSimpleName());
         softArt.persist();
      }

      // Count rows and check that increased
      DbUtil.getTableRowCounts(postCreateArtifactsCount, tables);
      TestUtil.checkThatIncreased(preCreateArtifactsCount, postCreateArtifactsCount);

      new PurgeArtifacts(softArts).execute();

      // Count rows and check that same as when began
      DbUtil.getTableRowCounts(postPurgeCount, tables);
      // TODO Looks like attributes created after initial artifact creation are not getting purged.  Needs Fix.
      TestUtil.checkThatEqual(preCreateArtifactsCount, postPurgeCount);

   }

}

Back to the top