Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Oct 12, 2022
1 parent 65734d2 commit a7b803e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 73 deletions.
5 changes: 5 additions & 0 deletions examples/http-patch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022 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 @@ -46,6 +46,7 @@
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.RequestEntityProcessing;
import org.glassfish.jersey.internal.guava.SettableFuture;
import org.glassfish.jersey.message.internal.ReaderWriter;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
Expand All @@ -57,8 +58,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.google.common.util.concurrent.SettableFuture;

/**
* Reproducer for JERSEY-2705. Client side entity InputStream exception
* in chunked mode should not lead to the same behavior on the server side,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import com.google.common.io.ByteStreams;

/**
* SSL connector hostname verification tests.
*
Expand Down Expand Up @@ -95,14 +93,15 @@ public void tearDown() throws Exception {
}

protected SSLContext getSslContext() throws IOException {
final InputStream trustStore = SslConnectorConfigurationTest.class.getResourceAsStream(clientTrustStore());
final InputStream keyStore = SslConnectorConfigurationTest.class.getResourceAsStream(CLIENT_KEY_STORE);
return SslConfigurator.newInstance()
.trustStoreBytes(ByteStreams.toByteArray(trustStore))
.trustStorePassword("asdfgh")
.keyStoreBytes(ByteStreams.toByteArray(keyStore))
.keyPassword("asdfgh")
.createSSLContext();
try (InputStream trustStore = SslConnectorConfigurationTest.class.getResourceAsStream(clientTrustStore());
InputStream keyStore = SslConnectorConfigurationTest.class.getResourceAsStream(CLIENT_KEY_STORE);) {
return SslConfigurator.newInstance()
.trustStoreBytes(trustStore.readAllBytes())
.trustStorePassword("asdfgh")
.keyStoreBytes(keyStore.readAllBytes())
.keyPassword("asdfgh")
.createSSLContext();
}
}

protected String serverKeyStore() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 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 @@ -31,8 +31,6 @@
import org.glassfish.grizzly.ssl.SSLContextConfigurator;
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;

import com.google.common.io.ByteStreams;

/**
* A simple SSL-secured HTTP server for testing purposes.
*
Expand Down Expand Up @@ -80,34 +78,34 @@ private static int getPort(int defaultPort) {
* @return an instance of the started SSL-secured HTTP test server.
*/
public static Server start(String keystore) throws IOException {
final InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
final InputStream keyStore = Server.class.getResourceAsStream(keystore);

// Grizzly ssl configuration
SSLContextConfigurator sslContext = new SSLContextConfigurator();

// set up security context
sslContext.setKeyStoreBytes(ByteStreams.toByteArray(keyStore)); // contains server key pair
sslContext.setKeyStorePass("asdfgh");
sslContext.setTrustStoreBytes(ByteStreams.toByteArray(trustStore)); // contains client certificate
sslContext.setTrustStorePass("asdfgh");

ResourceConfig rc = new ResourceConfig();
rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);

final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(
getBaseURI(),
rc,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true)
);

// start Grizzly embedded server //
LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
grizzlyServer.start();

return new Server(grizzlyServer);
try (InputStream trustStore = Server.class.getResourceAsStream(SERVER_TRUST_STORE);
InputStream keyStore = Server.class.getResourceAsStream(keystore);) {
// Grizzly ssl configuration
SSLContextConfigurator sslContext = new SSLContextConfigurator();

// set up security context
sslContext.setKeyStoreBytes(keyStore.readAllBytes()); // contains server key pair
sslContext.setKeyStorePass("asdfgh");
sslContext.setTrustStoreBytes(trustStore.readAllBytes()); // contains client certificate
sslContext.setTrustStorePass("asdfgh");

ResourceConfig rc = new ResourceConfig();
rc.register(new LoggingFeature(LOGGER, LoggingFeature.Verbosity.PAYLOAD_ANY));
rc.registerClasses(RootResource.class, SecurityFilter.class, AuthenticationExceptionMapper.class);

final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(
getBaseURI(),
rc,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true)
);

// start Grizzly embedded server //
LOGGER.info("Jersey app started. Try out " + BASE_URI + "\nHit CTRL + C to stop it...");
grizzlyServer.start();

return new Server(grizzlyServer);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022 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 All @@ -22,6 +22,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Map;

import javax.ws.rs.BeanParam;
import javax.ws.rs.CookieParam;
Expand All @@ -37,7 +38,6 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
Expand All @@ -47,22 +47,19 @@
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.glassfish.jersey.internal.util.SimpleNamespaceResolver;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.ElementNameAndTextQualifier;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.glassfish.jersey.internal.util.SimpleNamespaceResolver;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.google.common.collect.ImmutableMap;

/**
* Tests whether WADL for a {@link BeanParam} annotated resource method parameter is generated properly.
* <p/>
Expand Down Expand Up @@ -168,7 +165,7 @@ private void testBeanParamConstructorInitializedBean(String resource) throws Exc
XPathConstants.NODE))
);
XMLUnit.setXpathNamespaceContext(
new SimpleNamespaceContext(ImmutableMap.of("wadl", "http://wadl.dev.java.net/2009/02")));
new SimpleNamespaceContext(Map.of("wadl", "http://wadl.dev.java.net/2009/02")));
diff.overrideElementQualifier(elementQualifier);
XMLAssert.assertXMLEqual(diff, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022 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 All @@ -16,6 +16,13 @@

package org.glassfish.jersey.tests.e2e.server.wadl;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -33,6 +40,7 @@
import java.util.Properties;
import java.util.concurrent.ExecutionException;

import javax.inject.Named;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
Expand All @@ -52,8 +60,6 @@
import javax.ws.rs.core.Form;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import javax.inject.Named;
import javax.xml.XMLConstants;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.parsers.DocumentBuilder;
Expand All @@ -71,6 +77,12 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.ElementQualifier;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
import org.glassfish.jersey.internal.MapPropertiesDelegate;
import org.glassfish.jersey.internal.util.SaxHelper;
import org.glassfish.jersey.internal.util.SimpleNamespaceResolver;
Expand All @@ -89,13 +101,6 @@
import org.glassfish.jersey.server.wadl.internal.WadlUtils;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;

import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.ElementQualifier;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -105,14 +110,6 @@
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import com.google.common.collect.ImmutableMap;

import com.sun.research.ws.wadl.Method;
import com.sun.research.ws.wadl.Param;
Expand Down Expand Up @@ -1279,7 +1276,7 @@ public void testWadlIsSameForAnnotatedAndNot() throws Exception {
XPathConstants.NODE))
);
XMLUnit.setXpathNamespaceContext(
new SimpleNamespaceContext(ImmutableMap.of("wadl", "http://wadl.dev.java.net/2009/02")));
new SimpleNamespaceContext(Map.of("wadl", "http://wadl.dev.java.net/2009/02")));
final ElementQualifier elementQualifier = new RecursiveElementNameAndTextQualifier();
diff.overrideElementQualifier(elementQualifier);
XMLAssert.assertXMLEqual(diff, true);
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/microprofile/rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>1.4.1.Final</version>
<version>1.7.0.Alpha12</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit a7b803e

Please sign in to comment.