Skip to content

Commit

Permalink
Also use args when comparing test resources
Browse files Browse the repository at this point in the history
Relates to: #44129
  • Loading branch information
geoand committed Oct 31, 2024
1 parent 45dbff7 commit df6f7d4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public TestResourceManager(Class<?> testClass,
this.testResourceComparisonInfo = new HashSet<>();
for (TestResourceClassEntry uniqueEntry : uniqueEntries) {
testResourceComparisonInfo.add(new TestResourceComparisonInfo(
uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope()));
uniqueEntry.testResourceLifecycleManagerClass().getName(), uniqueEntry.getScope(), uniqueEntry.args));
}

Set<TestResourceClassEntry> remainingUniqueEntries = initParallelTestResources(uniqueEntries);
Expand Down Expand Up @@ -326,7 +326,12 @@ public static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCo
}
Set<TestResourceManager.TestResourceComparisonInfo> result = new HashSet<>(uniqueEntries.size());
for (TestResourceClassEntry entry : uniqueEntries) {
result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope()));
Map<String, String> args = new HashMap<>(entry.args);
if (entry.configAnnotation != null) {
args.put("configAnnotation", entry.configAnnotation.annotationType().getName());
}
result.add(new TestResourceComparisonInfo(entry.testResourceLifecycleManagerClass().getName(), entry.getScope(),
args));
}
return result;
}
Expand Down Expand Up @@ -603,7 +608,8 @@ public TestResourceScope getScope() {
}
}

public record TestResourceComparisonInfo(String testResourceLifecycleManagerClass, TestResourceScope scope) {
public record TestResourceComparisonInfo(String testResourceLifecycleManagerClass, TestResourceScope scope,
Map<String, String> initArgs) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.junit.jupiter.api.Test;
Expand All @@ -22,66 +23,74 @@ public void emptyResources() {
@Test
public void differentCount() {
assertTrue(testResourcesRequireReload(Collections.emptySet(),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap()))));

assertTrue(testResourcesRequireReload(Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
assertTrue(testResourcesRequireReload(Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS,
Collections.emptyMap())),
Collections.emptySet()));
}

@Test
public void sameSingleRestrictedToClassResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS)),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS))));
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", RESTRICTED_TO_CLASS, Collections.emptyMap()))));
}

@Test
public void sameSingleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void sameSingleMatchingResourceDifferentInitArgs() {
assertFalse(testResourcesRequireReload(

Check failure on line 49 in test-framework/common/src/test/java/io/quarkus/test/common/TestResourceManagerReloadTest.java

View check run for this annotation

quarkus-bot / Build summary for df6f7d4806a9cbfee807c040449df66faf5acf1f

JVM Tests - JDK 17

org.opentest4j.AssertionFailedError: expected: <false> but was: <true> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:31)
	at org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:231)
	at io.quarkus.test.common.TestResourceManagerReloadTest.sameSingleMatchingResourceDifferentInitArgs(TestResourceManagerReloadTest.java:49)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Check failure on line 49 in test-framework/common/src/test/java/io/quarkus/test/common/TestResourceManagerReloadTest.java

View check run for this annotation

quarkus-bot / Build summary for df6f7d4806a9cbfee807c040449df66faf5acf1f

JVM Tests - JDK 21

org.opentest4j.AssertionFailedError: expected: <false> but was: <true> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:31)
	at org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:231)
	at io.quarkus.test.common.TestResourceManagerReloadTest.sameSingleMatchingResourceDifferentInitArgs(TestResourceManagerReloadTest.java:49)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Check failure on line 49 in test-framework/common/src/test/java/io/quarkus/test/common/TestResourceManagerReloadTest.java

View check run for this annotation

quarkus-bot / Build summary for df6f7d4806a9cbfee807c040449df66faf5acf1f

JVM Tests - JDK 17 Windows

org.opentest4j.AssertionFailedError: expected: <false> but was: <true> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
Raw output
org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
	at org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:31)
	at org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:231)
	at io.quarkus.test.common.TestResourceManagerReloadTest.sameSingleMatchingResourceDifferentInitArgs(TestResourceManagerReloadTest.java:49)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Map.of("foo", "bar")))));
}

@Test
public void differentSingleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES)),
Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES))));
Set.of(new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void sameMultipleMatchingResource() {
assertFalse(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void differentMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test3", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES, Collections.emptyMap()))));
}

@Test
public void differentGlobalMultipleMatchingResource() {
assertTrue(testResourcesRequireReload(
Set.of(
new TestResourceComparisonInfo("test", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("test4", GLOBAL)),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES))));
new TestResourceComparisonInfo("test", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("test4", GLOBAL, Collections.emptyMap())),
Set.of(new TestResourceComparisonInfo("test3", GLOBAL, Collections.emptyMap()),
new TestResourceComparisonInfo("test2", MATCHING_RESOURCES, Collections.emptyMap()),
new TestResourceComparisonInfo("TEST", MATCHING_RESOURCES, Collections.emptyMap()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ static Set<TestResourceManager.TestResourceComparisonInfo> testResourceCompariso
if (originalTestResourceScope != null) {
testResourceScope = TestResourceScope.valueOf(originalTestResourceScope.toString());
}
Map<String, String> initArgs = (Map<String, String>) entry.getClass()
.getMethod("initArgs").invoke(entry);
result.add(new TestResourceManager.TestResourceComparisonInfo(testResourceLifecycleManagerClass,
testResourceScope));
testResourceScope, initArgs));
}

return result;
Expand Down

0 comments on commit df6f7d4

Please sign in to comment.