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