Skip to content

Commit

Permalink
Additional changes to execute all tests
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol authored and bvfalcon committed Nov 11, 2022
1 parent f03e351 commit f7d85d6
Show file tree
Hide file tree
Showing 34 changed files with 338 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -34,7 +42,21 @@
*/
public class RestrictedResourceTest {

public abstract static class RestrictedResourceTemplateTest extends JerseyTest {
public static Iterable<Class<? extends Feature>> providers() {
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
}

@TestFactory
public Collection<DynamicContainer> generateTests() {
Collection<DynamicContainer> tests = new ArrayList<>();
providers().forEach(feature -> {
RestrictedResourceTemplateTest test = new RestrictedResourceTemplateTest(feature);
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
});
return tests;
}

public static class RestrictedResourceTemplateTest extends JerseyTest {
public RestrictedResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
super(new ResourceConfig(SecurityEntityFilteringFeature.class)
.packages("org.glassfish.jersey.examples.entityfiltering.security")
Expand Down Expand Up @@ -136,16 +158,4 @@ public void testRuntimeRolesAllowedInvalid() throws Exception {
assertThat(mixedField, nullValue());
}
}

public static class MoxyJsonFeatureRestrictedResourceTest extends RestrictedResourceTemplateTest {
public MoxyJsonFeatureRestrictedResourceTest() {
super(MoxyJsonFeature.class);
}
}

public static class JacksonFeatureRestrictedResourceTest extends RestrictedResourceTemplateTest {
public JacksonFeatureRestrictedResourceTest() {
super(JacksonFeature.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -32,7 +40,21 @@
*/
public class UnrestrictedResourceTest {

public abstract static class UnrestrictedResourceTemplateTest extends JerseyTest {
public static Iterable<Class<? extends Feature>> providers() {
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
}

@TestFactory
public Collection<DynamicContainer> generateTests() {
Collection<DynamicContainer> tests = new ArrayList<>();
providers().forEach(feature -> {
UnrestrictedResourceTemplateTest test = new UnrestrictedResourceTemplateTest(feature) {};
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
});
return tests;
}

public static class UnrestrictedResourceTemplateTest extends JerseyTest {
public UnrestrictedResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
super(new ResourceConfig(SecurityEntityFilteringFeature.class)
.packages("org.glassfish.jersey.examples.entityfiltering.security")
Expand All @@ -58,16 +80,4 @@ public void testRestrictedEntity() throws Exception {
assertThat(mixedField.getUserField(), nullValue());
}
}

public static class MoxyJsonFeatureUnrestrictedResourceTest extends UnrestrictedResourceTemplateTest {
public MoxyJsonFeatureUnrestrictedResourceTest() {
super(MoxyJsonFeature.class);
}
}

public static class JacksonFeatureUnrestrictedResourceTest extends UnrestrictedResourceTemplateTest {
public JacksonFeatureUnrestrictedResourceTest() {
super(JacksonFeature.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;

Expand All @@ -26,7 +29,10 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -40,7 +46,21 @@
*/
public class PersonResourceTest {

public abstract static class PersonResourceTemplateTest extends JerseyTest {
public static Iterable<Class<? extends Feature>> providers() {
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
}

@TestFactory
public Collection<DynamicContainer> generateTests() {
Collection<DynamicContainer> tests = new ArrayList<>();
providers().forEach(feature -> {
PersonResourceTemplateTest test = new PersonResourceTemplateTest(feature);
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
});
return tests;
}

public static class PersonResourceTemplateTest extends JerseyTest {
private final Class<? extends Feature> filteringProvider;

public PersonResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
Expand Down Expand Up @@ -193,16 +213,4 @@ public void testFiltersSameName() throws Exception {
assertThat(secondLevel.getRegion(), nullValue());
}
}

public static class MoxyJsonFeaturePersonResourceTest extends PersonResourceTemplateTest {
public MoxyJsonFeaturePersonResourceTest() {
super(MoxyJsonFeature.class);
}
}

public static class JacksonFeaturePersonResourceTest extends PersonResourceTemplateTest {
public JacksonFeaturePersonResourceTest() {
super(JacksonFeature.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

package org.glassfish.jersey.examples.entityfiltering;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.ws.rs.core.Feature;
Expand All @@ -22,8 +25,11 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -36,8 +42,22 @@
*/
public class ProjectsResourceTest {

public abstract static class ProjectsResourceTemplateTest extends JerseyTest {
public ProjectsResourceTemplateTest(final Class<?extends Feature> filteringProvider) {
public static Iterable<Class<? extends Feature>> providers() {
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
}

@TestFactory
public Collection<DynamicContainer> generateTests() {
Collection<DynamicContainer> tests = new ArrayList<>();
providers().forEach(feature -> {
ProjectsResourceTemplateTest test = new ProjectsResourceTemplateTest(feature);
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
});
return tests;
}

public static class ProjectsResourceTemplateTest extends JerseyTest {
public ProjectsResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
super(new ResourceConfig(EntityFilteringFeature.class)
.packages("org.glassfish.jersey.examples.entityfiltering.resource")
.register(filteringProvider));
Expand Down Expand Up @@ -87,17 +107,4 @@ private void testProject(final Project project, final boolean isDetailed) {
}
}

@Nested
public static class MoxyJsonFeatureProjectsResourceTest extends ProjectsResourceTemplateTest {
public MoxyJsonFeatureProjectsResourceTest() {
super(MoxyJsonFeature.class);
}
}

@Nested
public static class JacksonFeatureProjectsResourceTest extends ProjectsResourceTemplateTest {
public JacksonFeatureProjectsResourceTest() {
super(JacksonFeature.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

package org.glassfish.jersey.examples.entityfiltering;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import javax.ws.rs.core.Feature;
Expand All @@ -22,7 +25,10 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.glassfish.jersey.test.spi.TestHelper;
import org.junit.jupiter.api.DynamicContainer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
Expand All @@ -35,6 +41,20 @@
*/
public class TaskResourceTest {

public static Iterable<Class<? extends Feature>> providers() {
return Arrays.asList(MoxyJsonFeature.class, JacksonFeature.class);
}

@TestFactory
public Collection<DynamicContainer> generateTests() {
Collection<DynamicContainer> tests = new ArrayList<>();
providers().forEach(feature -> {
TaskResourceTemplateTest test = new TaskResourceTemplateTest(feature) {};
tests.add(TestHelper.toTestContainer(test, feature.getSimpleName()));
});
return tests;
}

public abstract static class TaskResourceTemplateTest extends JerseyTest {
public TaskResourceTemplateTest(final Class<? extends Feature> filteringProvider) {
super(new ResourceConfig(EntityFilteringFeature.class)
Expand Down Expand Up @@ -85,16 +105,4 @@ private void testTask(final Task task, final boolean isDetailed) {
}
}
}

public static class MoxyJsonFeatureTaskResourceTest extends TaskResourceTemplateTest {
public MoxyJsonFeatureTaskResourceTest() {
super(MoxyJsonFeature.class);
}
}

public static class JacksonFeatureTaskResourceTest extends TaskResourceTemplateTest {
public JacksonFeatureTaskResourceTest() {
super(JacksonFeature.class);
}
}
}
7 changes: 7 additions & 0 deletions examples/extended-wadl-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@
<forkMode>always</forkMode>
<enableAssertions>false</enableAssertions>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.ops4j.pax.exam</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ public static void after() throws Exception {
weld.shutdown();
}

@Override
@AfterAll
public void tearDown() throws Exception {
super.tearDown();
System.out.printf("SYNC: %d, ASYNC: %d, STRAIGHT: %d%n",
parameterizedCounter.intValue(), parameterizedAsyncCounter.intValue(), straightCounter.intValue());
}

@Override
protected ResourceConfig configure() {
// enable(TestProperties.LOG_TRAFFIC);
Expand Down
7 changes: 7 additions & 0 deletions ext/metainf-services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<test>**/MetaInfServicesTest*</test>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.glassfish.jersey.test;

import java.lang.annotation.Annotation;
import java.net.URI;
import java.security.AccessController;
import java.util.ArrayList;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;

/**
* Parent class for testing JAX-RS and Jersey-based applications using Jersey test framework.
Expand Down Expand Up @@ -616,7 +618,7 @@ public final Client client() {
@BeforeEach
public void setUp() throws Exception {
synchronized (this) {
if (activeThreadCount.getAndIncrement() == 0) {
if (!isConcurrent() || activeThreadCount.getAndIncrement() == 0) {
registerLogHandlerIfEnabled();
final TestContainer testContainer = createTestContainer(context);

Expand All @@ -630,6 +632,24 @@ public void setUp() throws Exception {
}
}

/**
* Do not setup multiple containers for concurrent junit 5 environment not to hit Address already in use exception
* @return true when TestInstance.Lifecycle.PER_CLASS annotation is used and the test run in concurrent
*/
private boolean isConcurrent() {
Annotation[] annotations = this.getClass().getAnnotations();
for (Annotation annotation : annotations) {
// check the name first for JUnit 4 only environment
if (annotation.annotationType().getName().equals("org.junit.jupiter.api.TestInstance")) {
TestInstance testInstance = (TestInstance) annotation;
if (testInstance != null && testInstance.value() == TestInstance.Lifecycle.PER_CLASS) {
return true;
}
}
}
return false;
}

/**
* Tear down the test by {@link TestContainer#stop() stopping} the test container obtained from the
* {@link #getTestContainerFactory() test container factory} and by {@link javax.ws.rs.client.Client#close() closing}
Expand All @@ -642,7 +662,7 @@ public void setUp() throws Exception {
@AfterEach
public void tearDown() throws Exception {
synchronized (this) {
if (activeThreadCount.decrementAndGet() == 0) {
if (!isConcurrent() || activeThreadCount.decrementAndGet() == 0) {
if (isLogRecordingEnabled()) {
unregisterLogHandler();
}
Expand Down
Loading

0 comments on commit f7d85d6

Please sign in to comment.