Project

General

Profile

« Previous | Next » 

Revision 608f7100

Added by Cherian Mathew almost 9 years ago

corrected merge to latest snapshot version
updated hibernate config file and test db
setup testing framework with jetty and maven

View differences:

eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
205 205
 net.sf.json;uses:="net.sf.json.processors,net.sf.json.util,org.apache.commons.lang.exception",
206 206
 org.aopalliance.aop,
207 207
 org.apache.commons.collections;uses:="org.apache.commons.collections.keyvalue,new org.apache.commons.collections",
208
 org.apache.commons.collections.buffer,
208 209
 org.apache.commons.dbcp,
209 210
 org.apache.commons.io;uses:="org.apache.commons.io.filefilter",
210 211
 org.apache.commons.lang;uses:="org.apache.commons.lang.exception",
eu.etaxonomy.taxeditor.cdmlib/build.properties
184 184
               lib/poi-ooxml-3.10-FINAL.jar,\
185 185
               lib/poi-ooxml-schemas-3.10-FINAL.jar,\
186 186
               lib/xmlbeans-2.3.0.jar,\
187
               lib/cdmlib-commons-3.6.1-SNAPSHOT-sources.jar,\
188 187
               lib/cdmlib-commons-3.6.1-SNAPSHOT.jar,\
189
               lib/cdmlib-ext-3.6.1-SNAPSHOT-sources.jar,\
190 188
               lib/cdmlib-ext-3.6.1-SNAPSHOT.jar,\
191
               lib/cdmlib-io-3.6.1-SNAPSHOT-sources.jar,\
192 189
               lib/cdmlib-io-3.6.1-SNAPSHOT.jar,\
193
               lib/cdmlib-model-3.6.1-SNAPSHOT-sources.jar,\
194 190
               lib/cdmlib-model-3.6.1-SNAPSHOT.jar,\
195
               lib/cdmlib-persistence-3.6.1-SNAPSHOT-sources.jar,\
196 191
               lib/cdmlib-persistence-3.6.1-SNAPSHOT.jar,\
197
               lib/cdmlib-print-3.6.1-SNAPSHOT-sources.jar,\
198 192
               lib/cdmlib-print-3.6.1-SNAPSHOT.jar,\
199
               lib/cdmlib-remote-3.6.1-SNAPSHOT-sources.jar,\
200 193
               lib/cdmlib-remote-3.6.1-SNAPSHOT.jar,\
201
               lib/cdmlib-services-3.6.1-SNAPSHOT-sources.jar,\
202 194
               lib/cdmlib-services-3.6.1-SNAPSHOT.jar,\
203 195
               lib/swagger-annotations-1.3.5.jar
204 196

  
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml
35 35
          in your hibernate configuration, using hibernate-specific configuration keys.
36 36
          All other properties must be defined as usual in a c3p0.properties file.
37 37
          This is confusing, and will hopefully be simplified some time in the future, but for now...
38
          
39
          DOCUMENTATION UPDATE (2015-05-22):
40
          Hibernate's C3P0ConnectionProvider renames 7 c3p0 configuration properties, which, 
41
          if set in your hibernate configuration, will override any configuration you may have set 
42
          in a c3p0.properties file.
43
          TODO: are points (2) and (3) still valid? I don't think so! (AK)
38 44

  
39 45
            hibernate.c3p0.acquire_increment
40 46
			hibernate.c3p0.idle_test_period
......
186 192
      <mapping class="eu.etaxonomy.cdm.model.taxon.Taxon"/>
187 193
      <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonBase"/>
188 194
      <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonNode"/>
195
      <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation"/>
189 196
      <mapping class="eu.etaxonomy.cdm.model.taxon.Classification"/>
190 197
      <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonRelationship"/>
191 198
      <mapping class="eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType"/>
eu.etaxonomy.taxeditor.test/META-INF/MANIFEST.MF
2 2
Bundle-ManifestVersion: 2
3 3
Bundle-Name: eu.etaxonomy.taxeditor.test
4 4
Bundle-SymbolicName: eu.etaxonomy.taxeditor.test;singleton:=true
5
Bundle-Version: 3.5.2.qualifier
5
Bundle-Version: 3.6.1.qualifier
6 6
Bundle-ActivationPolicy: lazy
7 7
Bundle-Vendor: EDIT
8 8
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
eu.etaxonomy.taxeditor.test/pom.xml
4 4
  <parent>
5 5
    <groupId>eu.etaxonomy</groupId>
6 6
    <artifactId>taxeditor-parent</artifactId>
7
    <version>3.5.2-SNAPSHOT</version>
7
    <version>3.6.1-SNAPSHOT</version>
8 8
  </parent>
9 9
  <modelVersion>4.0.0</modelVersion>
10 10
  <artifactId>eu.etaxonomy.taxeditor.test</artifactId>
......
34 34
        <artifactId>tycho-surefire-plugin</artifactId>
35 35
        <version>${tycho.version}</version>
36 36
        <configuration>
37
          <!-- currently we run only the non-ui unit tests so we don't  the harness-->
37
          <!-- currently we run only the non-ui unit tests so we don't the 
38
            harness -->
38 39
          <!-- <useUIHarness>true</useUIHarness> -->
39 40
          <dependencies>
40
          <!-- This will pull the feature and its dependent plugins into the classpath
41
               for the tests. Note that this requires ALL taxeditor projects to be
42
               installed. -->
41
            <!-- This will pull the feature and its dependent plugins into 
42
              the classpath for the tests. Note that this requires ALL taxeditor projects 
43
              to be installed. -->
43 44
            <dependency>
44 45
              <type>eclipse-feature</type>
45 46
              <artifactId>eu.etaxonomy.taxeditor.feature</artifactId>
......
49 50
          </dependencies>
50 51
        </configuration>
51 52
      </plugin>
53
      <plugin>
54
        <groupId>org.eclipse.jetty</groupId>
55
        <artifactId>jetty-maven-plugin</artifactId>
56
        <version>9.2.9.v20150224</version>
57
        <configuration>
58
          <systemProperties>
59
            <systemProperty>
60
              <name>spring.profiles.active</name>
61
              <value>remoting</value>
62
            </systemProperty>
63
            <systemProperty>
64
              <name>cdm.beanDefinitionFile</name>
65
              <value>${basedir}/src/test/resources/datasources.xml</value>
66
            </systemProperty>
67
            <systemProperty>
68
              <name>cdm.datasource</name>
69
              <value>cdmTest</value>
70
            </systemProperty>
71
          </systemProperties>
72
          <stopPort>9191</stopPort>
73
          <stopKey>jetty-cdm-server</stopKey>
74
          <stopWait>10</stopWait>
75
          <httpConnector>
76
            <port>9090</port>
77
          </httpConnector>
78
          <war>${project.parent.basedir}/eu.etaxonomy.taxeditor.cdmlib/src/main/resources/etc/jetty/cdmlib-remote-webapp.war</war>
79
          <daemon>true</daemon>
80
        </configuration>
81
        <executions>
82
          <execution>
83
            <id>start-jetty</id>
84
            <phase>pre-integration-test</phase>
85
            <goals>
86
              <goal>deploy-war</goal>
87
            </goals>
88
            <configuration>
89
              <scanIntervalSeconds>0</scanIntervalSeconds>              
90
            </configuration>
91
          </execution>
92
          <execution>
93
            <id>stop-jetty</id>
94
            <phase>post-integration-test</phase>
95
            <goals>
96
              <goal>stop</goal>
97
            </goals>
98
          </execution>
99
        </executions>
100
      </plugin>
52 101
    </plugins>
53 102
  </build>
54 103
</project>
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmClientCachingTest.java
16 16
import java.util.Set;
17 17
import java.util.UUID;
18 18

  
19
import org.apache.log4j.Level;
20 19
import org.apache.log4j.Logger;
21 20
import org.junit.Assert;
22 21
import org.junit.Before;
......
35 34
import eu.etaxonomy.cdm.model.description.PolytomousKey;
36 35
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
37 36
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
38
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
39 37
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
40 38
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
41 39
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
......
79 77

  
80 78
    @BeforeClass
81 79
    public static void initializePolytomousKeyTest() {
82
        logger.setLevel(Level.INFO);
83
        CDMServer.getInstance().setKeepServerRunning(true);
80

  
84 81
    }
85 82

  
86 83
    @Before
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/PolytomousKeyTest.java
16 16
import java.util.Set;
17 17
import java.util.UUID;
18 18

  
19
import org.apache.log4j.Level;
20 19
import org.apache.log4j.Logger;
21 20
import org.hibernate.collection.spi.PersistentCollection;
22 21
import org.junit.Assert;
......
40 39
import eu.etaxonomy.cdm.model.description.PolytomousKey;
41 40
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
42 41
import eu.etaxonomy.cdm.model.media.Rights;
43
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
44 42
import eu.etaxonomy.cdm.model.taxon.Taxon;
45 43
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
46
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
47 44
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
48 45
import eu.etaxonomy.taxeditor.remoting.cache.EntityCacherDebugResult;
49 46
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
......
83 80

  
84 81
    @BeforeClass
85 82
    public static void initializePolytomousKeyTest() {
86
        logger.setLevel(Level.INFO);
87
        CDMServer.getInstance().setKeepServerRunning(true);
88
        initializeController("default",
89
                "localhost",
90
                8080,
91
                "",
92
                NomenclaturalCode.ICNAFP,
93
                "admin",
94
                "00000");
95 83
    }
96 84

  
97 85
    @Before
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNameEditorTest.java
29 29
import eu.etaxonomy.cdm.model.common.Language;
30 30
import eu.etaxonomy.cdm.model.name.BotanicalName;
31 31
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
32
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
33 32
import eu.etaxonomy.cdm.model.name.NonViralName;
34 33
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
35 34
import eu.etaxonomy.cdm.model.taxon.Synonym;
36 35
import eu.etaxonomy.cdm.model.taxon.Taxon;
37 36
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
38 37
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
39
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
40 38
import eu.etaxonomy.taxeditor.operations.OperationTestBase;
41 39
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
42 40
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
......
69 67

  
70 68
    @BeforeClass
71 69
    public static void initializePolytomousKeyTest() {
72
        //logger.setLevel(Level.INFO);
73
        CDMServer.getInstance().setKeepServerRunning(true);
74
        initializeController("default",
75
                "localhost",
76
                8080,
77
                "",
78
                NomenclaturalCode.ICNAFP,
79
                "admin",
80
                "00000");
81 70
    }
82 71

  
83 72
    @Before
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/model/TaxonNavigatorTest.java
9 9
*/
10 10
package eu.etaxonomy.cdm.model;
11 11

  
12
import org.apache.log4j.Level;
13 12
import org.apache.log4j.Logger;
14 13
import org.junit.Before;
15 14
import org.junit.BeforeClass;
......
19 18
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
20 19
import eu.etaxonomy.cdm.api.service.ITaxonService;
21 20
import eu.etaxonomy.cdm.model.common.Language;
22
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
23
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
24 21
import eu.etaxonomy.taxeditor.operations.OperationTestBase;
25 22
import eu.etaxonomy.taxeditor.remoting.cache.CdmTransientEntityCacher;
26 23
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
......
54 51

  
55 52
    @BeforeClass
56 53
    public static void initializePolytomousKeyTest() {
57
        logger.setLevel(Level.INFO);
58
        CDMServer.getInstance().setKeepServerRunning(true);
59
        initializeController("default",
60
                "localhost",
61
                8080,
62
                "",
63
                NomenclaturalCode.ICNAFP,
64
                "admin",
65
                "00000");
66 54
    }
67 55

  
68 56

  
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/BaseRemotingTest.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.httpinvoker;
10 10

  
11
import java.io.InputStream;
11 12
import java.lang.reflect.Field;
12 13
import java.util.Map;
14
import java.util.Properties;
13 15

  
16
import org.apache.log4j.Logger;
14 17
import org.junit.AfterClass;
15 18
import org.junit.Assert;
16 19
import org.junit.BeforeClass;
......
48 51
 */
49 52
@Transactional(TransactionMode.DISABLED)
50 53
@SpringApplicationContext("file:./target/classes/eu/etaxonomy/cdm/testRemotingApplicationContext.xml")
51
public abstract class BaseRemotingTest extends UnitilsJUnit4 {
52
    //private static final Logger logger = Logger.getLogger(BaseRemotingTest.class);
54
public class BaseRemotingTest extends UnitilsJUnit4 {
55
    private static final Logger logger = Logger.getLogger(BaseRemotingTest.class);
53 56

  
54
    private static final Resource TEST_REMOTE_APPLICATION_CONTEXT_RESOURCE =
55
            new ClassPathResource("/eu/etaxonomy/cdm/testRemotingApplicationContext.xml");
57

  
58
    public static final Resource SERVER_PROPERTIES_FILE =
59
            new ClassPathResource("server.properties");
56 60

  
57 61
    private static CdmApplicationRemoteController remoteApplicationController;
58 62
    private static ICdmRemoteSource cdmRemoteSource;
59 63
    private static CdmPersistentRemoteSource remotePersistentSource;
60 64

  
61
    public static boolean useManagedServer = false;
65
    public static boolean useManagedServer = true;
62 66

  
63 67

  
64 68
    protected static ICdmEntitySessionManager cdmEntitySessionManager;
65 69

  
70
    private final static String DEFAULT_USER = "admin";
71
    private final static String DEFAULT_PASSWORD = "00000";
72

  
73
    private static String user = DEFAULT_USER;
74
    private static String password = DEFAULT_PASSWORD;
66 75

  
67 76
    @BeforeClass
68 77
    public static void initializeBaseRemotingTest() {
......
74 83
        useManagedServer = (System.getProperty("use.managed.server") == null) ? useManagedServer : Boolean.valueOf(System.getProperty("use.managed.server"));
75 84
        if(useManagedServer) {
76 85
            try {
77
                CDMServer.getInstance().start();
86
                CDMServer cdmServer = CDMServer.getInstance();
87
                Properties prop = new Properties();
88
                InputStream inputStream = SERVER_PROPERTIES_FILE.getInputStream();
89

  
90
                if (inputStream != null) {
91
                    prop.load(inputStream);
92
                }
93

  
94
                if(prop.getProperty("httpPort") != null) {
95
                    cdmServer.setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
96
                }
97

  
98
                if(prop.getProperty("stopPort") != null) {
99
                    cdmServer.setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
100
                }
101

  
102
                if(prop.getProperty("stopKey") != null) {
103
                    cdmServer.setStopKey(prop.getProperty("stopKey"));
104
                }
105

  
106
                if(prop.getProperty("user") != null) {
107
                   user = prop.getProperty("user");
108
                }
109

  
110
                if(prop.getProperty("password") != null) {
111
                    password = prop.getProperty("password");
112
                 }
113

  
114
                cdmServer.start();
78 115
            } catch (Exception e) {
79 116
                e.printStackTrace();
80 117
                Assert.fail("Server failed to start. Reason : " + e.getMessage());
......
85 122
                CDMServer.getInstance().getPort(),
86 123
                CDMServer.getInstance().getContextPath(),
87 124
                NomenclaturalCode.ICNAFP,
88
                "admin",
89
                "00000");
125
                user,
126
                password);
90 127
        }
91 128

  
92 129

  
......
100 137
    	DatabaseUnitils.disableConstraints();
101 138
    }
102 139

  
140

  
103 141
    public static void initializeController(String sourceName, String host, int port, String contextPath, NomenclaturalCode ncode, String username, String password) {
104 142

  
143
        if(remoteApplicationController != null) {
144
            return;
145
        }
105 146
        cdmRemoteSource = CdmRemoteSource.NewInstance(sourceName, host, port, contextPath, ncode);
106 147
        remoteApplicationController =
107 148
                CdmApplicationRemoteController.NewInstance(cdmRemoteSource,
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java
12 12
import java.io.BufferedReader;
13 13
import java.io.IOException;
14 14
import java.io.InputStreamReader;
15
import java.net.Socket;
16 15

  
16
import javax.management.InstanceNotFoundException;
17
import javax.management.MBeanException;
18
import javax.management.MBeanServerConnection;
19
import javax.management.MalformedObjectNameException;
20
import javax.management.ObjectName;
21
import javax.management.ReflectionException;
22
import javax.management.remote.JMXConnector;
23
import javax.management.remote.JMXConnectorFactory;
24
import javax.management.remote.JMXServiceURL;
17 25
import javax.sql.DataSource;
18 26

  
19
import org.apache.log4j.Level;
20 27
import org.apache.log4j.Logger;
21 28
import org.springframework.core.io.ClassPathResource;
22 29
import org.springframework.core.io.Resource;
......
48 55

  
49 56
    private final String name = "default";
50 57
    private final String host = "127.0.0.1";
51
    private final int port = 9090;
52
    private final int stopPort = 9191;
53
    private final String stopKey = "jetty-cdm-server";
58
    private int httpPort = 9090;
59
    private int stopPort = 9191;
60
    private String stopKey = "jetty-cdm-server";
54 61
    private final String contextPath = "";
55 62

  
56
    private boolean keepServerRunning = false;
57

  
58 63
    public static final Resource DEFAULT_CDM_WEBAPP_RESOURCE =
59 64
            new ClassPathResource("/etc/jetty/cdmlib-remote-webapp.war");
60 65

  
61
    public static final Resource DEFAULT_JETTY_CONFIG_RESOURCE =
62
            new ClassPathResource("/etc/jetty/jetty.xml");
63

  
64
    public static final Resource DEFAULT_JETTY_TEMP_RESOURCE =
65
            new ClassPathResource("/etc/jetty/temp");
66

  
67
    public static final Resource DEFAULT_JETTY_TEMP_WAR_LIB_RESOURCE =
68
            new ClassPathResource("/etc/jetty/temp/webapp/WEB-INF/lib");
69

  
70 66
    public static final Resource DEFAULT_DATASOURCE_FILE =
71 67
            new ClassPathResource("datasources.xml");
72 68

  
......
76 72
    public static final Resource DEFAULT_JETTY_RESOURCE =
77 73
            new ClassPathResource("/etc/jetty/start-9.2.3.v20140905.jar");
78 74

  
79

  
80

  
81 75
    private static CDMServer cdmServer = null;
82 76
    private static CDMServerException cdmse = null;
83 77

  
84
    private void CDMServer() {
85
        logger.setLevel(Level.INFO);
86
    }
78
    private void CDMServer() {}
87 79

  
88 80
    public static CDMServer getInstance() {
89 81
        if(cdmServer == null) {
......
101 93
    }
102 94

  
103 95
    public int getPort() {
104
        return port;
96
        return httpPort;
105 97
    }
106 98

  
107 99
    public String getContextPath() {
108 100
        return contextPath;
109 101
    }
110 102

  
111
    public boolean getKeepServerRunning() {
112
        return keepServerRunning;
103
    public void setHttpPort(int port) {
104
        this.httpPort = port;
105
    }
106

  
107
    public void setStopPort(int stopPort) {
108
        this.stopPort = stopPort;
113 109
    }
114 110

  
115
    public void setKeepServerRunning(boolean keepServerRunning) {
116
        this.keepServerRunning = keepServerRunning;
111
    public void setStopKey(String stopKey) {
112
        this.stopKey = stopKey;
117 113
    }
118 114

  
115

  
119 116
    public static boolean isRunningInEclipse() {
120 117
        return (System.getProperty("sun.java.command") != null &&
121 118
                System.getProperty("sun.java.command").startsWith("org.eclipse.jdt.internal.junit.runner.RemoteTestRunner"));
......
129 126
        return sb.toString();
130 127
    }
131 128

  
132
    private String getStartServerArgs() {
129
    private String getStartServerArgs() throws IOException {
133 130
        StringBuilder sb = new StringBuilder();
134
        sb.append(" --port ");
135
        sb.append(port);
131
        sb.append(" --port " + httpPort);
136 132
        return sb.toString();
137 133
    }
138 134

  
......
154 150
        return sb.toString();
155 151
    }
156 152

  
153

  
157 154
    public void start() throws CDMServerException {
158 155

  
159 156
        /**
......
163 160
         * has started but incorrectly, in which case we try to force stop it (if we can)
164 161
         * and start a new server.
165 162
         */
166
        if(isRunning(1)) {
167
            logger.info("[CDM-Server] Server already running @ " + host + ":" + port );
163
        if(isStarted(1)) {
164
            logger.info("[CDM-Server] Server already running @ " + host + ":" + httpPort );
168 165
            return;
169
        } else if (isAvailable(1)){
170
            logger.info("[CDM-Server] Server available, but not started correctly @ " + host + ":" + port );
171
            logger.info("[CDM-Server] .... trying to force stop server @ " + host + ":" + port );
172
            try {
173
                stop(true);
174
            } catch (Exception e) {
175
                throw new CDMServerException("CDM Server could not be stopped : " + e.getMessage());
176
            }
177 166
        }
178 167

  
179 168
        Thread t = new Thread() {
180 169
            @Override
181 170
            public void run() {
171

  
182 172
                StringBuffer output = new StringBuffer();
183 173
                try{
184 174
                    Process p;
......
193 183
                    logger.info("[CDM-Server] Starting server with Command : " + command);
194 184
                    p = Runtime.getRuntime().exec(command);
195 185

  
196
                    BufferedReader reader =
186
                    BufferedReader inpReader =
197 187
                            new BufferedReader(new InputStreamReader(p.getInputStream()));
198 188

  
189
                    BufferedReader errReader =
190
                            new BufferedReader(new InputStreamReader(p.getErrorStream()));
191

  
199 192
                    String line = "";
200
                    while ((line = reader.readLine())!= null) {
201
                        logger.info("[CDM-Server] Start : " + line);
193
                    while ((line = inpReader.readLine())!= null) {
194
                        logger.info("[CDM-Server Start] : " + line);
195
                    }
196

  
197
                    while ((line = errReader.readLine())!= null) {
198
                        logger.info("[CDM-Server Start] : " + line);
202 199
                    }
203 200

  
204 201
                } catch (Exception e) {
205 202
                    e.printStackTrace();
206 203
                    cdmse = new CDMServerException(e);
207 204
                }
208

  
209 205
            }
210 206
        };
211 207

  
......
213 209
        cdmse = null;
214 210
        t.start();
215 211

  
216
        if(isRunning(60)) {
217
            logger.info("[CDM-Server] Started Server @ " + host + ":" + port );
212
        if(isStarted(50)) {
213
            logger.info("[CDM-Server] Server running @ " + host + ":" + httpPort );
218 214
        } else {
219 215
            logger.info("[CDM-Server] Server not started within given interval");
220 216
            // making sure to kill server if it is not started correctly
......
228 224

  
229 225
    }
230 226

  
231
    public boolean isAvailable(int checkingIntervals) throws CDMServerException {
232
        int intervalsCount = 0;
233
        do {
234
            try {
235
                Socket s = new Socket(host, port);
236
                logger.info("[CDM-Server] Available @ " + host + ":" + port );
237
                return true;
238
            } catch (IOException ioe) {
239 227

  
240
            }
241
            try {
242
                Thread.sleep(1000);
243
            } catch (InterruptedException ie) {
244
                throw new CDMServerException("Error checking CDM Server status", ie);
245
            }
246
            intervalsCount++;
247
        } while (intervalsCount < checkingIntervals);
248

  
249
        return false;
250
    }
251

  
252
    public boolean isStopped(int checkingIntervals) throws CDMServerException {
253
        int intervalsCount = 0;
254
        do {
255
            try {
256
                Socket s = new Socket(host, port);
257
            } catch (IOException ioe) {
258
                return true;
259
            }
260
            try {
261
                Thread.sleep(1000);
262
            } catch (InterruptedException ie) {
263
                throw new CDMServerException("Error checking CDM Server status", ie);
264
            }
265
            intervalsCount++;
266
        } while (intervalsCount < checkingIntervals);
267

  
268
        return false;
269
    }
270

  
271
    public boolean isRunning(int checkingIntervals) throws CDMServerException  {
228
    public boolean isStarted(int checkingIntervals) throws CDMServerException  {
272 229
        CdmRemoteSourceBase crsb = new CdmRemoteSourceBase("local-cdm-server",
273 230
                host,
274
                port,
231
                httpPort,
275 232
                contextPath,
276 233
                null);
277 234
        int intervalsCount = 0;
......
282 239
                }
283 240
                boolean check = crsb.checkConnection();
284 241
                if(check) {
285
                    logger.info("[CDM-Server] Running @ " + host + ":" + port );
242
                    logger.info("[CDM-Server] Running @ " + host + ":" + httpPort );
286 243
                    return true;
287 244
                }
288 245
            } catch (Exception e) {
......
301 258
    public void stop() throws Exception {
302 259
        stop(false);
303 260
    }
261

  
304 262
    public void stop(boolean force) throws Exception {
305 263

  
306 264
        if(!force) {
307
            if(!getInstance().isAvailable(1)) {
308
                logger.info("[CDM-Server] Server already stopped @ " + host + ":" + port );
309
                return;
310
            }
311

  
312
            if(getInstance().getKeepServerRunning()) {
313
                logger.info("[CDM-Server] Server @ " + host + ":" + port + " is set to keep running");
265
            if(!getInstance().isStarted(1)) {
266
                logger.info("[CDM-Server] Server already stopped @ " + host + ":" + httpPort );
314 267
                return;
315 268
            }
316 269
        }
270

  
317 271
        Thread t = new Thread() {
318 272
            @Override
319 273
            public void run() {
......
324 278
                            + getStopServerArgs() + " --stop ";
325 279
                    logger.info("[CDM-Server] Stop Command : " + command);
326 280
                    p = Runtime.getRuntime().exec(command);
327
                    p.waitFor();
328
                    BufferedReader reader =
281

  
282
                    BufferedReader inpReader =
329 283
                            new BufferedReader(new InputStreamReader(p.getInputStream()));
284

  
285
                    BufferedReader errReader =
286
                            new BufferedReader(new InputStreamReader(p.getErrorStream()));
287

  
330 288
                    String line = "";
331
                    while ((line = reader.readLine())!= null) {
332
                        logger.info("CDM-Server Stop : " + line + "\n");
289
                    while ((line = inpReader.readLine())!= null) {
290
                        logger.info("[CDM-Server Stop] : " + line);
291
                    }
292

  
293
                    while ((line = errReader.readLine())!= null) {
294
                        logger.info("[CDM-Server Stop] : " + line);
333 295
                    }
296
                    logger.info("CDM-Server Stopped : ");
334 297
                } catch (Exception e) {
335
                    e.printStackTrace();
298
                    logger.info("[CDM-Server] Could not stop @ " + host + ":" + httpPort + ". Please kill it manually");
299

  
336 300
                }
337 301

  
338 302
            }
......
341 305
        t.setDaemon(true);
342 306
        t.start();
343 307

  
344
        if(isStopped(5)) {
345
            logger.info("[CDM-Server] Stopped Server @ " + host + ":" + port );
346
        } else {
347
            logger.info("[CDM-Server] Could not stop @ " + host + ":" + port + ". Please kill it manually");
308
    }
309

  
310
    public static void stopServerViaJMX(int jmxPort) throws CDMServerException  {
311
        String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi";
312
        logger.warn("Shutting down Jetty instance ... ");
313

  
314
        try {
315
            JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), null);
316
            connector.connect(null);
317
            MBeanServerConnection connection = connector.getMBeanServerConnection();
318
            ObjectName objectName = new ObjectName("org.eclipse.jetty.server:type=server,id=0");
319
            connection.invoke(objectName, "stop", null, null);
320
            logger.warn("Shutdown command sent");
321
        } catch (InstanceNotFoundException e) {
322
            throw new CDMServerException(e);
323
        } catch (MBeanException e) {
324
            throw new CDMServerException(e);
325
        } catch (ReflectionException e) {
326
            throw new CDMServerException(e);
327
        } catch (IOException e) {
328
            throw new CDMServerException(e);
329
        } catch (MalformedObjectNameException e) {
330
            throw new CDMServerException(e);
348 331
        }
332

  
333

  
334

  
349 335
    }
350 336
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CdmServerTest.java
9 9
*/
10 10
package eu.etaxonomy.taxeditor.httpinvoker;
11 11

  
12
import org.apache.log4j.Level;
13 12
import org.apache.log4j.Logger;
14 13
import org.junit.Assert;
15
import org.junit.Ignore;
16 14
import org.junit.Test;
17 15
import org.unitils.UnitilsJUnit4;
18 16

  
19
import eu.etaxonomy.taxeditor.lazyloading.AbstractLazyInitializerTest;
17
import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
20 18

  
21 19
/**
22 20
 * @author cmathew
......
27 25
    private static final Logger logger = Logger.getLogger(CdmServerTest.class);
28 26

  
29 27

  
28
    @Test
29
    public void startCdmServer() throws CDMServerException {
30
        CDMServer.getInstance().start();
31
    }
32

  
30 33
    @Test
31 34
    public void stopCdmServer() {
32
        Logger.getRootLogger().setLevel(Level.INFO);
33
        CDMServer.getInstance().setKeepServerRunning(false);
34 35
        try {
35 36
            CDMServer.getInstance().stop(true);
36 37
        } catch (Exception e) {
38
            e.printStackTrace();
37 39
            Assert.fail("Server could not be stopped. Reason : " + e.getMessage());
38 40
        }
39 41
    }
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/lazyloading/CdmEntityCacherTest.java
11 11

  
12 12
import java.util.UUID;
13 13

  
14
import org.apache.log4j.Level;
15 14
import org.apache.log4j.Logger;
16 15
import org.hibernate.collection.spi.PersistentCollection;
17 16
import org.junit.Assert;
......
26 25
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27 26
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
28 27
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
29
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
30 28

  
31 29
/**
32 30
 * @author cmathew
......
49 47

  
50 48
    @BeforeClass
51 49
    public static void initializePolytomousKeyTest() {
52
        logger.setLevel(Level.INFO);
53
        CDMServer.getInstance().setKeepServerRunning(true);
54

  
55
        //initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
56 50
    }
57 51

  
58 52
    @Test
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/service/ServiceInterceptorTest.java
12 12
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
13 13
import eu.etaxonomy.cdm.model.common.TermType;
14 14
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
15
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
16 15

  
17 16
public class ServiceInterceptorTest extends BaseRemotingTest {
18
	
17

  
19 18
	 private static final Logger logger = Logger.getLogger(ServiceInterceptorTest.class);
20 19
	 ITermService termService = getRemoteApplicationController().getTermService();
21
	 
20

  
22 21
	    @BeforeClass
23
	    public static void initializeServiceInterceptorTest() {	        
24
	        CDMServer.getInstance().setKeepServerRunning(true);       
22
	    public static void initializeServiceInterceptorTest() {
25 23
	    }
26
	    
24

  
27 25
	    @Test
28 26
	    public void termServiceInterceptorTest() {
29 27
	    	List<DefinedTermBase<?>> terms = termService.listByTermType(TermType.Language, null, null, null, null);
30 28
	    	Assert.assertEquals(terms.size(),CdmCacher.getDefaultCache().getSize());
31
	    	// TO DO : get the static termTypeMap from TermServiceRequestExecutor and check the size 
29
	    	// TO DO : get the static termTypeMap from TermServiceRequestExecutor and check the size
32 30
	    }
33 31
}
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionManagerTest.java
14 14
import eu.etaxonomy.cdm.model.common.Language;
15 15
import eu.etaxonomy.cdm.model.description.PolytomousKey;
16 16
import eu.etaxonomy.taxeditor.httpinvoker.BaseRemotingTest;
17
import eu.etaxonomy.taxeditor.httpinvoker.CDMServer;
18 17

  
19 18
public class CdmEntitySessionManagerTest extends BaseRemotingTest {
20 19

  
......
31 30

  
32 31
	@BeforeClass
33 32
	public static void initializeCdmEntitySessionManagerTest() {
34
		CDMServer.getInstance().setKeepServerRunning(true);
35
		//initializeController("default", "127.0.0.1", 8080, "", NomenclaturalCode.ICNAFP);
36 33
	}
37 34

  
38 35
	@Before
eu.etaxonomy.taxeditor.test/src/test/resources/server.properties
1
httpPort=9090
2
stopPort=9191
3
stopKey=jetty-cdm-server
4
user=admin
5
password=00000
pom.xml
425 425
      </url>
426 426
    </repository>
427 427
  </distributionManagement>
428

  
428 429
</project>

Also available in: Unified diff