/
ConfigTest.java
131 lines (109 loc) · 4.26 KB
/
ConfigTest.java
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
125
126
127
128
129
130
131
/*
* $Id$
*
* Copyright 2006-2014 University of Dundee. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package ome.server.itests;
import java.util.UUID;
import ome.api.IConfig;
import ome.conditions.SecurityViolation;
import org.testng.annotations.*;
/**
* simple server-side test of the ome.api.IConfig service.
*
* Also used as the main developer example for developing
* (stateless/client-side) tests. See source code documentation for more.
*
* @author Josh Moore, josh.moore at gmx.de
* @version $Revision$, $Date$
* @since 3.0-M3
*/
/*
* Developer notes: --------------- The "integration" group is important for
* having tests run properly. It's not actually needed here because it's also
* defined on the super class. The "ticket:306" group works as a pointer to why
* certain tests were created, allowing for acceptance test-like functionality
* (TBD).
*
* It should be noted that server side integration tests DO NOT test the
* application server in any way. You are using the server-side code as a
* library at that point and no deployment has been made. (This may change if we
* start to use an embedded container like the one available from JBoss for
* testing, in which case there should be an AbstractEmbeddedContextTest)
*
* Also to explain, the AbstractInternalContextTest which is a close parallel to
* AbstractManagedContextTest is partially deprecated and should only really be
* used when testing specific parts of the internal plumbing of Omero, Spring,
* or Hibernate, such as flushing or transactions.
*/
@Test(groups = { "ticket:306", "config", "integration" })
public class ConfigTest extends AbstractManagedContextTest {
/*
* Developer notes: --------------- The name of the method is unimportant
* for testng. We continue to use test<name> for the possibility of having
* the tests also run onJunit 3.8.
*/
@Test
public void testConfigGetServerTime() throws Exception {
/*
* Developer notes: --------------- An iConfig instance has also be set
* on the super class as has been done with almost all our interfaces.
* It is reset before each method call
*/
IConfig test = factory.getConfigService();
assertNotNull(test.getServerTime());
}
@Test
public void testConfigGetDBTime() throws Exception {
/*
* Developer notes: --------------- Using the instance variable
*/
assertNotNull(iConfig.getDatabaseTime());
}
@Test
public void testGetMissingConfigValue() throws Exception {
/*
* Developer notes: --------------- HIGHLY unlikely that the UUID string
* will be available
*/
String value = iConfig.getConfigValue(UUID.randomUUID().toString());
assertNull(value);
}
@Test
public void testDefaultPreferencesConfiguration() throws Exception {
loginNewUser();
assertEquals("false", iConfig
.getConfigValue("omero.mail.config"));
try {
iConfig.getConfigValue("omero.mail.password");
fail("secvio!");
} catch (SecurityViolation sv) {
// regular user should not be able to acquire sensitive info
}
// But this should be ok
loginRoot();
iConfig.getConfigValue("omero.mail.password");
}
@Test
public void testSettingClusterProperties() throws Exception {
loginRoot();
iConfig.setConfigValue("omero.cluster.redirect", "foo");
assertEquals("foo", iConfig.getConfigValue("omero.cluster.redirect"));
}
/*
* Developer notes: --------------- Tests that should not be run, either
* because they're not yet finished, or because they're waiting on a known
* issue, can be added to the "ignore" or "broken" group or marked "enabled =
* false"
*/
@Test(groups = "ignore")
public void testThisTestUsuallyWontBeCalled() throws Exception {
fail("This usually won't be called. You're probably using "
+ "the developer test suite; don't worry about this.");
}
@Test(enabled = false)
public void testThisTestWontBeCalled() throws Exception {
fail("Error in TestNG!");
}
}