Skip to content

Commit

Permalink
Added integration tests for lifecycle methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Jun 20, 2021
1 parent 9f13375 commit eb7e308
Show file tree
Hide file tree
Showing 6 changed files with 502 additions and 0 deletions.
228 changes: 228 additions & 0 deletions junit5/integration-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?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>

<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-integration-test</artifactId>

<parent>
<groupId>org.jboss.arquillian</groupId>
<version>1.7.0.Final-SNAPSHOT</version>
<artifactId>arquillian-build</artifactId>
<relativePath>../../build</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<payara.start.skip>${skipITs}</payara.start.skip>
<payara.version>5.2021.2</payara.version>
</properties>

<name>Arquillian JUnit 5 Container Integration Test</name>

<dependencies>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>1.0.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<!-- Payara Java EE Container support (container) -->
<dependency>
<groupId>fish.payara.arquillian</groupId>
<artifactId>arquillian-payara-server-remote</artifactId>
<version>2.4.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-cdi</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-ejb</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-initialcontext</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-resource</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Disable Surefire Plugin - Integration Only -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>

<!-- Download / Unpack Payara -->
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
</executions>
<configuration>
<overWrite>false</overWrite>
<outputDirectory>${basedir}/target</outputDirectory>
<markersDirectory>${basedir}/target/dependency-maven-plugin-markers</markersDirectory>
<artifactItems>
<artifactItem>
<groupId>fish.payara.distributions</groupId>
<artifactId>payara</artifactId>
<version>${payara.version}</version>
<type>zip</type>
</artifactItem>
</artifactItems>
<skip>${payara.start.skip}</skip>
</configuration>
</plugin>

<!-- Start / Stop Payara Domain -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>start-domain</id>
<phase>pre-integration-test</phase>
<configuration>
<arguments>
<argument>start-domain</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>stop-domain</id>
<phase>post-integration-test</phase>
<configuration>
<arguments>
<argument>stop-domain</argument>
</arguments>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<runOrder>alphabetical</runOrder>
<includes>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<executable>${basedir}/target/payara5/bin/asadmin</executable>
<skip>${payara.start.skip}</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2021 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.arquillian.junit5.lifecycle;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

/**
*
* @author lprimak
*/
public class CreateFileTestCase {
private static Path TMP_FILE_PATH;
static final String TMP_FILE_ASSET_NAME = "temporaryFileAsset";

enum RunsWhere {
CLIENT,
SERVER,
}

@BeforeAll
static void initTmpFileName(@TempDir Path tmpDirBase) {
TMP_FILE_PATH = tmpDirBase.getParent().resolve(
tmpDirBase.getFileName() + "-arquillianLifecycleTest")
.resolve("lifecycleOutput");
}

@Test
void createTmpFile() throws IOException {
TMP_FILE_PATH.getParent().toFile().mkdir();
File tmpFile = TMP_FILE_PATH.toFile();
tmpFile.delete();
assertTrue(tmpFile.createNewFile(), "cannot create results file");
}

static Path getTmpFilePath() {
if (isRunningOnServer()) {
try (InputStream istrm = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(TMP_FILE_ASSET_NAME)) {
return Paths.get(new BufferedReader(new InputStreamReader(istrm)).readLine());
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
} else {
return TMP_FILE_PATH;
}
}

static void appendToFile(String str) {
try (FileWriter fw = new FileWriter(getTmpFilePath().toFile(), true)) {
fw.append(str + ",");
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

static void checkRunsWhere(RunsWhere expected) {
assertEquals(expected, isRunningOnServer() ? RunsWhere.SERVER : RunsWhere.CLIENT);
}

static boolean isRunningOnServer() {
try {
new InitialContext().lookup("java:comp/env");
return true;
} catch (NamingException ex) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2021 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.arquillian.junit5.lifecycle;

import java.io.PrintStream;

/**
*
* @author lprimak
*/
public class Greeter {
public void greet(PrintStream to, String name) {
to.println(createGreeting(name));
}

public String createGreeting(String name) {
return "Hello, " + name + "!";
}
}

0 comments on commit eb7e308

Please sign in to comment.