blob: b43b5f24c11672df3c719f6b59773dfc60cb3607 (
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
|
/*******************************************************************************
* Copyright (c) 2012 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.test.framework;
import static org.junit.Assert.*;
import org.eclipse.osee.client.test.framework.internal.AbstractTestRule;
import org.eclipse.osee.client.test.framework.internal.DatabaseInitializer;
import org.eclipse.osee.framework.core.client.ClientSessionManager;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.database.init.IDbInitChoiceEnum;
import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
import org.eclipse.osee.framework.ui.skynet.render.RenderingUtil;
import org.junit.Assert;
import org.junit.runners.model.FrameworkMethod;
/**
* The OseeClientIntegration Rule initializes an OSEE database instance using the configuration specified. This rule
* should be added to all OSEE integration tests. The database will only be initialized for the first test in the test
* suite. Finally, the rule also guards against writing to production databases.
*
* <pre>
* public class TestA {
*
* @Rule
* public OseeClientIntegrationRule rule = new OseeClientIntegrationRule(DemoChoice.OSEE_CLIENT_DEMO);
*
* @Test
* public void testA() {
* Artifact artifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.Folder, DemoSawBuilds.SAW_Bld_1, "Folder");
* artifact.persist("write to db");
* }
* }
* </pre>
*
* @author Roberto E. Escobar
*/
public final class OseeClientIntegrationRule extends AbstractTestRule {
private static boolean onFirstSuccess = false;
// private boolean originalIsInTest;
// private boolean popUps;
private final IDbInitChoiceEnum choice;
private final String authenticationType = "demo";
public OseeClientIntegrationRule(IDbInitChoiceEnum choice) {
this.choice = choice;
}
@Override
public void onFirstTest(FrameworkMethod method) throws Throwable {
String message = String.format("[%s] Application Server must be running", authenticationType.toUpperCase());
assertTrue(message, ClientSessionManager.getAuthenticationProtocols().contains(authenticationType));
checkNotProductionDataStore();
DatabaseInitializer initializer = new DatabaseInitializer(choice);
initializer.execute();
onFirstSuccess = true;
}
/**
* Invoked when a test method is about to start
*
* @param method
*/
@Override
public void onTestStarting(FrameworkMethod method) throws Throwable {
if (onFirstSuccess) {
checkNotProductionDataStore();
// originalIsInTest = OseeProperties.isInTest();
OseeProperties.setIsInTest(true);
// popUps = RenderingUtil.arePopupsAllowed();
RenderingUtil.setPopupsAllowed(false);
checkAuthenticatedSession(authenticationType);
} else {
Assert.fail("Error during database initialization");
}
}
/**
* Invoked when a test method finishes (whether passing or failing)
*
* @param method
*/
@Override
public void onTestFinished(FrameworkMethod method) {
// OseeProperties.setIsInTest(originalIsInTest);
// RenderingUtil.setPopupsAllowed(popUps);
}
private static void checkAuthenticatedSession(String authenticationType) throws OseeCoreException {
String message = String.format("Client must authenticate using [%s] protocol", authenticationType);
assertTrue(message, ClientSessionManager.getSession().getAuthenticationProtocol().equals(authenticationType));
}
private static void checkNotProductionDataStore() throws OseeCoreException {
// assertTrue("Should be run on demo database.", TestUtil.isDemoDb());
assertFalse("Not to be run on a production database.", isProductionDataStore());
}
private static boolean isProductionDataStore() throws OseeCoreException {
return ClientSessionManager.isProductionDataStore();
}
}
|