Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate tests using jmockit from jersey core #4125

Merged
merged 1 commit into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions core-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@
<artifactId>osgi-resource-locator</artifactId>
</dependency>

<dependency>
<!-- Must be declared before JUnit dependency, otherwise not visible to JUnit. -->
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions core-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
*/
Expand Down Expand Up @@ -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());
Expand Down
13 changes: 13 additions & 0 deletions ext/cdi/jersey-cdi1x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- for convenience reasons, 'argLine' should not be overridden in child poms. if needed, a property should be declared and used here -->
<argLine>
-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}
</argLine>
<skipTests>${skip.tests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
6 changes: 1 addition & 5 deletions media/multipart/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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
Expand Down Expand Up @@ -99,10 +99,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -69,10 +69,6 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import mockit.Expectations;
import mockit.Mocked;
import mockit.Verifications;

/**
* Tests for multipart {@code MessageBodyReader} and {@code MessageBodyWriter} as well as {@code FormDataMultiPart} and {@code
* FormDataParam} injections.
Expand Down Expand Up @@ -666,36 +662,6 @@ public long fileSize(@FormDataParam("file") final File file) {
}
}

/**
* 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")
.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));
}

/**
* JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after a successful request.
*/
Expand Down Expand Up @@ -772,59 +738,6 @@ public String put(@FormDataParam("submit") final InputStream stream) {
}
}

/**
* 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;
}};
}

private void checkEntity(final String expected, final BodyPartEntity entity) throws IOException {
// Convert the raw bytes into a String
final InputStreamReader sr = new InputStreamReader(entity.getInputStream());
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@
<configuration>
<!-- for convenience reasons, 'argLine' should not be overridden in child poms. if needed, a property should be declared and used here -->
<argLine>
-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}
</argLine>
<skipTests>${skip.tests}</skipTests>
Expand Down
81 changes: 81 additions & 0 deletions tests/jmockit/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>project</artifactId>
<groupId>org.glassfish.jersey.tests</groupId>
<version>2.29-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jersey-tests-jmockit</artifactId>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- for convenience reasons, 'argLine' should not be overridden in child poms. if needed, a property should be declared and used here -->
<argLine>
-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}
</argLine>
<skipTests>${skip.tests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading