Skip to content

Commit 26f934a

Browse files
ARTEMIS-6126 Fixing basedir resolution on testsuite
This is particularly important if running tests through the IDE
1 parent 473d8c8 commit 26f934a

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.io.IOException;
22+
23+
public class BasedirSupport {
24+
25+
public static String getBasedir() {
26+
String basedir = System.getProperty("basedir");
27+
if (basedir == null) {
28+
try {
29+
basedir = new File(".").getCanonicalPath();
30+
} catch (IOException e) {
31+
throw new RuntimeException("Failed to resolve canonical path for current directory", e);
32+
}
33+
}
34+
return basedir;
35+
}
36+
37+
}

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)