Skip to content

Commit f7d85d6

Browse files
jansupolbvfalcon
authored andcommitted
Additional changes to execute all tests
Signed-off-by: jansupol <[email protected]>
1 parent f03e351 commit f7d85d6

File tree

34 files changed

+338
-110
lines changed

34 files changed

+338
-110
lines changed

examples/entity-filtering-security/src/test/java/org/glassfish/jersey/examples/entityfiltering/security/RestrictedResourceTest.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@
2121
import org.glassfish.jersey.server.ResourceConfig;
2222
import org.glassfish.jersey.test.JerseyTest;
2323
import org.glassfish.jersey.test.TestProperties;
24+
import org.glassfish.jersey.test.spi.TestHelper;
25+
import org.junit.jupiter.api.DynamicContainer;
2426
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.TestFactory;
28+
29+
import java.util.ArrayList;
30+
import java.util.Arrays;
31+
import java.util.Collection;
32+
2533
import static org.hamcrest.CoreMatchers.equalTo;
2634
import static org.hamcrest.CoreMatchers.notNullValue;
2735
import static org.hamcrest.CoreMatchers.nullValue;
@@ -34,7 +42,21 @@
3442
*/
3543
public class RestrictedResourceTest {
3644

37-
public abstract static class RestrictedResourceTemplateTest extends JerseyTest {
45+
public static Iterable<Class<? extends Feature>> providers() {
46+
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
47+
}
48+
49+
@TestFactory
50+
public Collection<DynamicContainer> generateTests() {
51+
Collection<DynamicContainer> tests = new ArrayList<>();
52+
providers().forEach(feature -> {
53+
RestrictedResourceTemplateTest test = new RestrictedResourceTemplateTest(feature);
54+
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
55+
});
56+
return tests;
57+
}
58+
59+
public static class RestrictedResourceTemplateTest extends JerseyTest {
3860
public RestrictedResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
3961
super(new ResourceConfig(SecurityEntityFilteringFeature.class)
4062
.packages("org.glassfish.jersey.examples.entityfiltering.security")
@@ -136,16 +158,4 @@ public void testRuntimeRolesAllowedInvalid() throws Exception {
136158
assertThat(mixedField, nullValue());
137159
}
138160
}
139-
140-
public static class MoxyJsonFeatureRestrictedResourceTest extends RestrictedResourceTemplateTest {
141-
public MoxyJsonFeatureRestrictedResourceTest() {
142-
super(MoxyJsonFeature.class);
143-
}
144-
}
145-
146-
public static class JacksonFeatureRestrictedResourceTest extends RestrictedResourceTemplateTest {
147-
public JacksonFeatureRestrictedResourceTest() {
148-
super(JacksonFeature.class);
149-
}
150-
}
151161
}

examples/entity-filtering-security/src/test/java/org/glassfish/jersey/examples/entityfiltering/security/UnrestrictedResourceTest.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
import org.glassfish.jersey.server.ResourceConfig;
2121
import org.glassfish.jersey.test.JerseyTest;
2222
import org.glassfish.jersey.test.TestProperties;
23+
import org.glassfish.jersey.test.spi.TestHelper;
24+
import org.junit.jupiter.api.DynamicContainer;
2325
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.api.TestFactory;
27+
28+
import java.util.ArrayList;
29+
import java.util.Arrays;
30+
import java.util.Collection;
31+
2432
import static org.hamcrest.CoreMatchers.notNullValue;
2533
import static org.hamcrest.CoreMatchers.nullValue;
2634
import static org.hamcrest.MatcherAssert.assertThat;
@@ -32,7 +40,21 @@
3240
*/
3341
public class UnrestrictedResourceTest {
3442

35-
public abstract static class UnrestrictedResourceTemplateTest extends JerseyTest {
43+
public static Iterable<Class<? extends Feature>> providers() {
44+
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
45+
}
46+
47+
@TestFactory
48+
public Collection<DynamicContainer> generateTests() {
49+
Collection<DynamicContainer> tests = new ArrayList<>();
50+
providers().forEach(feature -> {
51+
UnrestrictedResourceTemplateTest test = new UnrestrictedResourceTemplateTest(feature) {};
52+
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
53+
});
54+
return tests;
55+
}
56+
57+
public static class UnrestrictedResourceTemplateTest extends JerseyTest {
3658
public UnrestrictedResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
3759
super(new ResourceConfig(SecurityEntityFilteringFeature.class)
3860
.packages("org.glassfish.jersey.examples.entityfiltering.security")
@@ -58,16 +80,4 @@ public void testRestrictedEntity() throws Exception {
5880
assertThat(mixedField.getUserField(), nullValue());
5981
}
6082
}
61-
62-
public static class MoxyJsonFeatureUnrestrictedResourceTest extends UnrestrictedResourceTemplateTest {
63-
public MoxyJsonFeatureUnrestrictedResourceTest() {
64-
super(MoxyJsonFeature.class);
65-
}
66-
}
67-
68-
public static class JacksonFeatureUnrestrictedResourceTest extends UnrestrictedResourceTemplateTest {
69-
public JacksonFeatureUnrestrictedResourceTest() {
70-
super(JacksonFeature.class);
71-
}
72-
}
7383
}

examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
package org.glassfish.jersey.examples.entityfiltering.selectable;
1212

13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
import java.util.Collection;
1316
import java.util.List;
1417
import java.util.Map;
1518

@@ -26,7 +29,10 @@
2629
import org.glassfish.jersey.server.ResourceConfig;
2730
import org.glassfish.jersey.test.JerseyTest;
2831
import org.glassfish.jersey.test.TestProperties;
32+
import org.glassfish.jersey.test.spi.TestHelper;
33+
import org.junit.jupiter.api.DynamicContainer;
2934
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.TestFactory;
3036

3137
import static org.hamcrest.CoreMatchers.notNullValue;
3238
import static org.hamcrest.CoreMatchers.nullValue;
@@ -40,7 +46,21 @@
4046
*/
4147
public class PersonResourceTest {
4248

43-
public abstract static class PersonResourceTemplateTest extends JerseyTest {
49+
public static Iterable<Class<? extends Feature>> providers() {
50+
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
51+
}
52+
53+
@TestFactory
54+
public Collection<DynamicContainer> generateTests() {
55+
Collection<DynamicContainer> tests = new ArrayList<>();
56+
providers().forEach(feature -> {
57+
PersonResourceTemplateTest test = new PersonResourceTemplateTest(feature);
58+
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
59+
});
60+
return tests;
61+
}
62+
63+
public static class PersonResourceTemplateTest extends JerseyTest {
4464
private final Class<? extends Feature> filteringProvider;
4565

4666
public PersonResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
@@ -193,16 +213,4 @@ public void testFiltersSameName() throws Exception {
193213
assertThat(secondLevel.getRegion(), nullValue());
194214
}
195215
}
196-
197-
public static class MoxyJsonFeaturePersonResourceTest extends PersonResourceTemplateTest {
198-
public MoxyJsonFeaturePersonResourceTest() {
199-
super(MoxyJsonFeature.class);
200-
}
201-
}
202-
203-
public static class JacksonFeaturePersonResourceTest extends PersonResourceTemplateTest {
204-
public JacksonFeaturePersonResourceTest() {
205-
super(JacksonFeature.class);
206-
}
207-
}
208216
}

examples/entity-filtering/src/test/java/org/glassfish/jersey/examples/entityfiltering/ProjectsResourceTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
package org.glassfish.jersey.examples.entityfiltering;
1212

13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
import java.util.Collection;
1316
import java.util.List;
1417

1518
import javax.ws.rs.core.Feature;
@@ -22,8 +25,11 @@
2225
import org.glassfish.jersey.server.ResourceConfig;
2326
import org.glassfish.jersey.test.JerseyTest;
2427
import org.glassfish.jersey.test.TestProperties;
28+
import org.glassfish.jersey.test.spi.TestHelper;
29+
import org.junit.jupiter.api.DynamicContainer;
2530
import org.junit.jupiter.api.Nested;
2631
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.TestFactory;
2733

2834
import static org.hamcrest.CoreMatchers.notNullValue;
2935
import static org.hamcrest.CoreMatchers.nullValue;
@@ -36,8 +42,22 @@
3642
*/
3743
public class ProjectsResourceTest {
3844

39-
public abstract static class ProjectsResourceTemplateTest extends JerseyTest {
40-
public ProjectsResourceTemplateTest(final Class<?extends Feature> filteringProvider) {
45+
public static Iterable<Class<? extends Feature>> providers() {
46+
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
47+
}
48+
49+
@TestFactory
50+
public Collection<DynamicContainer> generateTests() {
51+
Collection<DynamicContainer> tests = new ArrayList<>();
52+
providers().forEach(feature -> {
53+
ProjectsResourceTemplateTest test = new ProjectsResourceTemplateTest(feature);
54+
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
55+
});
56+
return tests;
57+
}
58+
59+
public static class ProjectsResourceTemplateTest extends JerseyTest {
60+
public ProjectsResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
4161
super(new ResourceConfig(EntityFilteringFeature.class)
4262
.packages("org.glassfish.jersey.examples.entityfiltering.resource")
4363
.register(filteringProvider));
@@ -87,17 +107,4 @@ private void testProject(final Project project, final boolean isDetailed) {
87107
}
88108
}
89109

90-
@Nested
91-
public static class MoxyJsonFeatureProjectsResourceTest extends ProjectsResourceTemplateTest {
92-
public MoxyJsonFeatureProjectsResourceTest() {
93-
super(MoxyJsonFeature.class);
94-
}
95-
}
96-
97-
@Nested
98-
public static class JacksonFeatureProjectsResourceTest extends ProjectsResourceTemplateTest {
99-
public JacksonFeatureProjectsResourceTest() {
100-
super(JacksonFeature.class);
101-
}
102-
}
103110
}

examples/entity-filtering/src/test/java/org/glassfish/jersey/examples/entityfiltering/TaskResourceTest.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
package org.glassfish.jersey.examples.entityfiltering;
1212

13+
import java.util.ArrayList;
14+
import java.util.Arrays;
15+
import java.util.Collection;
1316
import java.util.List;
1417

1518
import javax.ws.rs.core.Feature;
@@ -22,7 +25,10 @@
2225
import org.glassfish.jersey.server.ResourceConfig;
2326
import org.glassfish.jersey.test.JerseyTest;
2427
import org.glassfish.jersey.test.TestProperties;
28+
import org.glassfish.jersey.test.spi.TestHelper;
29+
import org.junit.jupiter.api.DynamicContainer;
2530
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.TestFactory;
2632

2733
import static org.hamcrest.CoreMatchers.notNullValue;
2834
import static org.hamcrest.CoreMatchers.nullValue;
@@ -35,6 +41,20 @@
3541
*/
3642
public class TaskResourceTest {
3743

44+
public static Iterable<Class<? extends Feature>> providers() {
45+
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
46+
}
47+
48+
@TestFactory
49+
public Collection<DynamicContainer> generateTests() {
50+
Collection<DynamicContainer> tests = new ArrayList<>();
51+
providers().forEach(feature -> {
52+
TaskResourceTemplateTest test = new TaskResourceTemplateTest(feature) {};
53+
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
54+
});
55+
return tests;
56+
}
57+
3858
public abstract static class TaskResourceTemplateTest extends JerseyTest {
3959
public TaskResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
4060
super(new ResourceConfig(EntityFilteringFeature.class)
@@ -85,16 +105,4 @@ private void testTask(final Task task, final boolean isDetailed) {
85105
}
86106
}
87107
}
88-
89-
public static class MoxyJsonFeatureTaskResourceTest extends TaskResourceTemplateTest {
90-
public MoxyJsonFeatureTaskResourceTest() {
91-
super(MoxyJsonFeature.class);
92-
}
93-
}
94-
95-
public static class JacksonFeatureTaskResourceTest extends TaskResourceTemplateTest {
96-
public JacksonFeatureTaskResourceTest() {
97-
super(JacksonFeature.class);
98-
}
99-
}
100108
}

examples/extended-wadl-webapp/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@
234234
<forkMode>always</forkMode>
235235
<enableAssertions>false</enableAssertions>
236236
</configuration>
237+
<dependencies>
238+
<dependency>
239+
<groupId>org.apache.maven.surefire</groupId>
240+
<artifactId>surefire-junit47</artifactId>
241+
<version>${surefire.version}</version>
242+
</dependency>
243+
</dependencies>
237244
</plugin>
238245
<plugin>
239246
<groupId>org.ops4j.pax.exam</groupId>

examples/helloworld-weld/src/test/java/org/glassfish/jersey/examples/helloworld/RequestScopedResourceTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ public static void after() throws Exception {
9797
weld.shutdown();
9898
}
9999

100+
@Override
101+
@AfterAll
102+
public void tearDown() throws Exception {
103+
super.tearDown();
104+
System.out.printf("SYNC: %d, ASYNC: %d, STRAIGHT: %d%n",
105+
parameterizedCounter.intValue(), parameterizedAsyncCounter.intValue(), straightCounter.intValue());
106+
}
107+
100108
@Override
101109
protected ResourceConfig configure() {
102110
// enable(TestProperties.LOG_TRAFFIC);

ext/metainf-services/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@
9090
</instructions>
9191
</configuration>
9292
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-surefire-plugin</artifactId>
96+
<configuration>
97+
<test>**/MetaInfServicesTest*</test>
98+
</configuration>
99+
</plugin>
93100
</plugins>
94101
</build>
95102

test-framework/core/src/main/java/org/glassfish/jersey/test/JerseyTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.glassfish.jersey.test;
1818

19+
import java.lang.annotation.Annotation;
1920
import java.net.URI;
2021
import java.security.AccessController;
2122
import java.util.ArrayList;
@@ -57,6 +58,7 @@
5758
import org.junit.Before;
5859
import org.junit.jupiter.api.AfterEach;
5960
import org.junit.jupiter.api.BeforeEach;
61+
import org.junit.jupiter.api.TestInstance;
6062

6163
/**
6264
* Parent class for testing JAX-RS and Jersey-based applications using Jersey test framework.
@@ -616,7 +618,7 @@ public final Client client() {
616618
@BeforeEach
617619
public void setUp() throws Exception {
618620
synchronized (this) {
619-
if (activeThreadCount.getAndIncrement() == 0) {
621+
if (!isConcurrent() || activeThreadCount.getAndIncrement() == 0) {
620622
registerLogHandlerIfEnabled();
621623
final TestContainer testContainer = createTestContainer(context);
622624

@@ -630,6 +632,24 @@ public void setUp() throws Exception {
630632
}
631633
}
632634

635+
/**
636+
* Do not setup multiple containers for concurrent junit 5 environment not to hit Address already in use exception
637+
* @return true when TestInstance.Lifecycle.PER_CLASS annotation is used and the test run in concurrent
638+
*/
639+
private boolean isConcurrent() {
640+
Annotation[] annotations = this.getClass().getAnnotations();
641+
for (Annotation annotation : annotations) {
642+
// check the name first for JUnit 4 only environment
643+
if (annotation.annotationType().getName().equals("org.junit.jupiter.api.TestInstance")) {
644+
TestInstance testInstance = (TestInstance) annotation;
645+
if (testInstance != null && testInstance.value() == TestInstance.Lifecycle.PER_CLASS) {
646+
return true;
647+
}
648+
}
649+
}
650+
return false;
651+
}
652+
633653
/**
634654
* Tear down the test by {@link TestContainer#stop() stopping} the test container obtained from the
635655
* {@link #getTestContainerFactory() test container factory} and by {@link javax.ws.rs.client.Client#close() closing}
@@ -642,7 +662,7 @@ public void setUp() throws Exception {
642662
@AfterEach
643663
public void tearDown() throws Exception {
644664
synchronized (this) {
645-
if (activeThreadCount.decrementAndGet() == 0) {
665+
if (!isConcurrent() || activeThreadCount.decrementAndGet() == 0) {
646666
if (isLogRecordingEnabled()) {
647667
unregisterLogHandler();
648668
}

0 commit comments

Comments
 (0)