From 8dda218207094437400c98e358fee0f42e6aaea0 Mon Sep 17 00:00:00 2001 From: Jan Supol Date: Fri, 3 May 2019 20:22:27 +0200 Subject: [PATCH] Separate tests using jmockit from jersey core Signed-off-by: Jan Supol --- core-common/pom.xml | 5 - core-server/pom.xml | 5 - .../jersey/server/ResourceConfigTest.java | 53 +---- ext/cdi/jersey-cdi1x/pom.xml | 13 ++ media/multipart/pom.xml | 6 +- .../FormDataMultiPartReaderWriterTest.java | 89 +------- pom.xml | 1 - tests/jmockit/pom.xml | 81 +++++++ .../server/innerstatic/InnerStaticClass.java | 62 ++++++ .../toplevel/PackageRootResourceClass.java | 32 +++ .../toplevel/PublicRootResourceClass.java | 32 +++ .../PublicRootResourceInnerStaticClass.java | 41 ++++ .../FormDataMultiPartReaderWriterTest.java | 205 ++++++++++++++++++ .../jmockit/server/ResourceConfigTest.java | 79 +++++++ .../scanning/PackageNamesScannerTest.java | 4 +- tests/pom.xml | 1 + 16 files changed, 552 insertions(+), 157 deletions(-) create mode 100644 tests/jmockit/pom.xml create mode 100644 tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/innerstatic/InnerStaticClass.java create mode 100644 tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PackageRootResourceClass.java create mode 100644 tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PublicRootResourceClass.java create mode 100644 tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevelinnerstatic/PublicRootResourceInnerStaticClass.java create mode 100644 tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/media/multipart/internal/FormDataMultiPartReaderWriterTest.java create mode 100644 tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/ResourceConfigTest.java rename {core-server/src/test/java/org/glassfish/jersey => tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit}/server/internal/scanning/PackageNamesScannerTest.java (96%) diff --git a/core-common/pom.xml b/core-common/pom.xml index 8185bd8ccd..c30b536d89 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -189,11 +189,6 @@ osgi-resource-locator - - - org.jmockit - jmockit - junit junit diff --git a/core-server/pom.xml b/core-server/pom.xml index 3069a25592..be40b6ee02 100644 --- a/core-server/pom.xml +++ b/core-server/pom.xml @@ -199,11 +199,6 @@ provided - - org.jmockit - jmockit - test - junit junit diff --git a/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java b/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java index 4f4ee99711..6ba596d34f 100644 --- a/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java +++ b/core-server/src/test/java/org/glassfish/jersey/server/ResourceConfigTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -33,7 +33,6 @@ import org.glassfish.jersey.server.config.innerstatic.InnerStaticClass; import org.glassfish.jersey.server.config.toplevel.PublicRootResourceClass; import org.glassfish.jersey.server.config.toplevelinnerstatic.PublicRootResourceInnerStaticClass; -import org.glassfish.jersey.server.internal.scanning.PackageNamesScanner; import org.junit.Test; import static org.glassfish.jersey.server.JarUtils.createJarFile; @@ -45,9 +44,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import mockit.Mocked; -import mockit.Verifications; - /** * @author Pavel Bucek (pavel.bucek at oracle.com) */ @@ -350,53 +346,6 @@ public void testGetClasses() throws Exception { assertThat(classes, hasItem(InnerStaticClass.PublicClass.class)); } - /** - * Reproducer for OWLS-19790: Invalidate resource finders in resource config only when needed. - */ - @Test - public void testInvalidateResourceFinders(@Mocked final PackageNamesScanner scanner) throws Exception { - final ResourceConfig resourceConfig = new ResourceConfig() - .packages(false, PublicRootResourceClass.class.getPackage().getName()); - - // Scan packages. - resourceConfig.getClasses(); - - // No reset. - new Verifications() {{ - scanner.reset(); - times = 0; - }}; - - resourceConfig.register(InnerStaticClass.PublicClass.class); - - // Reset - we called getClasses() on ResourceConfig. - new Verifications() {{ - scanner.reset(); - times = 1; - }}; - - // No reset. - resourceConfig.register(PublicRootResourceClass.class); - resourceConfig.register(PublicRootResourceInnerStaticClass.PublicClass.class); - - // No reset - simple registering does not invoke cache invalidation and reset of resource finders. - new Verifications() {{ - scanner.reset(); - times = 1; - }}; - - // Scan packages. - resourceConfig.getClasses(); - - resourceConfig.registerFinder(new PackageNamesScanner(new String[] {"javax.ws.rs"}, false)); - - // Reset - we called getClasses() on ResourceConfig. - new Verifications() {{ - scanner.reset(); - times = 2; - }}; - } - @Test public void testResourceFinderStreamsClosed() throws IOException { System.out.println(new ResourceConfig().packages("javax.ws.rs").getClasses()); diff --git a/ext/cdi/jersey-cdi1x/pom.xml b/ext/cdi/jersey-cdi1x/pom.xml index 99463ff18f..0966ce7e57 100644 --- a/ext/cdi/jersey-cdi1x/pom.xml +++ b/ext/cdi/jersey-cdi1x/pom.xml @@ -87,6 +87,19 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + + -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar + -Xmx${surefire.maxmem.argline}m -Dfile.encoding=UTF8 ${surefire.security.argline} + ${surefire.coverage.argline} + + ${skip.tests} + + diff --git a/media/multipart/pom.xml b/media/multipart/pom.xml index befc434ee4..b3b9c315e6 100644 --- a/media/multipart/pom.xml +++ b/media/multipart/pom.xml @@ -1,7 +1,7 @@ - -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar -Xmx${surefire.maxmem.argline}m -Dfile.encoding=UTF8 ${surefire.security.argline} ${surefire.coverage.argline} ${skip.tests} diff --git a/tests/jmockit/pom.xml b/tests/jmockit/pom.xml new file mode 100644 index 0000000000..1503446175 --- /dev/null +++ b/tests/jmockit/pom.xml @@ -0,0 +1,81 @@ + + + + project + org.glassfish.jersey.tests + 2.29-SNAPSHOT + + 4.0.0 + + jersey-tests-jmockit + + + + org.glassfish.jersey.core + jersey-common + ${project.version} + + + org.glassfish.jersey.core + jersey-server + ${project.version} + + + org.glassfish.jersey.media + jersey-media-multipart + ${project.version} + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-bundle + ${project.version} + pom + test + + + + org.jmockit + jmockit + test + + + junit + junit + test + + + org.hamcrest + hamcrest-library + test + + + org.glassfish.jersey.media + jersey-media-multipart + test + + + org.glassfish.jersey.test-framework + jersey-test-framework-core + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + -javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar + -Xmx${surefire.maxmem.argline}m -Dfile.encoding=UTF8 ${surefire.security.argline} + ${surefire.coverage.argline} + + ${skip.tests} + + + + + \ No newline at end of file diff --git a/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/innerstatic/InnerStaticClass.java b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/innerstatic/InnerStaticClass.java new file mode 100644 index 0000000000..26d2d3c180 --- /dev/null +++ b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/innerstatic/InnerStaticClass.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.server.innerstatic; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * @author Paul Sandoz + */ +public class InnerStaticClass { + + @Path("/") + public static class PublicClass { + + @GET + public String getMe() { + return "ME"; + } + } + + @Path("/") + private static class PrivateClass { + + @GET + public String getMe() { + return "ME"; + } + } + + @Path("/") + protected static class ProtectedClass { + + @GET + public String getMe() { + return "ME"; + } + } + + @Path("/") + /* package */ static class PackageClass { + + @GET + public String getMe() { + return "ME"; + } + } +} diff --git a/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PackageRootResourceClass.java b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PackageRootResourceClass.java new file mode 100644 index 0000000000..ffb778e689 --- /dev/null +++ b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PackageRootResourceClass.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.server.toplevel; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * @author Paul Sandoz + */ +@Path("/") +/* package */ class PackageRootResourceClass { + + @GET + public String getMe() { + return "ME"; + } +} diff --git a/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PublicRootResourceClass.java b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PublicRootResourceClass.java new file mode 100644 index 0000000000..0fb023829f --- /dev/null +++ b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevel/PublicRootResourceClass.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.server.toplevel; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * @author Paul Sandoz + */ +@Path("/") +public class PublicRootResourceClass { + + @GET + public String getMe() { + return "ME"; + } +} diff --git a/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevelinnerstatic/PublicRootResourceInnerStaticClass.java b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevelinnerstatic/PublicRootResourceInnerStaticClass.java new file mode 100644 index 0000000000..191578bfbd --- /dev/null +++ b/tests/jmockit/src/main/java/org/glassfish/jersey/tests/jmockit/server/toplevelinnerstatic/PublicRootResourceInnerStaticClass.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.server.toplevelinnerstatic; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * @author Paul Sandoz + */ +@Path("/") +public class PublicRootResourceInnerStaticClass { + + @GET + public String getMe() { + return "ME"; + } + + @Path("/") + public static class PublicClass { + + @GET + public String getMe() { + return "ME"; + } + } +} diff --git a/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/media/multipart/internal/FormDataMultiPartReaderWriterTest.java b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/media/multipart/internal/FormDataMultiPartReaderWriterTest.java new file mode 100644 index 0000000000..3c99d0089f --- /dev/null +++ b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/media/multipart/internal/FormDataMultiPartReaderWriterTest.java @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.media.multipart.internal; + +import mockit.Expectations; +import mockit.Mocked; +import mockit.Verifications; +import org.glassfish.jersey.media.multipart.BodyPartEntity; +import org.glassfish.jersey.media.multipart.FormDataBodyPart; +import org.glassfish.jersey.media.multipart.FormDataContentDisposition; +import org.glassfish.jersey.media.multipart.FormDataMultiPart; +import org.glassfish.jersey.media.multipart.FormDataParam; +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; +import org.jvnet.mimepull.MIMEMessage; +import org.jvnet.mimepull.MIMEParsingException; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.File; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +/** + * Tests for multipart {@code MessageBodyReader} and {@code MessageBodyWriter} as well as {@code FormDataMultiPart} and {@code + * FormDataParam} injections. + * + * @author Paul Sandoz + * @author Michal Gajdos + */ +public class FormDataMultiPartReaderWriterTest extends JerseyTest { + + @Override + protected Application configure() { + return new ResourceConfig() + .register(MediaTypeWithBoundaryResource.class) + .register(FileResource.class) + .register(new MultiPartFeature()); + } + + @Path("/MediaTypeWithBoundaryResource") + public static class MediaTypeWithBoundaryResource { + + @PUT + @Consumes("multipart/form-data") + @Produces("text/plain") + public String get( + @Context final HttpHeaders h, + @FormDataParam("submit") final String s) { + final String b = h.getMediaType().getParameters().get("boundary"); + assertEquals("XXXX_YYYY", b); + return s; + } + + } + + + @Path("/FileResource") + @Consumes("multipart/form-data") + @Produces("text/plain") + public static class FileResource { + + @POST + @Path("InjectedFileNotCopied") + public String injectedFileNotCopied(@FormDataParam("file") final File file) { + final String path = file.getAbsolutePath(); + //noinspection ResultOfMethodCallIgnored + file.delete(); + return path; + } + + @POST + @Path("ExceptionInMethod") + public String exceptionInMethod(@FormDataParam("file") final File file) { + throw new WebApplicationException(Response.serverError().entity(file.getAbsolutePath()).build()); + } + + @POST + @Path("SuccessfulMethod") + public String successfulMethod(@FormDataParam("file") final File file) { + return file.getAbsolutePath(); + } + + @POST + @Path("FileSize") + public long fileSize(@FormDataParam("file") final File file) { + return file.length(); + } + } + + /** + * JERSEY-2663 reproducer. Make sure that temporary file created by MIMEPull is not copied into new temporary file created + * by Jersey. + */ + @Test + public void testInjectedFileNotCopied(@Mocked final BodyPartEntity entity) throws Exception { + final FormDataMultiPart multipart = new FormDataMultiPart(); + final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), + "CONTENT"); + multipart.bodyPart(bodypart); + + final Response response = target().path("FileResource").path("InjectedFileNotCopied") + .register(MultiPartFeature.class) + .request() + .post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA)); + + // Make sure that the Mimepull temp file has been moved to specific file. + new Verifications() {{ + entity.moveTo(withInstanceOf(File.class)); + times = 1; + }}; + + // Make sure that the temp file has been removed. + final String pathname = response.readEntity(String.class); + // Wait a second to make sure the file doesn't exist. + Thread.sleep(1000); + + assertThat("Temporary file, " + pathname + ", on the server has not been removed", + new File(pathname).exists(), is(false)); + } + + /** + * Mocked JERSEY-2794 reproducer. Real test is under integration tests. + */ + @Test + public void mimeTempFileRemovedAfterAbortedUpload(@Mocked final MIMEMessage message) throws Exception { + new Expectations() {{ + message.getAttachments(); + result = new MIMEParsingException(); + }}; + + final URL url = new URL(getBaseUri().toString() + "MediaTypeWithBoundaryResource"); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + + connection.setRequestMethod("PUT"); + connection.setRequestProperty("Accept", "text/plain"); + connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=XXXX_YYYY"); + + connection.setDoOutput(true); + connection.connect(); + + final OutputStream outputStream = connection.getOutputStream(); + outputStream.write("--XXXX_YYYY".getBytes()); + outputStream.write('\n'); + outputStream.write("Content-Type: text/plain".getBytes()); + outputStream.write('\n'); + outputStream.write("Content-Disposition: form-data; name=\"big-part\"".getBytes()); + outputStream.write('\n'); + outputStream.write('\n'); + + // Send big chunk of data. + for (int i = 0; i < 16 * 4096; i++) { + outputStream.write('E'); + if (i % 1024 == 0) { + outputStream.flush(); + } + } + + // Do NOT send end of the MultiPart message to simulate the issue. + + // Get Response ... + final int response = connection.getResponseCode(); + // ... Disconnect. + connection.disconnect(); + + assertThat("Bad Request expected", response, is(400)); + + // Make sure that the Mimepull message and it's parts have been closed and temporary files deleted. + new Verifications() {{ + message.close(); + times = 1; + }}; + } +} diff --git a/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/ResourceConfigTest.java b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/ResourceConfigTest.java new file mode 100644 index 0000000000..0caf3cad5d --- /dev/null +++ b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/ResourceConfigTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.jmockit.server; + +import mockit.Mocked; +import mockit.Verifications; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.server.internal.scanning.PackageNamesScanner; +import org.glassfish.jersey.tests.jmockit.server.innerstatic.InnerStaticClass; +import org.glassfish.jersey.tests.jmockit.server.toplevel.PublicRootResourceClass; +import org.glassfish.jersey.tests.jmockit.server.toplevelinnerstatic.PublicRootResourceInnerStaticClass; +import org.junit.Test; + +/** + * @author Pavel Bucek (pavel.bucek at oracle.com) + */ +public class ResourceConfigTest { + + /** + * Reproducer for OWLS-19790: Invalidate resource finders in resource config only when needed. + */ + @Test + public void testInvalidateResourceFinders(@Mocked final PackageNamesScanner scanner) throws Exception { + final ResourceConfig resourceConfig = new ResourceConfig() + .packages(false, PublicRootResourceClass.class.getPackage().getName()); + + // Scan packages. + resourceConfig.getClasses(); + + // No reset. + new Verifications() {{ + scanner.reset(); + times = 0; + }}; + + resourceConfig.register(InnerStaticClass.PublicClass.class); + + // Reset - we called getClasses() on ResourceConfig. + new Verifications() {{ + scanner.reset(); + times = 1; + }}; + + // No reset. + resourceConfig.register(PublicRootResourceClass.class); + resourceConfig.register(PublicRootResourceInnerStaticClass.PublicClass.class); + + // No reset - simple registering does not invoke cache invalidation and reset of resource finders. + new Verifications() {{ + scanner.reset(); + times = 1; + }}; + + // Scan packages. + resourceConfig.getClasses(); + + resourceConfig.registerFinder(new PackageNamesScanner(new String[] {"javax.ws.rs"}, false)); + + // Reset - we called getClasses() on ResourceConfig. + new Verifications() {{ + scanner.reset(); + times = 2; + }}; + } +} diff --git a/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/internal/scanning/PackageNamesScannerTest.java similarity index 96% rename from core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java rename to tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/internal/scanning/PackageNamesScannerTest.java index b7d1907be4..f8f56684e8 100644 --- a/core-server/src/test/java/org/glassfish/jersey/server/internal/scanning/PackageNamesScannerTest.java +++ b/tests/jmockit/src/test/java/org/glassfish/jersey/tests/jmockit/server/internal/scanning/PackageNamesScannerTest.java @@ -14,12 +14,14 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.jersey.server.internal.scanning; +package org.glassfish.jersey.tests.jmockit.server.internal.scanning; import mockit.Expectations; import mockit.Injectable; import mockit.Tested; import mockit.Verifications; +import org.glassfish.jersey.server.internal.scanning.PackageNamesScanner; +import org.glassfish.jersey.server.internal.scanning.ResourceFinderException; import org.junit.Before; import org.junit.Test; diff --git a/tests/pom.xml b/tests/pom.xml index 589b811140..bbc162cc8e 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -45,6 +45,7 @@ e2e-server e2e-testng integration + jmockit mem-leaks osgi stress