Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / httpinvoker / CdmRemoteSourceTest.java
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.cdm.model.name.NomenclaturalCode;
18 import eu.etaxonomy.taxeditor.lazyloading.RemotePersistentCollectionTest;
19 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSource;
20
21 public class CdmRemoteSourceTest extends BaseRemotingTest {
22 private static final Logger logger = Logger.getLogger(RemotePersistentCollectionTest.class);
23
24
25 @Test
26 public void whenConnectingToInactiveServerThenFailToConnect() {
27
28 // check if non-active server throws the right exception
29 CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
30 cdmServer.getHost(),
31 808080,
32 cdmServer.getContextPath(),
33 NomenclaturalCode.ICNAFP);
34 try {
35 inactiveCrs.getDbSchemaVersion();
36 Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
37 } catch(CdmSourceException cse) {
38 Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
39 } catch(RemoteAccessException rae){
40
41 }
42
43 try {
44 inactiveCrs.isDbEmpty();
45 Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
46 } catch(CdmSourceException cse) {
47 Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
48 } catch(RemoteAccessException rae){
49
50 }
51
52 try {
53 inactiveCrs.checkConnection();
54 Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
55 } catch(CdmSourceException cse) {
56 Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
57 } catch(RemoteAccessException rae){
58
59 }
60
61 }
62
63 @Test
64 public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
65
66 }
67
68 @Test
69 public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
70 // check if active server throws the right exception
71 CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(cdmServer.getName(),
72 cdmServer.getHost(),
73 cdmServer.getPort(),
74 cdmServer.getContextPath(),
75 NomenclaturalCode.ICNAFP);
76 String dbSchemaVersion = "";
77 try {
78 dbSchemaVersion = activeCrs.getDbSchemaVersion();
79 } catch (CdmSourceException e) {
80 Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
81 }
82 logger.info("dbSchemaVersion is " + dbSchemaVersion);
83
84
85 boolean isDbEmpty = false;
86 try {
87 isDbEmpty = activeCrs.isDbEmpty();
88 } catch (CdmSourceException e) {
89 Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
90 }
91 Assert.assertFalse(isDbEmpty);
92
93
94 boolean check = true;
95 try {
96 isDbEmpty = activeCrs.checkConnection();
97 } catch (CdmSourceException e) {
98 Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
99 }
100 Assert.assertTrue(check);
101
102 }
103
104 }