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

Multiple test modules #488

Merged
merged 6 commits into from
Aug 18, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
run: ./mvnw -B formatter:validate install --file pom.xml

- name: Build - Native
run: ./mvnw -B verify -Pnative -Dquarkus.native.container-build=true --file integration-tests/pom.xml
run: cd integration-tests && ../mvnw -B verify -Pnative -Dquarkus.native.container-build=true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Why not -f integration-tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd tends to be safer for some buggy plugins (e.g. assuming that Paths.get(".") always returns ${basedir}). Maybe we do not have any such here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't but in the end I don't mind cd.


96 changes: 96 additions & 0 deletions integration-tests/basic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf-integration-tests</artifactId>
<version>1.5.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>quarkus-cxf-integration-test-basic</artifactId>

<name>Quarkus CXF Extension - Integration Test - Basic</name>

<dependencies>
<dependency>
<groupId>io.quarkiverse.cxf</groupId>
<artifactId>quarkus-cxf</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<!-- provides CXF logging feature -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-features-logging</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.report-errors-at-runtime>true</quarkus.native.report-errors-at-runtime>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class GreetingWebServiceImpl implements GreetingWebService {

@Inject
public HelloResource helloResource;
HelloBean helloResource;

@Override
public String reply(@WebParam(name = "text") String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class GreetingWebServiceNoIntf {

@Inject
public HelloResource helloResource;
HelloBean helloResource;

public String reply(@WebParam(name = "text") String text) {
return helloResource.getHello() + text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import javax.inject.Singleton;

/**
* A simple bean for testing whether injecting into service implementation works.
*/
@Singleton
public class HelloResource {
public class HelloBean {
public String getHello() {
return "Hello ";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,3 @@ quarkus.cxf.client."greeting-with-log".features=org.apache.cxf.ext.logging.Loggi
quarkus.cxf.client."greetingclient".client-endpoint-url=http://localhost:8081/soap/greeting
quarkus.cxf.client."greetingclient".service-interface=io.quarkiverse.it.cxf.GreetingClientWebService

# A "featured" client to service "/soap/greeting" (see above), use it like
#
# @Inject @CXFClient(config="featured-foo") GreetingClientWebService myclient;
#
quarkus.cxf.client."greetingclient-fault".client-endpoint-url=http://localhost:8081/soap/greeting
quarkus.cxf.client."greetingclient-fault".out-interceptors=io.quarkiverse.it.cxf.SOAPExceptionInterceptor

quarkus.cxf.client."mockCalculator".wsdl=http://localhost:9000/mockCalculator?wsdl
quarkus.cxf.client."mockCalculator".client-endpoint-url=http://localhost:9000/mockCalculator
quarkus.cxf.client."mockCalculator".service-interface=org.tempuri.CalculatorSoap
quarkus.cxf.client."mockCalculator".endpoint-namespace=http://tempuri.org/
quarkus.cxf.client."mockCalculator".endpoint-name=CalculatorSoap

quarkus.cxf.client."mockAltCalculator".wsdl=http://localhost:9000/mockAltCalculator?wsdl
quarkus.cxf.client."mockAltCalculator".client-endpoint-url=http://localhost:9000/mockAltCalculator
quarkus.cxf.client."mockAltCalculator".service-interface=org.tempuri.alt.AltCalculatorSoap
quarkus.cxf.client."mockAltCalculator".endpoint-namespace=http://alt.tempuri.org/
quarkus.cxf.client."mockAltCalculator".endpoint-name=CalculatorSoap
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.quarkiverse.it.cxf;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.runtime.LaunchMode;

public class ClientTestUtil {

private ClientTestUtil() {
}

public static <T> T getClient(Class<T> serviceInterface) {
try {
final URL serviceUrl = new URL(getServerUrl() + "/soap/greeting?wsdl");
final Service service = javax.xml.ws.Service.create(serviceUrl,
new QName("http://cxf.it.quarkiverse.io/", serviceInterface.getSimpleName()));
return service.getPort(serviceInterface);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}

public static String getServerUrl() {
Config config = ConfigProvider.getConfig();
final int port = LaunchMode.current().equals(LaunchMode.TEST) ? config.getValue("quarkus.http.test-port", Integer.class)
: config.getValue("quarkus.http.port", Integer.class);
return String.format("http://localhost:%d", port);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,42 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;

import java.lang.reflect.Proxy;
import java.net.MalformedURLException;

import javax.inject.Inject;

import org.junit.jupiter.api.Assertions;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
class GreetingWebServiceImplTest {
private static GreetingWebService greetingWS;

@Inject
public GreetingWebService greetingWS;
@BeforeAll
public static void setup() throws MalformedURLException {
greetingWS = ClientTestUtil.getClient(GreetingWebService.class);
}

@Test
void testIsNotProxy() {
Assertions.assertFalse(Proxy.isProxyClass(greetingWS.getClass()));
void reply() {
Assertions.assertThat(greetingWS.reply("bar")).isEqualTo("Hello bar");
}

@Test
void testCxfClient() {
Assertions.assertEquals("Hello bar", greetingWS.reply("bar"));
void ping() throws GreetingException {
Assertions.assertThat(greetingWS.ping("foo")).isEqualTo("Hello foo");
}

@Test
void testPing() {
String ret = null;
try {
ret = greetingWS.ping("bar");
} catch (GreetingException e) {
}
Assertions.assertEquals("Hello bar", ret);
void greetingException() {
Assertions.assertThatExceptionOfType(GreetingException.class)
.isThrownBy(() -> greetingWS.ping("error"))
.withMessage("foo");
}

@Test
void testSoapEndpoint() {
void rawSoap() {
String xml = "<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:cxf=\"http://cxf.it.quarkiverse.io/\">\n"
+
" <x:Header/>\n" +
Expand All @@ -59,20 +58,16 @@ void testSoapEndpoint() {
}

@Test
void testSoap12Binding() {
void soap12Binding() {
given()
.when().get("/soap/greeting?wsdl")
.then()
.statusCode(200)
.body(containsString("http://schemas.xmlsoap.org/wsdl/soap12/"));
.body(
containsString("http://schemas.xmlsoap.org/wsdl/soap12/"),
containsString("<wsdl:portType name=\"GreetingWebService\">"),
containsString("<wsdl:operation name=\"reply\">"),
containsString("<wsdl:operation name=\"ping\">"));
}

@Test
void testRestCxfClient() {
given()
.when().get("/rest")
.then()
.statusCode(200)
.body(containsString("Hello foo"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
import io.quarkus.test.junit.QuarkusIntegrationTest;

@QuarkusIntegrationTest
class ClientFacadeResourceTestIT extends ClientFacadeResourceTest {

class GreetingWebServiceImplTestIT extends GreetingWebServiceImplTest {
}
29 changes: 29 additions & 0 deletions integration-tests/client/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
= Quarkus CXF client tests

These are pure client tests - i.e. there are intentionally no services implemented in the test application.
All clients access services running in containers.

== Maintenenance notes

=== `CalculatorService.wsdl`

`src/main/cxf-codegen-resources/wsdl/CalculatorService.wsdl` is a static copy of the WSDL served by the testing container.
It is used solely by `cxf-codegen-plugin`.
It would be too complicated to start the container before running the plugin, so we rather keep the static copy.

There is `io.quarkiverse.cxf.client.it.CxfClientTest.wsdlUpToDate()` to ensure that it is up to date.

To update `CalculatorService.wsdl` manually, first start the container

[shource,shell]
----
$ docker pull quay.io/l2x6/calculator-ws:1.0
$ docker run -p 8080:8080 quay.io/l2x6/calculator-ws:1.0
----

And then overwrite the existing file with the new content from the container:

[shource,shell]
----
curl http://localhost:8080/calculator-ws/CalculatorService?wsdl --output src/main/cxf-codegen-resources/wsdl/CalculatorService.wsdl
----
Loading