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.Logger;
|
12
|
import org.junit.Assert;
|
13
|
import org.junit.Test;
|
14
|
import org.springframework.remoting.RemoteAccessException;
|
15
|
|
16
|
import eu.etaxonomy.cdm.config.CdmSourceException;
|
17
|
import eu.etaxonomy.taxeditor.lazyloading.RemotePersistentCollectionTest;
|
18
|
import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
|
19
|
|
20
|
public class CdmRemoteSourceTest extends BaseRemotingTest {
|
21
|
private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
|
22
|
|
23
|
|
24
|
@Test
|
25
|
public void whenConnectingToInactiveServerThenFailToConnect() {
|
26
|
|
27
|
// check if non-active server throws the right exception
|
28
|
CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(sourceName,
|
29
|
host,
|
30
|
808080,
|
31
|
contextPath);
|
32
|
try {
|
33
|
String dbSchemaVersion = inactiveCrs.getDbSchemaVersion();
|
34
|
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
|
35
|
} catch(CdmSourceException cse) {
|
36
|
Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
37
|
} catch(RemoteAccessException rae){
|
38
|
|
39
|
}
|
40
|
|
41
|
try {
|
42
|
inactiveCrs.isDbEmpty();
|
43
|
Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
|
44
|
} catch(CdmSourceException cse) {
|
45
|
Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
46
|
} catch(RemoteAccessException rae){
|
47
|
|
48
|
}
|
49
|
|
50
|
try {
|
51
|
inactiveCrs.checkConnection();
|
52
|
Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
|
53
|
} catch(CdmSourceException cse) {
|
54
|
Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
|
55
|
} catch(RemoteAccessException rae){
|
56
|
|
57
|
}
|
58
|
|
59
|
}
|
60
|
|
61
|
@Test
|
62
|
public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
|
63
|
// check if active server throws the right exception
|
64
|
CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(sourceName,
|
65
|
host,
|
66
|
httpPort,
|
67
|
contextPath);
|
68
|
String dbSchemaVersion = "";
|
69
|
try {
|
70
|
dbSchemaVersion = activeCrs.getDbSchemaVersion();
|
71
|
} catch (CdmSourceException e) {
|
72
|
Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
|
73
|
}
|
74
|
logger.info("dbSchemaVersion is " + dbSchemaVersion);
|
75
|
|
76
|
|
77
|
boolean isDbEmpty = false;
|
78
|
try {
|
79
|
isDbEmpty = activeCrs.isDbEmpty();
|
80
|
} catch (CdmSourceException e) {
|
81
|
Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
|
82
|
}
|
83
|
Assert.assertFalse(isDbEmpty);
|
84
|
|
85
|
|
86
|
boolean check = true;
|
87
|
try {
|
88
|
isDbEmpty = activeCrs.checkConnection();
|
89
|
} catch (CdmSourceException e) {
|
90
|
Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
|
91
|
}
|
92
|
Assert.assertTrue(check);
|
93
|
|
94
|
}
|
95
|
|
96
|
}
|