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
|
/*******************************************************************************
* 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.eclipse.osee.framework.core.enums.DeletionFlag.EXCLUDE_DELETED;
import java.util.Collection;
import java.util.Date;
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.exception.OseeCoreException;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
/**
* @author Donald G. Dunne
*/
public class Artifact_getLastModified {
@BeforeClass
public static void testCleanupPre() throws Exception {
cleanup();
}
@AfterClass
public static void testCleanupPost() throws Exception {
cleanup();
}
@org.junit.Test
public void testGetLastModified() throws Exception {
Artifact artifact =
ArtifactTypeManager.addArtifact(CoreArtifactTypes.GeneralDocument, BranchManager.getCommonBranch(),
getClass().getSimpleName());
Assert.assertNotNull(artifact.getLastModified());
Assert.assertEquals(UserManager.getUser(SystemUser.OseeSystem), artifact.getLastModifiedBy());
Date previousModifyDate = artifact.getLastModified();
Thread.sleep(1100); // just enough time to guarantee the date will be at least a second later
artifact.persist(getClass().getSimpleName());
assertBefore(previousModifyDate, artifact);
Assert.assertEquals(UserManager.getUser(), artifact.getLastModifiedBy());
previousModifyDate = artifact.getLastModified();
// Test post-modified
artifact.setSingletonAttributeValue(CoreAttributeTypes.StaticId, "this");
Thread.sleep(1100); // just enough time to guarantee the date will be at least a second later
artifact.persist(getClass().getSimpleName());
assertBefore(previousModifyDate, artifact);
Assert.assertEquals(UserManager.getUser(), artifact.getLastModifiedBy());
previousModifyDate = artifact.getLastModified();
// Test post deleted
Thread.sleep(1100); // just enough time to guarantee the date will be at least a second later
artifact.deleteAndPersist();
assertBefore(previousModifyDate, artifact);
Assert.assertEquals(UserManager.getUser(), artifact.getLastModifiedBy());
}
private void assertBefore(Date previousModifyDate, Artifact artifact) throws OseeCoreException {
Assert.assertTrue(String.format("expected %tc to be before %tc", previousModifyDate, artifact.getLastModified()),
previousModifyDate.before(artifact.getLastModified()));
}
private static void cleanup() throws Exception {
Collection<Artifact> arts =
ArtifactQuery.getArtifactListFromName(Artifact_getLastModified.class.getSimpleName(),
BranchManager.getCommonBranch(), EXCLUDE_DELETED);
Operations.executeWorkAndCheckStatus(new PurgeArtifacts(arts));
}
}
|