2 * Copyright (C) 2014 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.remoting
;
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
;
21 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 import eu
.etaxonomy
.cdm
.remote
.CdmRemoteSource
;
25 public class CdmRemoteSourceTest
extends UnitilsJUnit4
{
26 private static final Logger logger
= Logger
.getLogger(RemotePersistentCollectionTest
.class);
30 public static void initialize() {
31 Logger
.getRootLogger().setLevel(Level
.INFO
);
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
);
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
){
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
){
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
){
69 public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
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
= "";
79 dbSchemaVersion
= activeCrs
.getDbSchemaVersion();
80 } catch (CdmSourceException e
) {
81 Assert
.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
83 logger
.info("dbSchemaVersion is " + dbSchemaVersion
);
86 boolean isDbEmpty
= false;
88 isDbEmpty
= activeCrs
.isDbEmpty();
89 } catch (CdmSourceException e
) {
90 Assert
.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
92 Assert
.assertFalse(isDbEmpty
);
97 isDbEmpty
= activeCrs
.checkConnection();
98 } catch (CdmSourceException e
) {
99 Assert
.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
101 Assert
.assertTrue(check
);