-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for MATCHING_RESOURCE TestResource issue
- Loading branch information
Showing
5 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...t-extension/tests/src/test/java/io/quarkus/it/extension/testresources/SharedResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.quarkus.it.extension.testresources; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class SharedResource implements QuarkusTestResourceLifecycleManager { | ||
private String argument; | ||
|
||
@Override | ||
public void init(Map<String, String> initArgs) { | ||
this.argument = requireNonNull(initArgs.get("resource.arg")); | ||
} | ||
|
||
@Override | ||
public Map<String, String> start() { | ||
System.err.println(getClass().getSimpleName() + " start with arg '" + argument + "'"); | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.err.println(getClass().getSimpleName() + " stop"); | ||
} | ||
|
||
@Override | ||
public void inject(TestInjector testInjector) { | ||
testInjector.injectIntoFields(argument, | ||
new TestInjector.AnnotatedAndMatchesType(SharedResourceAnnotation.class, String.class)); | ||
} | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface SharedResourceAnnotation { | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...st-extension/tests/src/test/java/io/quarkus/it/extension/testresources/SomeResource1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.it.extension.testresources; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class SomeResource1 implements QuarkusTestResourceLifecycleManager { | ||
@Override | ||
public Map<String, String> start() { | ||
System.err.println(getClass().getSimpleName() + " start"); | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.err.println(getClass().getSimpleName() + " stop"); | ||
} | ||
|
||
@Override | ||
public void inject(TestInjector testInjector) { | ||
testInjector.injectIntoFields(getClass().getSimpleName(), | ||
new TestInjector.AnnotatedAndMatchesType(Resource1Annotation.class, String.class)); | ||
} | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface Resource1Annotation { | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...st-extension/tests/src/test/java/io/quarkus/it/extension/testresources/SomeResource2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.it.extension.testresources; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.util.Map; | ||
|
||
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
||
public class SomeResource2 implements QuarkusTestResourceLifecycleManager { | ||
@Override | ||
public Map<String, String> start() { | ||
System.err.println(getClass().getSimpleName() + " start"); | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
System.err.println(getClass().getSimpleName() + " stop"); | ||
} | ||
|
||
@Override | ||
public void inject(TestInjector testInjector) { | ||
testInjector.injectIntoFields(getClass().getSimpleName(), | ||
new TestInjector.AnnotatedAndMatchesType(Resource2Annotation.class, String.class)); | ||
} | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface Resource2Annotation { | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/src/test/java/io/quarkus/it/extension/testresources/WithResourcesPoliciesFirstTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.it.extension.testresources; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.ResourceArg; | ||
import io.quarkus.test.common.TestResourceScope; | ||
import io.quarkus.test.common.WithTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@WithTestResource(value = SomeResource1.class, scope = TestResourceScope.MATCHING_RESOURCES) | ||
@WithTestResource(value = SharedResource.class, scope = TestResourceScope.MATCHING_RESOURCES, initArgs = { | ||
@ResourceArg(name = "resource.arg", value = "test-one") }) | ||
public class WithResourcesPoliciesFirstTest { | ||
@SomeResource1.Resource1Annotation | ||
String resource1; | ||
@SomeResource2.Resource2Annotation | ||
String resource2; | ||
@SharedResource.SharedResourceAnnotation | ||
String sharedResource; | ||
|
||
@Test | ||
public void checkOnlyResource1started() { | ||
assertThat(Arrays.asList(resource1, resource2, sharedResource)).isEqualTo( | ||
Arrays.asList("SomeResource1", null, "test-one")); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
.../src/test/java/io/quarkus/it/extension/testresources/WithResourcesPoliciesSecondTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.it.extension.testresources; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.ResourceArg; | ||
import io.quarkus.test.common.TestResourceScope; | ||
import io.quarkus.test.common.WithTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
@WithTestResource(value = SomeResource2.class, scope = TestResourceScope.MATCHING_RESOURCES) | ||
@WithTestResource(value = SharedResource.class, scope = TestResourceScope.MATCHING_RESOURCES, initArgs = { | ||
@ResourceArg(name = "resource.arg", value = "test-two") }) | ||
public class WithResourcesPoliciesSecondTest { | ||
@SomeResource1.Resource1Annotation | ||
String resource1; | ||
@SomeResource2.Resource2Annotation | ||
String resource2; | ||
@SharedResource.SharedResourceAnnotation | ||
String sharedResource; | ||
|
||
@Test | ||
public void checkOnlyResource1started() { | ||
assertThat(Arrays.asList(resource1, resource2, sharedResource)).isEqualTo( | ||
Arrays.asList(null, "SomeResource2", "test-two")); | ||
} | ||
} |