Merge branch 'release/3.12.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(sourceName,
30 host,
31 808080,
32 contextPath,
33 NomenclaturalCode.ICNAFP);
34 try {
35 String dbSchemaVersion = 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 whenConnectingToAnActiveServerThenConnectSuccessfully() {
65 // check if active server throws the right exception
66 CdmRemoteSource activeCrs = CdmRemoteSource.NewInstance(sourceName,
67 host,
68 httpPort,
69 contextPath,
70 NomenclaturalCode.ICNAFP);
71 String dbSchemaVersion = "";
72 try {
73 dbSchemaVersion = activeCrs.getDbSchemaVersion();
74 } catch (CdmSourceException e) {
75 Assert.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
76 }
77 logger.info("dbSchemaVersion is " + dbSchemaVersion);
78
79
80 boolean isDbEmpty = false;
81 try {
82 isDbEmpty = activeCrs.isDbEmpty();
83 } catch (CdmSourceException e) {
84 Assert.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
85 }
86 Assert.assertFalse(isDbEmpty);
87
88
89 boolean check = true;
90 try {
91 isDbEmpty = activeCrs.checkConnection();
92 } catch (CdmSourceException e) {
93 Assert.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
94 }
95 Assert.assertTrue(check);
96
97 }
98
99 }