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 java
.lang
.reflect
.Field
;
13 import org
.apache
.log4j
.Level
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.junit
.AfterClass
;
16 import org
.junit
.Assert
;
17 import org
.junit
.BeforeClass
;
18 import org
.junit
.Ignore
;
19 import org
.junit
.Test
;
20 import org
.springframework
.core
.io
.ClassPathResource
;
21 import org
.springframework
.core
.io
.Resource
;
22 import org
.unitils
.UnitilsJUnit4
;
23 import org
.unitils
.database
.DatabaseUnitils
;
24 import org
.unitils
.database
.annotations
.Transactional
;
25 import org
.unitils
.database
.util
.TransactionMode
;
26 import org
.unitils
.spring
.annotation
.SpringApplicationContext
;
28 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationRemoteController
;
29 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
30 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
31 import eu
.etaxonomy
.cdm
.remote
.CdmPersistentRemoteSource
;
32 import eu
.etaxonomy
.cdm
.remote
.CdmRemoteSource
;
33 import eu
.etaxonomy
.cdm
.remote
.CdmRemoteSourceException
;
34 import eu
.etaxonomy
.cdm
.remote
.ICdmRemoteSource
;
38 * Base class for remoting tests, responsible for
39 * - starting / stop the cdm server
40 * - running some basic connection tests
41 * - setting up the remote configuration.
44 @Transactional(TransactionMode
.DISABLED
)
45 @SpringApplicationContext("file:./target/test-classes/eu/etaxonomy/cdm/testRemotingApplicationContext.xml")
46 public class BaseRemotingTest
extends UnitilsJUnit4
{
47 //private static final Logger logger = Logger.getLogger(BaseRemotingTest.class);
49 private static final Resource TEST_REMOTE_APPLICATION_CONTEXT_RESOURCE
=
50 new ClassPathResource("/eu/etaxonomy/cdm/testRemotingApplicationContext.xml");
52 private static ICdmApplicationConfiguration remoteApplicationController
;
53 private static ICdmRemoteSource cdmRemoteSource
;
54 private static CdmPersistentRemoteSource remotePersistentSource
;
56 public static boolean useManagedServer
= false;
59 public static void initializeBaseRemotingTest() {
60 //Logger.getRootLogger().setLevel(Level.INFO);
61 useManagedServer
= (System
.getProperty("use.managed.server") == null) ? useManagedServer
: Boolean
.valueOf(System
.getProperty("use.managed.server"));
62 if(useManagedServer
) {
64 CDMServer
.getInstance().start();
65 } catch (Exception e
) {
67 Assert
.fail("Server failed to start. Reason : " + e
.getMessage());
70 initializeController(CDMServer
.getInstance().getName(),
71 CDMServer
.getInstance().getHost(),
72 CDMServer
.getInstance().getPort(),
73 CDMServer
.getInstance().getContextPath(),
74 NomenclaturalCode
.ICNAFP
);
79 public static void initializeController(String sourceName
, String host
, int port
, String contextPath
, NomenclaturalCode ncode
) {
81 cdmRemoteSource
= CdmRemoteSource
.NewInstance(sourceName
, host
, port
, contextPath
, ncode
);
82 remoteApplicationController
=
83 CdmApplicationRemoteController
.NewInstance(cdmRemoteSource
,
89 remotePersistentSource
= CdmPersistentRemoteSource
.NewInstance(sourceName
);
90 } catch (CdmRemoteSourceException e
) {
91 Assert
.fail("Default Remote Persistent Source failed to load. Reason : " + e
.getMessage());
98 protected static ICdmApplicationConfiguration
getRemoteApplicationController() {
99 return remoteApplicationController
;
102 protected static ICdmRemoteSource
getCdmRemoteSource() {
103 return cdmRemoteSource
;
106 protected static CdmPersistentRemoteSource
getCdmPersistentRemoteSource() {
107 return remotePersistentSource
;
111 public static void cleanup() {
113 CDMServer
.getInstance().stop();
114 } catch (Exception e
) {
115 Assert
.fail("Server could not be stopped. Reason : " + e
.getMessage());
120 protected static Object
getFieldValueViaReflection(Object object
, String fieldName
) {
121 Class
<?
> clazz
= object
.getClass();
123 Field field
= clazz
.getDeclaredField(fieldName
);
124 field
.setAccessible(true);
125 return field
.get(object
);
126 } catch (NoSuchFieldException e
) {
128 } catch (SecurityException e
) {
130 } catch (IllegalArgumentException e
) {
132 } catch (IllegalAccessException e
) {