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
|
/*******************************************************************************
* 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.client.integration.tests.integration.skynet.core;
import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.eclipse.osee.client.integration.tests.integration.skynet.core.utils.Asserts.assertThatEquals;
import static org.eclipse.osee.client.integration.tests.integration.skynet.core.utils.Asserts.assertThatIncreased;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_2;
import java.util.Collection;
import java.util.Map;
import org.eclipse.osee.client.integration.tests.integration.skynet.core.utils.TestUtil;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.client.test.framework.TestInfo;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.operation.NullOperationLogger;
import org.eclipse.osee.framework.core.operation.OperationBuilder;
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.BranchManager;
import org.eclipse.osee.framework.skynet.core.httpRequests.PurgeBranchHttpRequestOperation;
import org.eclipse.osee.framework.skynet.core.transaction.SkynetTransaction;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
import org.eclipse.osee.framework.skynet.core.utility.Artifacts;
import org.eclipse.osee.framework.skynet.core.utility.PurgeUnusedBackingDataAndTransactions;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
/**
* 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 {
@Rule
public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_CLIENT_DEMO);
@Rule
public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();
@Rule
public TestInfo method = new TestInfo();
private static final String[] TABLES =
new String[] {"osee_attribute", "osee_artifact", "osee_relation_link", "osee_tx_details", "osee_txs"};
private IOseeBranch workingBranch;
@Before
public void setup() {
workingBranch = TokenFactory.createBranch(method.getQualifiedTestName());
}
@After
public void cleanup() throws Exception {
if (BranchManager.branchExists(workingBranch)) {
BranchManager.purgeBranch(workingBranch);
}
Operations.executeWorkAndCheckStatus(
new PurgeUnusedBackingDataAndTransactions(NullOperationLogger.getSingleton()));
}
@Test
public void testPurgeBranch() throws Exception {
Operations.executeWorkAndCheckStatus(
new PurgeUnusedBackingDataAndTransactions(NullOperationLogger.getSingleton()));
Map<String, Integer> initialRowCount = TestUtil.getTableRowCounts(TABLES);
BranchId branch = BranchManager.createWorkingBranch(SAW_Bld_2, workingBranch);
Collection<Artifact> softArts = TestUtil.createSimpleArtifacts(CoreArtifactTypes.SoftwareRequirement, 10,
method.getQualifiedTestName(), branch);
Artifacts.persistInTransaction("Test purge branch", softArts);
SkynetTransaction transaction = TransactionManager.createTransaction(branch, method.getQualifiedTestName());
// make more changes to artifacts
for (Artifact softArt : softArts) {
softArt.addAttribute(CoreAttributeTypes.StaticId, method.getQualifiedTestName());
softArt.persist(transaction);
}
transaction.execute();
// Count rows and check that increased
assertThatIncreased(initialRowCount, TestUtil.getTableRowCounts(TABLES));
OperationBuilder builder =
Operations.createBuilder(method.getQualifiedTestName(), new PurgeBranchHttpRequestOperation(branch, false),
new PurgeUnusedBackingDataAndTransactions(NullOperationLogger.getSingleton()));
Operations.executeWorkAndCheckStatus(builder.build());
// Count rows and check that same as when began
// TODO looks like artifacts are not being removed when purge a branch
assertThatEquals(initialRowCount, TestUtil.getTableRowCounts(TABLES));
}
}
|