Skip to main content
summaryrefslogtreecommitdiffstats
blob: 04620590dbb3f4adc4f7c0a92e6b5988e8513eee (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
/*******************************************************************************
 * 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.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
import org.eclipse.osee.framework.skynet.core.mocks.DbTestUtil;
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 Jeff C. Phillips
 * @author Donald G. Dunne
 */
public abstract class AbstractPurgeTest {

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

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

   @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>();
   }

   @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 testPurge() throws Exception {
      runPurgeOperation();

      // TODO Looks like attributes created after initial artifact creation are not getting purged.  Needs Fix.
      TestUtil.checkThatEqual(preCreateArtifactsCount, postPurgeCount);
   }

   protected void getPreTableCount() throws OseeCoreException {
      // Count rows in tables prior to purge
      DbTestUtil.getTableRowCounts(preCreateArtifactsCount, getTables());
   }

   protected void getPostTableCount() throws OseeCoreException {
      // Count rows and check that same as when began
      DbTestUtil.getTableRowCounts(postPurgeCount, getTables());
   }

   public abstract void runPurgeOperation() throws OseeCoreException;

   public abstract List<String> getTables();

}

Back to the top