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
.httpinvoker
;
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
.Test
;
16 import org
.springframework
.remoting
.RemoteAccessException
;
18 import eu
.etaxonomy
.cdm
.config
.CdmSourceException
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
20 import eu
.etaxonomy
.cdm
.remote
.CdmRemoteSource
;
21 import eu
.etaxonomy
.taxeditor
.lazyloading
.RemotePersistentCollectionTest
;
23 public class CdmRemoteSourceTest
extends BaseRemotingTest
{
24 private static final Logger logger
= Logger
.getLogger(RemotePersistentCollectionTest
.class);
28 public static void initialize() {
30 Logger
.getRootLogger().setLevel(Level
.INFO
);
35 public void whenConnectingToInactiveServerThenFailToConnect() {
36 // check if non-active server throws the right exception
37 CdmRemoteSource inactiveCrs
= CdmRemoteSource
.NewInstance(CDMServer
.getInstance().getName(),
38 CDMServer
.getInstance().getHost(),
40 CDMServer
.getInstance().getContextPath(),
41 NomenclaturalCode
.ICNAFP
);
43 inactiveCrs
.getDbSchemaVersion();
44 Assert
.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException");
45 } catch(CdmSourceException cse
) {
46 Assert
.fail("getDbSchemaVersion() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
47 } catch(RemoteAccessException rae
){
52 inactiveCrs
.isDbEmpty();
53 Assert
.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException");
54 } catch(CdmSourceException cse
) {
55 Assert
.fail("isDbEmpty() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
56 } catch(RemoteAccessException rae
){
61 inactiveCrs
.checkConnection();
62 Assert
.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException");
63 } catch(CdmSourceException cse
) {
64 Assert
.fail("checkConnection() on inactive cdm server should have thrown RemoteAccessException and not CdmSourceException");
65 } catch(RemoteAccessException rae
){
72 public void whenConnectingToAnActiveServerWithServicesBlockedThenFailToAccessServices() {
77 public void whenConnectingToAnActiveServerThenConnectSuccessfully() {
78 // check if active server throws the right exception
79 CdmRemoteSource activeCrs
= CdmRemoteSource
.NewInstance(CDMServer
.getInstance().getName(),
80 CDMServer
.getInstance().getHost(),
81 CDMServer
.getInstance().getPort(),
82 CDMServer
.getInstance().getContextPath(),
83 NomenclaturalCode
.ICNAFP
);
84 String dbSchemaVersion
= "";
86 dbSchemaVersion
= activeCrs
.getDbSchemaVersion();
87 } catch (CdmSourceException e
) {
88 Assert
.fail("getDbSchemaVersion() on active cdm server should not have thrown CdmSourceException");
90 logger
.info("dbSchemaVersion is " + dbSchemaVersion
);
93 boolean isDbEmpty
= false;
95 isDbEmpty
= activeCrs
.isDbEmpty();
96 } catch (CdmSourceException e
) {
97 Assert
.fail("isDbEmpty() on active cdm server should not have thrown CdmSourceException");
99 Assert
.assertFalse(isDbEmpty
);
102 boolean check
= true;
104 isDbEmpty
= activeCrs
.checkConnection();
105 } catch (CdmSourceException e
) {
106 Assert
.fail("checkConnection() on active cdm server should not have thrown CdmSourceException");
108 Assert
.assertTrue(check
);