Project

General

Profile

« Previous | Next » 

Revision 115e458f

Added by Cherian Mathew almost 9 years ago

fixed issues with resource loading for maven int tests

View differences:

eu.etaxonomy.taxeditor.test/build.properties
3 3
bin.includes = META-INF/,\
4 4
               .,\
5 5
               lib/byte-buddy-0.5.1.jar,\
6
               src/,\
7 6
               lib/org.springframework.context-3.2.2.RELEASE.jar,\
8 7
               lib/unitils-core-3.4.2.jar,\
9 8
               lib/unitils-database-3.4.2.jar,\
10 9
               lib/unitils-dbmaintainer-3.4.2.jar,\
11 10
               lib/unitils-dbunit-3.4.2.jar,\
12 11
               lib/unitils-spring-3.4.2.jar,\
13
               lib/dbunit-2.4.9.jar
14
output.. = bin/
12
               lib/dbunit-2.4.9.jar,\               
13
               src/test/resources/
14
output.. = target/classes
eu.etaxonomy.taxeditor.test/pom.xml
13 13
  <description>Holds all Tests for the Taxonomic Editor</description>
14 14
  <build>
15 15
    <plugins>
16
<!--       <plugin> -->
17
<!--         <groupId>org.eclipse.tycho</groupId> -->
18
<!--         <artifactId>tycho-compiler-plugin</artifactId> -->
19
<!--         <version>${tycho.version}</version> -->
20
<!--         <configuration> -->
21
<!--           <excludes> -->
22
<!--             <exclude>**/*.*</exclude> -->
23
<!--           </excludes> -->
24
<!--         </configuration> -->
25
<!--       </plugin> -->
16 26
      <plugin>
17 27
        <groupId>org.eclipse.tycho</groupId>
18 28
        <artifactId>target-platform-configuration</artifactId>
......
86 96
              <goal>deploy-war</goal>
87 97
            </goals>
88 98
            <configuration>
89
              <scanIntervalSeconds>0</scanIntervalSeconds>              
99
              <scanIntervalSeconds>0</scanIntervalSeconds>
90 100
            </configuration>
91 101
          </execution>
92 102
          <execution>
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.File;
11 12
import java.io.InputStream;
12 13
import java.lang.reflect.Field;
14
import java.net.URL;
13 15
import java.util.Map;
14 16
import java.util.Properties;
15 17

  
16 18
import org.apache.log4j.Logger;
19
import org.eclipse.core.runtime.FileLocator;
20
import org.eclipse.core.runtime.Platform;
17 21
import org.junit.AfterClass;
18 22
import org.junit.Assert;
19 23
import org.junit.BeforeClass;
20 24
import org.junit.Test;
25
import org.osgi.framework.Bundle;
21 26
import org.springframework.core.io.ClassPathResource;
22 27
import org.springframework.core.io.Resource;
23 28
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
......
58 63
    public static final Resource SERVER_PROPERTIES_FILE =
59 64
            new ClassPathResource("server.properties");
60 65

  
66
    public static final Resource EDITOR_DATASOURCES_FILE =
67
            new ClassPathResource(".cdmLibrary/writableResources/cdm.datasources.xml");
68

  
61 69
    private static CdmApplicationRemoteController remoteApplicationController;
62 70
    private static ICdmRemoteSource cdmRemoteSource;
63 71
    private static CdmPersistentRemoteSource remotePersistentSource;
......
70 78
    private final static String DEFAULT_USER = "admin";
71 79
    private final static String DEFAULT_PASSWORD = "00000";
72 80

  
81
    private static String userHomeKey = "user.home";
82

  
73 83
    private static String user = DEFAULT_USER;
74 84
    private static String password = DEFAULT_PASSWORD;
75 85

  
76 86
    @BeforeClass
77 87
    public static void initializeBaseRemotingTest() {
88

  
78 89
        //NOTE: Run this the cdmTest H2 DB whenever it needs to be
79
    	//      recreated e.g. after a model change
80
    	DatabaseUnitils.disableConstraints();
90
        //      recreated e.g. after a model change
91
        DatabaseUnitils.disableConstraints();
81 92

  
93
        try {
94
            String userHomeDirPath;
95
            Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.test");
96
            // if bundle is null then we are running as junit test in eclipse
97
            if(bundle == null) {
98
                userHomeDirPath = EDITOR_DATASOURCES_FILE.getFile().getParentFile().getParentFile().getParent();
99
            } else {
100
                // ... else we are running in maven which requires loading the dir via the
101
                // classpath bundle
102
                URL userHomeDirURL = bundle.getEntry("src/test/resources");
103
                File userHomeDir = new File(FileLocator.resolve(userHomeDirURL).toURI());
104
                userHomeDirPath = userHomeDir.getAbsolutePath();
105
            }
82 106

  
83
        useManagedServer = (System.getProperty("use.managed.server") == null) ? useManagedServer : Boolean.valueOf(System.getProperty("use.managed.server"));
84
        if(useManagedServer) {
85
            try {
86
                CDMServer cdmServer = CDMServer.getInstance();
87
                Properties prop = new Properties();
88
                InputStream inputStream = SERVER_PROPERTIES_FILE.getInputStream();
89 107

  
90
                if (inputStream != null) {
91
                    prop.load(inputStream);
92
                }
108
            logger.info("Setting user.home to " + userHomeDirPath);
109
            System.setProperty(userHomeKey, userHomeDirPath);
93 110

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

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

  
102
                if(prop.getProperty("stopKey") != null) {
103
                    cdmServer.setStopKey(prop.getProperty("stopKey"));
104
                }
114
            Properties prop = new Properties();
115
            InputStream inputStream = SERVER_PROPERTIES_FILE.getInputStream();
105 116

  
106
                if(prop.getProperty("user") != null) {
107
                   user = prop.getProperty("user");
108
                }
117
            if (inputStream != null) {
118
                prop.load(inputStream);
119
                inputStream.close();
120
            }
109 121

  
110
                if(prop.getProperty("password") != null) {
111
                    password = prop.getProperty("password");
112
                 }
122
            if(prop.getProperty("httpPort") != null) {
123
                cdmServer.setHttpPort(Integer.valueOf(prop.getProperty("httpPort")));
124
            }
113 125

  
114
                cdmServer.start();
115
            } catch (Exception e) {
116
                e.printStackTrace();
117
                Assert.fail("Server failed to start. Reason : " + e.getMessage());
126
            if(prop.getProperty("stopPort") != null) {
127
                cdmServer.setStopPort(Integer.valueOf(prop.getProperty("stopPort")));
118 128
            }
119 129

  
120
        initializeController(CDMServer.getInstance().getName(),
121
                CDMServer.getInstance().getHost(),
122
                CDMServer.getInstance().getPort(),
123
                CDMServer.getInstance().getContextPath(),
124
                NomenclaturalCode.ICNAFP,
125
                user,
126
                password);
127
        }
130
            if(prop.getProperty("stopKey") != null) {
131
                cdmServer.setStopKey(prop.getProperty("stopKey"));
132
            }
133

  
134
            if(prop.getProperty("user") != null) {
135
                user = prop.getProperty("user");
136
            }
128 137

  
138
            if(prop.getProperty("password") != null) {
139
                password = prop.getProperty("password");
140
            }
129 141

  
142
            cdmServer.start();
143
            initializeController(CDMServer.getInstance().getName(),
144
                    CDMServer.getInstance().getHost(),
145
                    CDMServer.getInstance().getPort(),
146
                    CDMServer.getInstance().getContextPath(),
147
                    NomenclaturalCode.ICNAFP,
148
                    user,
149
                    password);
150
        } catch (Exception e) {
151
            e.printStackTrace();
152
           // Assert.fail("Server failed to start. Reason : " + e.getMessage());
153
        }
130 154
    }
131 155

  
132 156

  
133 157
    @Test
134 158
    public void disableConstraints() {
135
    	// To be run on the src/test/resources/h2/cdmTest h2 db after
136
    	// updating the unitils.properties 'database.url' property
137
    	DatabaseUnitils.disableConstraints();
159
        // To be run on the src/test/resources/h2/cdmTest h2 db after
160
        // updating the unitils.properties 'database.url' property
161
        DatabaseUnitils.disableConstraints();
138 162
    }
139 163

  
140 164

  
......
181 205
    }
182 206

  
183 207
    protected static ICdmEntitySessionManager getCdmEntitySessionManager() {
184
    	return cdmEntitySessionManager;
208
        return cdmEntitySessionManager;
185 209
    }
186 210

  
187 211

  
188 212
    protected static CdmEntitySession getSession(ICdmEntitySessionEnabled sessionOwner) {
189
    	Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
190
    			(Map<ICdmEntitySessionEnabled, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
191
    	return ownerSessionMap.get(sessionOwner);
213
        Map<ICdmEntitySessionEnabled, CdmEntitySession> ownerSessionMap =
214
                (Map<ICdmEntitySessionEnabled, CdmEntitySession>) getFieldValueViaReflection(cdmEntitySessionManager, "ownerSessionMap");
215
        return ownerSessionMap.get(sessionOwner);
192 216
    }
193 217

  
194 218
    protected static CdmTransientEntityCacher getActiveSession() {
195
    	return (CdmTransientEntityCacher) getFieldValueViaReflection(cdmEntitySessionManager, "activeSession");
219
        return (CdmTransientEntityCacher) getFieldValueViaReflection(cdmEntitySessionManager, "activeSession");
196 220
    }
197 221

  
198 222
    protected static CdmTransientEntityCacher getCacher(ICdmEntitySessionEnabled sessionOwner) {
199
    	return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
223
        return (CdmTransientEntityCacher) getFieldValueViaReflection(getSession(sessionOwner), "cdmTransientEntityCacher");
200 224
    }
201 225

  
202 226
    @AfterClass
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/httpinvoker/CDMServer.java
75 75
    private static CDMServer cdmServer = null;
76 76
    private static CDMServerException cdmse = null;
77 77

  
78
    private boolean serverAlreadyRunning = false;
79

  
78 80
    private void CDMServer() {}
79 81

  
80 82
    public static CDMServer getInstance() {
......
162 164
         */
163 165
        if(isStarted(1)) {
164 166
            logger.info("[CDM-Server] Server already running @ " + host + ":" + httpPort );
167
            serverAlreadyRunning = true;
165 168
            return;
166 169
        }
167 170

  
......
268 271
            }
269 272
        }
270 273

  
274
        if(serverAlreadyRunning) {
275
            return;
276
        }
271 277
        Thread t = new Thread() {
272 278
            @Override
273 279
            public void run() {
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/cdm.datasources.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-3.1.xsd      http://www.springframework.org/schema/context      http://www.springframework.org/schema/context/spring-context-2.5.xsd">
3
  <bean id="defaultRemoteSource">
4
    <property name="server" value="127.0.0.1" />
5
    <property name="port" value="9090" />
6
    <property name="contextPath" value="" />
7
  </bean>
8
  <bean id="incompleteRemoteSource">
9
    <property name="port" value="9090" />
10
    <property name="contextPath" value="" />
11
  </bean>
12
</beans>
13

  
eu.etaxonomy.taxeditor.test/src/test/resources/eu/etaxonomy/cdm/cdm.datasources.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans" 
3
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
4
xmlns:context="http://www.springframework.org/schema/context" 
5
xsi:schemaLocation="http://www.springframework.org/schema/beans      
6
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd     
7
http://www.springframework.org/schema/context     
8
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
9
  <bean id="defaultRemoteSource">
10
    <property name="server" value="127.0.0.1" />
11
    <property name="port" value="9090" />
12
    <property name="contextPath" value="" />
13
  </bean>
14
  
15
  <bean id="incompleteRemoteSource">
16
    <property name="port" value="9090" />
17
    <property name="contextPath" value="" />
18
  </bean>
19
</beans>
20

  

Also available in: Unified diff