7656a9c0cd84d7bc24c8496d6824e454913ea416
[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 // check if non-active server throws the right exception
28 CdmRemoteSource inactiveCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
29 CDMServer.getInstance().getHost(),
30 808080,
31 CDMServer.getInstance().getContextPath(),
32 NomenclaturalCode.ICNAFP);
33 try {
34 inactiveCrs.getDbSchemaVersion();
35 Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
36 } catch(CdmSourceException cse) {
37 Assert.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
38 } catch(RemoteAccessException rae){
39
40 }
41
42 try {
43 inactiveCrs.isDbEmpty();
44 Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
45 } catch(CdmSourceException cse) {
46 Assert.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
47 } catch(RemoteAccessException rae){
48
49 }
50
51 try {
52 inactiveCrs.checkConnection();
53 Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
54 } catch(CdmSourceException cse) {
55 Assert.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
56 } catch(RemoteAccessException rae){
57
58 }
59
60 }
61
62 @Test
63 public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
64
65 }
66
67 @Test
68 public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
69 // check if active server throws the right exception
70 CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(CDMServer.getInstance().getName(),
71 CDMServer.getInstance().getHost(),
72 CDMServer.getInstance().getPort(),
73 CDMServer.getInstance().getContextPath(),
74 NomenclaturalCode.ICNAFP);
75 String dbSchemaVersion = "";
76 try {
77 dbSchemaVersion = activeCrs.getDbSchemaVersion();
78 } catch (CdmSourceException e) {
79 Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
80 }
81 logger.info("dbSchemaVersion is " + dbSchemaVersion);
82
83
84 boolean isDbEmpty = false;
85 try {
86 isDbEmpty = activeCrs.isDbEmpty();
87 } catch (CdmSourceException e) {
88 Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
89 }
90 Assert.assertFalse(isDbEmpty);
91
92
93 boolean check = true;
94 try {
95 isDbEmpty = activeCrs.checkConnection();
96 } catch (CdmSourceException e) {
97 Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
98 }
99 Assert.assertTrue(check);
100
101 }
102
103 }