Skip to content

Commit

Permalink
Test Framework container provider (Helidon 4.x)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <[email protected]>
  • Loading branch information
senivam committed Jun 13, 2024
1 parent b3bac21 commit ebebcbc
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 11 deletions.
9 changes: 5 additions & 4 deletions containers/helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<version>3.1.99-SNAPSHOT</version>
</parent>

<artifactId>jersey-container-helidon</artifactId>
<artifactId>jersey-container-helidon-http</artifactId>
<packaging>jar</packaging>
<name>jersey-container-helidon</name>

Expand All @@ -47,21 +47,22 @@
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>4.0.9</version>
<version>${helidon.container.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
<version>4.0.9</version>
<version>${helidon.container.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.http</groupId>
<artifactId>helidon-http</artifactId>
<version>4.0.9</version>
<version>${helidon.container.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,31 @@
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spi.Container;

import java.net.URI;

public class HelidonHttpContainer implements Container, WebServer {

private static final int DEFAULT_PORT = 8080;
private static final String DEFAULT_HOST = "0.0.0.0";

private final WebServer webServer;

private ApplicationHandler applicationHandler;

HelidonHttpContainer(Application application) {
HelidonHttpContainer(URI baseUri, Application application) {
this.applicationHandler = new ApplicationHandler(application, new WebServerBinder());
this.webServer = WebServer.builder().port(8080).routing(
HttpRouting.builder().register(
JerseySupport.create(this)
)).build();
int port = baseUri == null ? DEFAULT_PORT : baseUri.getPort();
final String host = baseUri == null ? DEFAULT_HOST : baseUri.getHost();
final String path = baseUri == null ? null : baseUri.getPath();
final HttpRouting.Builder routingBuilder = path == null ? HttpRouting.builder().register(
JerseySupport.create(this)
) : HttpRouting.builder().register(path,
JerseySupport.create(this)
);
this.webServer = WebServer.builder()
.port(port)
.host(host)
.routing(routingBuilder).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (c) 2024 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.helidon;

import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.UriBuilder;

import java.net.URI;

/**
* Helidon container builder
*/
class HelidonHttpContainerBuilder {

private URI baseUri;

private Application application;

private String host;

private String path;

private int port;

private HelidonHttpContainerBuilder() {
}



public static HelidonHttpContainerBuilder builder() {
return new HelidonHttpContainerBuilder();
}

public HelidonHttpContainerBuilder withUri(URI baseUri) {
this.baseUri = baseUri;
return this;
}

public HelidonHttpContainerBuilder withApplication(Application application) {
this.application = application;
return this;
}

public HelidonHttpContainerBuilder withPort(int port) {
this.port = port;
return this;
}

public HelidonHttpContainerBuilder withHost(String host) {
this.host = host;
return this;
}

public HelidonHttpContainerBuilder withPath(String path) {
this.path = path;
return this;
}

public HelidonHttpContainer build() {
if (this.baseUri == null) {
baseUri = UriBuilder.fromPath(path).port(port).host(host).build();
}
return new HelidonHttpContainer(baseUri, application);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ private HelidonHttpContainerFactory() {
}

public static WebServer createServer(URI baseUri, ResourceConfig config) {
return new HelidonHttpContainer(config);
return new HelidonHttpContainer(baseUri, config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public <T> T createContainer(Class<T> type, Application application) throws Proc
if (type != WebServer.class && type != HelidonHttpContainer.class) {
return null;
}
return type.cast(new HelidonHttpContainer(application));
return type.cast(new HelidonHttpContainer(null, application));
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2152,6 +2152,7 @@
<microprofile.config.version>3.0.3</microprofile.config.version>
<microprofile.rest.client.version>3.0.1</microprofile.rest.client.version>
<helidon.config.version>3.2.6</helidon.config.version>
<helidon.container.version>4.0.10</helidon.container.version>
<helidon.jersey.connector.version>3.2.6</helidon.jersey.connector.version>
<helidon.config.11.version>1.4.14</helidon.config.11.version> <!-- JDK 11- support -->
<smallrye.config.version>3.7.1</smallrye.config.version>
Expand Down
48 changes: 48 additions & 0 deletions test-framework/providers/helidon-http/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 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
-->

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>project</artifactId>
<version>3.1.99-SNAPSHOT</version>
</parent>

<artifactId>jersey-test-framework-provider-helidon</artifactId>
<packaging>jar</packaging>
<name>jersey-test-framework-provider-helidon</name>

<description>Jersey Test Framework - Helidon (4.x) container</description>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-helidon-http</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2024 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.test.helidon;

import io.helidon.webserver.WebServer;
import jakarta.ws.rs.core.UriBuilder;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.helidon.HelidonHttpContainerFactory;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.spi.TestContainer;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.glassfish.jersey.test.spi.TestHelper;

import javax.net.ssl.SSLParameters;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;

public class HelidonTestContainerFactory implements TestContainerFactory {

private static class HelidonTestContainer implements TestContainer {

private static final Logger LOGGER = Logger.getLogger(HelidonTestContainer.class.getName());

private URI baseUri;

private final WebServer server;

private HelidonTestContainer(final URI baseUri, final DeploymentContext context) {
this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build();

if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info("Creating HelidonTestContainer configured at the base URI "
+ TestHelper.zeroPortToAvailablePort(baseUri));
}

if (context.getSslContext().isPresent() && context.getSslParameters().isPresent()) {
final SSLParameters sslParameters = context.getSslParameters().get();
this.server = HelidonHttpContainerFactory.createServer(
this.baseUri, context.getResourceConfig());
} else {
this.server = HelidonHttpContainerFactory.createServer(this.baseUri, context.getResourceConfig());
}
}

@Override
public ClientConfig getClientConfig() {
return null;
}

@Override
public URI getBaseUri() {
return baseUri;
}

@Override
public void start() {
if (!server.isRunning()) {
server.start();
}
}

@Override
public void stop() {
if (server.isRunning()) {
server.stop();
}
}
}
@Override
public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
return new HelidonTestContainer(baseUri, deploymentContext);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 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
*
*/

/**
* Test Framework Jersey container provider based on Helidon 4.x.
*/

package org.glassfish.jersey.test.helidon;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.glassfish.jersey.test.helidon.HelidonTestContainerFactory
Loading

0 comments on commit ebebcbc

Please sign in to comment.