Skip to content

Commit db62d8e

Browse files
ARTEMIS-6126 Fixing basedir resolution on testsuite
This is particularly important if running tests through the IDE
1 parent ab3c542 commit db62d8e

4 files changed

Lines changed: 51 additions & 4 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.activemq.artemis.utils;
19+
20+
import java.io.File;
21+
import java.lang.invoke.MethodHandles;
22+
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
public class BasedirSupport {
27+
28+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
29+
30+
public static final String getBasedir() {
31+
String basedir = System.getProperty("basedir", ".");
32+
try {
33+
if (basedir.equals(".")) {
34+
basedir = new File(".").getAbsolutePath();
35+
if (basedir.endsWith("/.")) {
36+
basedir = basedir.substring(0, basedir.length() - 2);
37+
}
38+
}
39+
40+
} catch (Exception e) {
41+
logger.warn(e.getMessage(), e);
42+
}
43+
return basedir;
44+
}
45+
46+
}

tests/artemis-test-support/src/main/java/org/apache/activemq/artemis/utils/RealServerTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class RealServerTestBase extends ActiveMQTestBase {
6262
private static final String JMX_SERVER_HOSTNAME = "localhost";
6363
private static final int JMX_SERVER_PORT = 10099;
6464

65-
public static final String basedir = System.getProperty("basedir");
65+
public static final String basedir = BasedirSupport.getBasedir();
6666

6767
public static final String ARTEMIS_HOME_PROPERTY = "artemis.distribution.output";
6868

tests/e2e-tests/src/test/java/org/apache/activemq/artemis/tests/e2e/common/E2ETestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
2020
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
2121
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
22+
import org.apache.activemq.artemis.utils.BasedirSupport;
2223

2324
public class E2ETestBase extends ActiveMQTestBase {
2425

25-
public static final String basedir = System.getProperty("basedir");
26+
public static final String basedir = BasedirSupport.getBasedir();
2627

2728
protected static final void recreateBrokerDirectory(final String homeInstance) {
2829
recreateDirectory(homeInstance + "/data");

tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/upgradeTest/CompareUpgradeTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.activemq.artemis.cli.commands.ActionContext;
4444
import org.apache.activemq.artemis.cli.commands.Create;
4545
import org.apache.activemq.artemis.cli.commands.Upgrade;
46+
import org.apache.activemq.artemis.utils.BasedirSupport;
4647
import org.apache.activemq.artemis.utils.FileUtil;
4748
import org.junit.jupiter.api.Test;
4849
import org.slf4j.Logger;
@@ -55,8 +56,7 @@ public class CompareUpgradeTest {
5556

5657
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
5758

58-
public static final String basedir = System.getProperty("basedir");
59-
59+
public static final String basedir = BasedirSupport.getBasedir();
6060

6161
@Test
6262
public void testCompareWindowsFreshInstance() throws Exception {

0 commit comments

Comments
 (0)