1
|
/**
|
2
|
* Copyright (C) 2014 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.httpinvoker;
|
10
|
|
11
|
import org.apache.log4j.Level;
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.junit.Assert;
|
14
|
import org.junit.BeforeClass;
|
15
|
import org.junit.Test;
|
16
|
import org.springframework.remoting.RemoteAccessException;
|
17
|
|
18
|
import eu.etaxonomy.cdm.config.CdmSourceException;
|
19
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
20
|
import eu.etaxonomy.cdm.remote.CdmRemoteSource;
|
21
|
import eu.etaxonomy.taxeditor.lazyloading.RemotePersistentCollectionTest;
|
22
|
|
23
|
public class CdmRemoteSourceTest extends BaseRemotingTest {
|
24
|
private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
|
25
|
|
26
|
|
27
|
@BeforeClass
|
28
|
public static void initialize() {
|
29
|
|
30
|
Logger.getRootLogger().setLevel(Level.INFO);
|
31
|
|
32
|
}
|
33
|
|
34
|
@Test
|
35
|
public void whenConnectingToInactiveServerThenFailToConnect() {
|
36
|
// check if non-active server throws the right exception
|
37
|
CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
|
38
|
CDMServer.getInstance().getHost(),
|
39
|
808080,
|
40
|
CDMServer.getInstance().getContextPath(),
|
41
|
NomenclaturalCode.ICNAFP);
|
42
|
try {
|
43
|
inactiveCrs.getDbSchemaVersion();
|
44
|
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
|
45
|
} catch(CdmSourceException cse) {
|
46
|
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
47
|
} catch(RemoteAccessException rae){
|
48
|
|
49
|
}
|
50
|
|
51
|
try {
|
52
|
inactiveCrs.isDbEmpty();
|
53
|
Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
|
54
|
} catch(CdmSourceException cse) {
|
55
|
Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
56
|
} catch(RemoteAccessException rae){
|
57
|
|
58
|
}
|
59
|
|
60
|
try {
|
61
|
inactiveCrs.checkConnection();
|
62
|
Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
|
63
|
} catch(CdmSourceException cse) {
|
64
|
Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
65
|
} catch(RemoteAccessException rae){
|
66
|
|
67
|
}
|
68
|
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
|
73
|
|
74
|
}
|
75
|
|
76
|
@Test
|
77
|
public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
|
78
|
// check if active server throws the right exception
|
79
|
CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
|
80
|
CDMServer.getInstance().getHost(),
|
81
|
CDMServer.getInstance().getPort(),
|
82
|
CDMServer.getInstance().getContextPath(),
|
83
|
NomenclaturalCode.ICNAFP);
|
84
|
String dbSchemaVersion = "";
|
85
|
try {
|
86
|
dbSchemaVersion = activeCrs.getDbSchemaVersion();
|
87
|
} catch (CdmSourceException e) {
|
88
|
Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
|
89
|
}
|
90
|
logger.info("dbSchemaVersion is " + dbSchemaVersion);
|
91
|
|
92
|
|
93
|
boolean isDbEmpty = false;
|
94
|
try {
|
95
|
isDbEmpty = activeCrs.isDbEmpty();
|
96
|
} catch (CdmSourceException e) {
|
97
|
Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
|
98
|
}
|
99
|
Assert.assertFalse(isDbEmpty);
|
100
|
|
101
|
|
102
|
boolean check = true;
|
103
|
try {
|
104
|
isDbEmpty = activeCrs.checkConnection();
|
105
|
} catch (CdmSourceException e) {
|
106
|
Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
|
107
|
}
|
108
|
Assert.assertTrue(check);
|
109
|
|
110
|
}
|
111
|
|
112
|
}
|