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
|
/*******************************************************************************
* 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 static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.data.SystemUser;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.logging.SevereLoggingMonitor;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.change.Change;
import org.eclipse.osee.framework.skynet.core.revision.ChangeManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
/**
* Tests the Change Manager.
*
* @author Jeff C. Phillips
*/
public class ChangeManagerTest {
private static Artifact newArtifact;
private static Artifact modArtifact;
private Branch branch;
@Before
public void setUp() throws Exception {
assertFalse("This test can not be run on Production", ClientSessionManager.isProductionDataStore());
modArtifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, CoreBranches.SYSTEM_ROOT);
modArtifact.persist();
sleep(5000);
String branchName = "Change Manager Test Branch" + GUID.create();
branch =
BranchManager.createWorkingBranch(CoreBranches.SYSTEM_ROOT, branchName,
UserManager.getUser(SystemUser.OseeSystem));
sleep(5000);
newArtifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.SoftwareRequirement, branch);
newArtifact.persist();
sleep(5000);
BranchManager.refreshBranches();
}
@org.junit.Test
public void testChangeManager() throws Exception {
SevereLoggingMonitor monitorLog = new SevereLoggingMonitor();
OseeLog.registerLoggerListener(monitorLog);
sleep(5000);
modArtifact = ArtifactQuery.getArtifactFromId(modArtifact.getArtId(), branch);
assertTrue("Check artifact new", checkArtifactModType(newArtifact, ModificationType.NEW));
newArtifact.setSoleAttributeFromString(CoreAttributeTypes.WordTemplateContent, "new content");
assertTrue("Check artifact is still new", checkArtifactModType(newArtifact, ModificationType.NEW));
modArtifact.setSoleAttributeFromString(CoreAttributeTypes.WordTemplateContent, "changed content");
modArtifact.persist();
assertTrue("Check artifact has changed", checkArtifactModType(modArtifact, ModificationType.NEW));
}
@Ignore
@Test
public void testArtifactTypeChange() {
// TODO Add artifact type change
}
@After
public void tearDown() throws Exception {
modArtifact.persist();
BranchManager.purgeBranch(branch);
sleep(5000);
}
public static boolean checkArtifactModType(Artifact artifact, ModificationType modificationType) throws OseeCoreException {
boolean pass = false;
Collection<Change> changes = new ArrayList<Change>();
IOperation operation = ChangeManager.comparedToParent(artifact.getBranch(), changes);
Operations.executeWorkAndCheckStatus(operation);
for (Change change : changes) {
if (change.getArtId() == artifact.getArtId()) {
pass = change.getModificationType() == modificationType;
break;
}
}
return pass;
}
public static void sleep(long milliseconds) throws Exception {
OseeLog.log(ChangeManagerTest.class, Level.INFO, "Sleeping " + milliseconds);
Thread.sleep(milliseconds);
OseeLog.log(ChangeManagerTest.class, Level.INFO, "Awake");
}
}
|