Skip to content

Commit e50af9b

Browse files
authored
Move polaris-admin-tool tests to separate package (#1227)
... and make the PG test-resource non-global.
1 parent 9369911 commit e50af9b

File tree

5 files changed

+121
-24
lines changed

5 files changed

+121
-24
lines changed

quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTest.java renamed to quarkus/admin/src/test/java/org/apache/polaris/admintool/BootstrapCommandTestBase.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020

2121
import static org.apache.polaris.admintool.BaseCommand.EXIT_CODE_BOOTSTRAP_ERROR;
2222
import static org.apache.polaris.admintool.BaseCommand.EXIT_CODE_USAGE;
23-
import static org.apache.polaris.admintool.PostgresTestResourceLifecycleManager.INIT_SCRIPT;
2423
import static org.assertj.core.api.Assertions.assertThat;
2524

26-
import io.quarkus.test.common.ResourceArg;
27-
import io.quarkus.test.common.TestResourceScope;
28-
import io.quarkus.test.common.WithTestResource;
2925
import io.quarkus.test.junit.main.Launch;
3026
import io.quarkus.test.junit.main.LaunchResult;
3127
import io.quarkus.test.junit.main.QuarkusMainLauncher;
@@ -41,11 +37,7 @@
4137
import org.junit.jupiter.api.io.TempDir;
4238

4339
@QuarkusMainTest
44-
@WithTestResource(
45-
value = PostgresTestResourceLifecycleManager.class,
46-
scope = TestResourceScope.GLOBAL,
47-
initArgs = @ResourceArg(name = INIT_SCRIPT, value = "org/apache/polaris/admintool/init.sql"))
48-
class BootstrapCommandTest {
40+
public abstract class BootstrapCommandTestBase {
4941

5042
private static Path json;
5143
private static Path yaml;
@@ -172,7 +164,7 @@ public void testBootstrapInvalidArg(LaunchResult result) {
172164
}
173165

174166
private static Path copyResource(Path temp, String resource) throws IOException {
175-
URL source = Objects.requireNonNull(BootstrapCommandTest.class.getResource(resource));
167+
URL source = Objects.requireNonNull(BootstrapCommandTestBase.class.getResource(resource));
176168
Path dest = temp.resolve(resource);
177169
try (InputStream in = source.openStream()) {
178170
Files.copy(in, dest);

quarkus/admin/src/test/java/org/apache/polaris/admintool/PurgeCommandTest.java renamed to quarkus/admin/src/test/java/org/apache/polaris/admintool/PurgeCommandTestBase.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@
2121
import static org.assertj.core.api.Assertions.assertThat;
2222

2323
import io.quarkus.runtime.StartupEvent;
24-
import io.quarkus.test.common.WithTestResource;
25-
import io.quarkus.test.junit.QuarkusTestProfile;
26-
import io.quarkus.test.junit.TestProfile;
2724
import io.quarkus.test.junit.main.Launch;
2825
import io.quarkus.test.junit.main.LaunchResult;
2926
import io.quarkus.test.junit.main.QuarkusMainTest;
3027
import jakarta.enterprise.event.Observes;
3128
import java.util.List;
32-
import java.util.Map;
3329
import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
3430
import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet;
31+
import org.assertj.core.api.SoftAssertions;
3532
import org.eclipse.microprofile.config.inject.ConfigProperty;
33+
import org.junit.jupiter.api.AfterEach;
34+
import org.junit.jupiter.api.BeforeEach;
3635
import org.junit.jupiter.api.Test;
3736

3837
@QuarkusMainTest
39-
@WithTestResource(PostgresTestResourceLifecycleManager.class)
40-
@TestProfile(PurgeCommandTest.Profile.class)
41-
class PurgeCommandTest {
38+
public abstract class PurgeCommandTestBase {
39+
protected SoftAssertions soft;
4240

43-
public static class Profile implements QuarkusTestProfile {
41+
@BeforeEach
42+
void setup() {
43+
soft = new SoftAssertions();
44+
}
4445

45-
@Override
46-
public Map<String, String> getConfigOverrides() {
47-
return Map.of("pre-bootstrap", "true");
48-
}
46+
@AfterEach
47+
void after() {
48+
soft.assertAll();
4949
}
5050

5151
void preBootstrap(
@@ -69,9 +69,9 @@ public void testPurge(LaunchResult result) {
6969
value = {"purge", "-r", "realm3"},
7070
exitCode = BaseCommand.EXIT_CODE_PURGE_ERROR)
7171
public void testPurgeFailure(LaunchResult result) {
72-
assertThat(result.getOutput())
72+
soft.assertThat(result.getOutput())
7373
.contains(
7474
"Realm realm3 is not bootstrapped, could not load root principal. Please run Bootstrap command.");
75-
assertThat(result.getErrorOutput()).contains("Purge encountered errors during operation.");
75+
soft.assertThat(result.getErrorOutput()).contains("Purge encountered errors during operation.");
7676
}
7777
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.admintool.el;
20+
21+
import io.quarkus.test.junit.TestProfile;
22+
import org.apache.polaris.admintool.BootstrapCommandTestBase;
23+
24+
@TestProfile(EclipselinkProfile.class)
25+
class EclipselinkBootstrapCommandTest extends BootstrapCommandTestBase {}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.admintool.el;
20+
21+
import static org.apache.polaris.admintool.PostgresTestResourceLifecycleManager.INIT_SCRIPT;
22+
23+
import io.quarkus.test.junit.QuarkusTestProfile;
24+
import java.util.List;
25+
import java.util.Map;
26+
import org.apache.polaris.admintool.PostgresTestResourceLifecycleManager;
27+
28+
public class EclipselinkProfile implements QuarkusTestProfile {
29+
30+
@Override
31+
public Map<String, String> getConfigOverrides() {
32+
return Map.of();
33+
}
34+
35+
@Override
36+
public List<TestResourceEntry> testResources() {
37+
return List.of(
38+
new TestResourceEntry(
39+
PostgresTestResourceLifecycleManager.class,
40+
Map.of(INIT_SCRIPT, "org/apache/polaris/admintool/init.sql")));
41+
}
42+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.admintool.el;
20+
21+
import io.quarkus.test.junit.TestProfile;
22+
import java.util.Map;
23+
import org.apache.polaris.admintool.PurgeCommandTestBase;
24+
import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
25+
26+
@TestProfile(EclipselinkPurgeCommandTest.Profile.class)
27+
class EclipselinkPurgeCommandTest extends PurgeCommandTestBase {
28+
29+
public static class Profile extends EclipselinkProfile {
30+
@Override
31+
public Map<String, String> getConfigOverrides() {
32+
return ImmutableMap.<String, String>builder()
33+
.putAll(super.getConfigOverrides())
34+
.put("pre-bootstrap", "true")
35+
.build();
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)