Skip to content

Commit

Permalink
Refactored GF Embedded tests
Browse files Browse the repository at this point in the history
- set work dir inside target directory for creating temporary files
- renamed tests that end in ITest to IUnitTest to run them as UT not IT
Signed-off-by:Ondro Mihalyi <mihalyi@omnifish.ee>
  • Loading branch information
OndroMih committed Sep 4, 2023
1 parent 7222094 commit 9b54d52
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 60 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -58,9 +58,6 @@ appserver/tests/appserv-tests/devtests/webservice/ejb_annotations/security/roles
appserver/tests/appserv-tests/devtests/webservice/security/*.cer
appserver/tests/appserv-tests/devtests/webservice/security/*.jks

/appserver/tests/embedded/cdi_ejb_jpa/sun-appserv-samples/
/appserver/tests/embedded/cdi_ejb_jpa/derby.log

appserver/tests/appserv-tests/temppwd

opendj-*.zip
Expand Down
Expand Up @@ -43,7 +43,9 @@
* @author bhavanishankar@dev.java.net
*/

public class BasicCDITest{
public class BasicCDIUnitTest {

private static final String PROJECT_DIR = System.getProperty("project.directory");

@Test
public void test() throws Exception {
Expand All @@ -55,9 +57,9 @@ public void test() throws Exception {

// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_basic",
ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
ScatteredArchive.Type.WAR, new File(PROJECT_DIR, "src/main/webapp"));
sa.addClassPath(new File(PROJECT_DIR, "target/classes"));
sa.addClassPath(new File(PROJECT_DIR, "src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);

Expand Down
Expand Up @@ -29,14 +29,10 @@
urlPatterns = "/BasicCDITestServlet")

@DataSourceDefinition(
name="java:app/jdbc/DB1",
className="org.apache.derby.jdbc.EmbeddedDataSource",
portNumber=1527,
serverName="localhost",
databaseName="sun-appserv-samples",
user="APP",
password="APP",
properties={"connectionAttributes=;create=true"}
name = "java:app/jdbc/DB1",
className = "org.apache.derby.jdbc.EmbeddedDataSource",
databaseName = "sun-appserv-samples",
properties = {"connectionAttributes=;create=true"}
)
public class BasicCDITestServlet extends HttpServlet {

Expand Down
Expand Up @@ -43,7 +43,9 @@
* @author bhavanishankar@dev.java.net
*/

public class BasicCDITest{
public class BasicCDIUnitTest {

private static final String PROJECT_DIR = System.getProperty("project.directory");

@Test
public void test() throws Exception {
Expand All @@ -55,9 +57,9 @@ public void test() throws Exception {

// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_ejb_jpa",
ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
ScatteredArchive.Type.WAR, new File(PROJECT_DIR, "src/main/webapp"));
sa.addClassPath(new File(PROJECT_DIR, "target/classes"));
sa.addClassPath(new File(PROJECT_DIR, "src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);

Expand Down
58 changes: 28 additions & 30 deletions appserver/tests/embedded/glassfish_resources_xml/pom.xml
Expand Up @@ -20,33 +20,27 @@
<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>org.glassfish.tests</groupId>
<artifactId>embedded</artifactId>
<version>7.0.9-SNAPSHOT</version>
</parent>

<groupId>org.glassfish.tests.embedded.basic</groupId>
<artifactId>glassfish_resources_xml</artifactId>
<version>7.0.9-SNAPSHOT</version>
<name>CDI, EJB, JPA integration test which has glassfish-resources.xml</name>
<build>
<finalName>glassfish_resources_xml</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<useSystemClassLoader>false</useSystemClassLoader>
<useManifestOnlyJar>false</useManifestOnlyJar>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
</dependencies>

<profiles>
<profile>
<id>run-with-uber-jar</id>
Expand All @@ -57,12 +51,21 @@
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>run-with-uber-jar-web</id>
<activation>
<property>
<name>build</name>
<value>uber-jar-web</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-web</artifactId>
</dependency>
</dependencies>
</profile>
Expand All @@ -75,11 +78,6 @@
</property>
</activation>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
Expand Down
Expand Up @@ -16,17 +16,16 @@

package org.glassfish.tests.embedded.cdi_ejb_jpa;

import junit.framework.Assert;
import org.junit.jupiter.api.Assertions;
import org.glassfish.embeddable.Deployer;
import org.glassfish.embeddable.GlassFish;
import org.glassfish.embeddable.GlassFishProperties;
import org.glassfish.embeddable.BootstrapProperties;
import org.glassfish.embeddable.GlassFishRuntime;
import org.glassfish.embeddable.archive.ScatteredArchive;
import org.glassfish.embeddable.archive.ScatteredEnterpriseArchive;
import org.glassfish.embeddable.web.HttpListener;
import org.glassfish.embeddable.web.WebContainer;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -44,7 +43,9 @@
* @author bhavanishankar@dev.java.net
*/

public class BasicCDITest{
public class BasicCDIUnitTest {

private static final String PROJECT_DIR = System.getProperty("project.directory");

@Test
public void test() throws Exception {
Expand All @@ -57,17 +58,17 @@ public void test() throws Exception {

// Test Scattered Web Archive
ScatteredArchive sa = new ScatteredArchive("cdi_ejb_jpa",
ScatteredArchive.Type.WAR, new File("src/main/webapp"));
sa.addClassPath(new File("target/classes"));
sa.addClassPath(new File("src/main/resources"));
ScatteredArchive.Type.WAR, new File(PROJECT_DIR, "src/main/webapp"));
sa.addClassPath(new File(PROJECT_DIR, "target/classes"));
sa.addClassPath(new File(PROJECT_DIR, "src/main/resources"));
URI warURI = sa.toURI();
printContents(warURI);

// Deploy archive
Deployer deployer = glassfish.getDeployer();
String appname = deployer.deploy(warURI);
System.out.println("Deployed [" + appname + "]");
Assert.assertEquals(appname, "cdi_ejb_jpa");
Assertions.assertEquals(appname, "cdi_ejb_jpa");

// Now create a http listener and access the app.
WebContainer webcontainer = glassfish.getService(WebContainer.class);
Expand Down Expand Up @@ -99,7 +100,7 @@ private void get(String urlStr, String result) throws Exception {
found = true;
}
}
Assert.assertTrue(found);
Assertions.assertTrue(found);
System.out.println("\n***** SUCCESS **** Found [" + result + "] in the response.*****\n");
}

Expand Down
28 changes: 26 additions & 2 deletions appserver/tests/embedded/pom.xml
Expand Up @@ -38,10 +38,10 @@
<module>cdi_basic</module>
<module>cdi_ejb_jpa</module>
<module>glassfish_resources_xml</module>
<module>ejb</module>
<!-- <module>ejb</module>
<module>scatteredarchive</module>
<module>maven-plugin</module>
<module>web</module>
<module>web</module> -->
</modules>

<dependencyManagement>
Expand All @@ -59,4 +59,28 @@
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<workingDirectory>${project.build.directory}/surefire-workdir</workingDirectory>
<systemPropertyVariables>
<project.directory>${basedir}</project.directory>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<workingDirectory>${project.build.directory}/failsafe-workdir</workingDirectory>
<systemPropertyVariables>
<project.directory>${basedir}</project.directory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

0 comments on commit 9b54d52

Please sign in to comment.