Blog Archives

org.glassfish.embeddable.GlassFishException: PlainTextActionReporterFAILURENo configuration found for server.network-config.network-listeners.network-listener.http-listener

Overview

When I upgrade the Glassfish Server to be a version 3.1.2 from  here, the Glassfish Embedded Server should be upgraded as well. Anyhow when I perform the unit test, it is failed as

org.glassfish.embeddable.GlassFishException: PlainTextActionReporterFAILURENo configuration found for server.network-config.network-listeners.network-listener.http-listener

Investigation

I’ve put the whole exception mentioned above to sear via Google and found the useful information at Glassfish Jira issue #18452 . They mention about the configuration at the domain.xml is not completed. I’ve been noticed that the Glassfish Embeded Server has some limitation about the HTTP listener port and need to be applied the additional configuration as it is mentioned here.

The Root Cause

The root cause is I’ve configured the HTTP port explicitly as

props.put("org.glassfish.ejb.embedded.glassfish.web.http.port", 14080);
ejbContainer = EJBContainer.createEJBContainer(props);

The Solution

It is a very easy step by removing the explicitly configured HTTP port. Anyhow, the domain.xml should be configured for all related ports properly. We can download the starter domain.xml from here and start configure all related ports and/or further jdbc/datasource resources as well.

 

Java GUI implementation with Eclipse SWT, Eclipse Visual Editor Project and Maven: Part 3

Overview

This post will introduce you the end-to-end development with the Maven by using the very simple traditional, the Hello World ! So that you may apply to your own requirement.

The SWT Hello World !

Firstly we need the empty Maven project. All required dependency artifacts which have been mentioned at the previous post should be set at the project POM file as well.

After that we will create the SWT: Shell Visual Class at which you will see File –> New –> Other — > Java –> SWT –> Shell Visual Class. Here is the simple Hello World source which is generated by the visual editor. Please note, it is not a time to make a source code to be beautiful. We just need to see only the big picture.

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class HelloWorldSWT {

    private Shell sShell = null;
    private Text textName = null;
    private Label labelMessage = null;
    private Button buttonSubmit = null;
    private Button buttonCancel = null;
    private Label labelName = null;

    /**
     * This method initializes sShell
     */
    private void createSShell() {
        final GridData gridData = new GridData();
        gridData.horizontalSpan = 2;
        final GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        this.sShell = new Shell();
        this.sShell.setText("Shell");
        this.sShell.setLayout(gridLayout);
        this.sShell.setSize(new Point(300, 200));
        this.labelName = new Label(this.sShell, SWT.NONE);
        this.labelName.setText("Name:");
        this.textName = new Text(this.sShell, SWT.BORDER);
        this.labelMessage = new Label(this.sShell, SWT.NONE);
        this.labelMessage.setText("I'm waiting for you.");
        this.labelMessage.setLayoutData(gridData);
        this.buttonSubmit = new Button(this.sShell, SWT.NONE);
        this.buttonSubmit.setText("Submit");
        this.buttonSubmit.addMouseListener(
                new org.eclipse.swt.events.MouseAdapter() {
                    static final String MESSAGE = "Hello ";
                    @Override
                    public void mouseDown(
                            final org.eclipse.swt.events.MouseEvent e) {
                        final String name = HelloWorldSWT.this.textName.getText();
                        HelloWorldSWT.this.labelMessage.setText(MESSAGE + name);
                    }
                });
        this.buttonCancel = new Button(this.sShell, SWT.NONE);
        this.buttonCancel.setText("Cancel");

        this.buttonCancel.addMouseListener(
            new org.eclipse.swt.events.MouseAdapter() {
                @Override
                public void mouseDown(
                        final org.eclipse.swt.events.MouseEvent e) {
                    HelloWorldSWT.this.labelMessage.setText("");
                    HelloWorldSWT.this.textName.setText("");
                }
            });

        Display display = null;
        display = Display.getDefault();
        this.sShell.pack();
        this.sShell.open();
        while (!this.sShell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }

    public static void main(final String[] args) {
        final HelloWorldSWT main = new HelloWorldSWT();
        main.createSShell();
    }
}

The Unit Testing with SWTBot

Normally, we should test all possible scenarios such as the following:-

Table 1: Test case scenario

# Scenario Expected Result
1 When the user enter the name and click submit. The label should displays “Hello <NAME>”.
2 When the user enter the name as an empty String

and click submit.

The label should displays “Hello ”. (There is a space.)
3 When the user enter the name and click cancel. The text and label should be cleared.
Etc. Etc.

I will show you only one case, the case #1. It just create a simple JUnit4 class and put the SWTBot related statements as the following: –

import junit.framework.Assert;

import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.finders.ControlFinder;
import org.eclipse.swtbot.swt.finder.finders.MenuFinder;
import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.scc.biometric.poc.mock.swt.HelloWorldSWT;

public class HelloWorldSWTTest {
    private static final Logger LOGGER;
    static {
        LOGGER = Logger.getLogger(HelloWorldSWTTest.class);
    }

    private SWTBot bot;

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    }

    @AfterClass
    public static void tearDownAfterClass() throws Exception {
    }

    @Before
    public void setUp() throws Exception {
        this.initSWTApplication();
    }

    @After
    public void tearDown() throws Exception {

    }

    static {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    HelloWorldSWT.main(new String[] {});
                } catch (final Exception e) {
                    HelloWorldSWTTest.
                       LOGGER.
                          fatal("Cannot instantiate the Hello.", e);
                }
            }
        }).start();
    }

    @Test
    public void whenSay() {
        this.say("Charlee");
    }

    private void initSWTApplication() {
        this.waitForDisplayToAppear(5000);
        this.initSWTBot();
    }

    private void waitForDisplayToAppear(final long time) {
        long    endTime = -1;
        Display display = null;
        try {
            endTime = System.currentTimeMillis() + time;
            while (System.currentTimeMillis() < endTime) { // wait until timeout
                try {
                    display = SWTUtils.display();
                    if (display != null) {
                        HelloWorldSWTTest.LOGGER.info("The display is found.");
                        return;
                    }
                } catch (final Exception e) {
                    HelloWorldSWTTest.
                       LOGGER.
                          warn("Cannot find display, keep waiting.");
                }
                try {
                    Thread.sleep(100);
                } catch (final InterruptedException e) {
                    HelloWorldSWTTest.LOGGER.warn("The thread is interrupted", e);
                } // sleep for a while and try again
            }
        } finally {
            display = null;
        }
    }

    private void initSWTBot() {
        ControlFinder cf = null;
        MenuFinder    mf = null;
        try {
            cf       = new ControlFinder();
            mf       = new MenuFinder();
            this.bot = new SWTBot(cf, mf);
        } finally {
            cf = null;
            mf = null;
        }
    }

    private void say(final String name) {
        SWTBotLabel  swtBotLabel  = null;
        SWTBotButton swtBotButton = null;
        SWTBotText   swtBotText   = null;
        String       saidMessage  = null;
        try {
            swtBotText   = this.bot.
                              textWithLabel("Name:");
            Assert.assertNotNull("Cannot find the textName.", swtBotText);
            swtBotText.setText(name);

            swtBotButton = this.bot.button("Submit");
            Assert.assertNotNull("Cannot find the buttonSubmit.", swtBotButton);
            swtBotButton.click();

            saidMessage  = "Hello ";

            if (name != null) {
                saidMessage += name;
            } else {
                saidMessage += "null";
            }


            swtBotLabel  = this.bot.label(saidMessage);

            Assert.assertNotNull("Cannot find the said lable.", swtBotLabel);


        } catch (final Exception e) {
            HelloWorldSWTTest.LOGGER.fatal("This is an unexpected error", e);
            throw new RuntimeException(e);
        } finally {
            swtBotLabel  = null;
            swtBotButton = null;
            swtBotText   = null;
        }
    }
}

Test It !!!

There are 2 way for performing the testing, first is either via the JUnit within the Eclipse IDE or via the command line as “mvn test”.

Summary

We have created the big picture, end-to-end classic traditional Hello World SWT application, including with the unit testing with SWTBot inside the Maven environment. The next step is fulfilling the test case so that it covers all the possible scenarios as a good practice.

Since we always be the Maven, then our application can be expanded to the other infrastructure more simply and easily. e.g Maven report, Maven Site, Code quality, Code Coverage, Continuous Integration server and so on. Most of them not only support the Maven project and but also provide120% compatible and cross platform.

Please take note, I’m on the Windows x86 Vista and develop the Maven project. My infrastructure is on the Linux: CentOS x86_64. The CI Server can build and perform the unit testing successfully. I have achieved the cross platform already.

Java GUI implementation with Eclipse SWT, Eclipse Visual Editor Project and Maven: Part 2

Overview

Regarding to my previous post, There are three required artifacts which should be installed before we move further, i.e. The Eclipse Visual Editor, The Eclipse SWT runtime and the Eclipse SWTBot. After we have finished installing, then we should deploy the required dependency artifacts to the local repository or the local repository manager, since there is no any internet Maven repository which provides the latest version.

Please note, the assumption is we already have an Eclipse, including Maven and other related artifacts, including with the system software. Anyhow all of them has been posted at my blog as well, you may refer to the series of Java Development with NetBeans and Maven. Please do not worry, since we are in the Maven world, the tools / IDE does not the issue. It is transparent so that you can build them without the IDE, via the command line. It’s a strongest point. I’m loving it.

The Required Artifacts

The Eclipse Visual Editor

Installation

It can be installed remotely via the Eclipse update site or offline via the All-In-One Update Site. Please note, I’ve face some difficult due the remotely and only achieve via the offline installation.

Even the required artifacts has been installed at your ECLIPSE_HOME, it is only for your platform. For me, I’m at a Windows, then there is only a WIN32-x86 runtime.

The Eclipse Standard Widget Toolkit (SWT) Runtime

Overview

As we have known, there is an OS dependency for the GUI development so that we need to have a specific and correct runtime for each platform. The Eclipse SWT provides us the runtime for every OS already.

Installation

You can download them here. You may choose only your decided platform, But I have downloaded all of them.

Deploy the dependency to the Maven

After you have finished installing, you should extract the downloaded artifact and deploy the swt.jar to your local repository or local repository manager. As you have known, I prefer the local repository manager, the Artifactory. Please note, you may deploy the source code for further reference as the src.jar.

The Eclipse SWTBot

Installation

You can install them remotely via the Eclipse Update Site. It is a platform independent artifacts.

Deploy the dependency to the Maven

After you have finished installing, the required artifact also have been installed at your ECLIPSE_HOME. You can search them by using the wildcard as “*swtbot*.jar” and deploy them to the Maven repository. The artifacts is as following: –

Table 1: The SWTBot Runtime

# Artifact
1 org.eclipse.swtbot.ant.optional.junit3_2.0.4.20110304_0338-e5aff47-dev-e36.jar
2 org.eclipse.swtbot.ant.optional.junit4_2.0.4.20110304_0338-e5aff47-dev-e36.jar
3 org.eclipse.swtbot.eclipse.core_2.0.4.20110304_0338-e5aff47-dev-e36.jar
4 org.eclipse.swtbot.eclipse.finder_2.0.4.20110304_0338-e5aff47-dev-e36.jar
5 org.eclipse.swtbot.eclipse.gef.finder_2.0.4.20110304_0338-e5aff47-dev-e36.jar
6 org.eclipse.swtbot.eclipse.spy_2.0.4.20110304_0338-e5aff47-dev-e36.jar
7 org.eclipse.swtbot.eclipse.ui_2.0.4.20110304_0338-e5aff47-dev-e36.jar
8 org.eclipse.swtbot.forms.finder_2.0.4.20110304_0338-e5aff47-dev-e36.jar
9 org.eclipse.swtbot.go_2.0.4.20110304_0338-e5aff47-dev-e36.jar
10 org.eclipse.swtbot.junit4_x_2.0.4.20110304_0338-e5aff47-dev-e36.jar
11 org.eclipse.swtbot.swt.finder_2.0.4.20110304_0338-e5aff47-dev-e36.jar

Summary

At the moment we already have all required artifact and ready to start the development.

The next post we will see the big picture, end-to-end development with Maven. Please stay tuned as always.

Java Development with NetBeans and Maven: Part 5

Overview

I hope we are well prepared for moving further to the very powerful “Maven” features, which we have known before, the “site”, especially the “report” integration to the outer world. There are many powerful “Maven Plug-in” provided by the “Maven” itself. You can see further information here. From now on, I will introduce you the “Reporting Plug-ins”.

The Report Plug-ins

Regarding the “Maven Plug-inhere, you may be noticed that there are two plug in which we used before. Guess what? The “project-info-reports”, the “mvn site” command itself and the “surefire-report”, the testing report for our previous JUnit. You already know how easy it is. The rest plug in also be same for sure. One picture can give us a thousand words. Here is my tested template “Project POM File” (pom.xml). Please feel free to modify it so that it is fit for your environment.


<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>
    <groupId>com.scc.maven.java</groupId>
    <artifactId>MavenJavaPrj01</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>MavenJavaPrj01</name>
    <url>The Project web site URL</url>
    <description>The SDLC Learning</description>

    <licenses>
        <license>
            <name>Apache 2</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
            <comments>A business-friendly OSS license</comments>
        </license>
    </licenses>

    <organization>
        <name>The Organization Name</name>
        <url>The Organization web site URL</url>
    </organization>

    <developers>
        <developer>
            <id>The developer id</id>
            <name>The developer name</name>
            <email>The developer email</email>
            <url>The developer web site URL</url>
            <organization>The developer organization</organization>
            <organizationUrl>The organization web site url</organizationUrl>
            <roles>
                <role>Role #1</role>
                <role>Role #2</role>
            </roles>
            <timezone>+7</timezone>
            <properties>
                <picUrl>The developer picture URL</picUrl>
            </properties>
        </developer>
    </developers>

    <issueManagement>
        <system>The issue management system, e.g. Bugzilla, TestTrack, ClearQuest, etc</system>
        <url>The issue management system web site URL</url>
    </issueManagement>

    <ciManagement>
        <system>The CI management system, e.g. Hudson,continuum, etc</system>
        <url>The CI web site URL</url>
        <notifiers>
            <notifier>
                <type>mail</type>
                <sendOnError>true</sendOnError>
                <sendOnFailure>true</sendOnFailure>
                <sendOnSuccess>false</sendOnSuccess>
                <sendOnWarning>false</sendOnWarning>
                <configuration>
                    <address>The sender email address</address>
                </configuration>
            </notifier>
        </notifiers>
    </ciManagement>

    <scm>
        <connection>scm:svn:Path/To/Repository</connection>
        <developerConnection>scm:svn:Path/To/Repository</developerConnection>
        <tag>HEAD</tag>
        <url>The SCM web site URL</url>
    </scm>

    <prerequisites>
        <maven>2.2.1</maven>
    </prerequisites>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <includes>
                        <include>
                            **/*TestSuite*.java
                        </include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <locales>en</locales>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <includes>
                    <include>log4j.dtd</include>
                    <include>log4j.xml</include>
                </includes>
            </resource>
        </resources>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>2.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-changelog-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <username>${svnUser}</username>
                    <password>${svnPassword}</password>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <configLocation>config/sun_checks.xml</configLocation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <stylesheetfile>${basedir}/src/main/javadoc/stylesheet.css</stylesheetfile>
                    <show>private</show>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jxr-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <linkXref>true</linkXref>
                    <sourceEncoding>utf-8</sourceEncoding>
                    <minimumTokens>100</minimumTokens>
                    <targetJdk>1.5</targetJdk>
                    <excludes>
                        <exclude>**/*Bean.java</exclude>
                        <exclude>**/generated/*.java</exclude>
                    </excludes>
                    <excludeRoots>
                        <excludeRoot>target/generated-sources/stubs</excludeRoot>
                    </excludeRoots>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>2.5</version>
            </plugin>

        </plugins>
    </reporting>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

How the report is created.

It is simple by using the “mvn site” command, please refer to my previous post.

Are there any outer world plug in?

Yes, sure. Why not? Maven also mentioned in their plug in page as well. Please travel to the lower part of that page you will see the outer world for sure. I hope we are enjoy traveling.

Summary

We have finished preparing our development environment so that we can ensure that there should not be any surprise during the integration with the very powerful “Maven” features, the “site”, especially the “report”. As I’ve mentioned, This is a final article for my first series.

The well preparing will help us to reduce the defect, on the other hand, if the defect is less, the working time is less, too. That mean we will have more time to do other things in my life. For me is writing this blog. Next I will move further to the detailed “Java/JavaEE” development with “Maven” and will do my best to post for sure. Please stay tuned as always.

Java Development with NetBeans and Maven: Part 2

Overview

Now we will focus on the further maven configuration. There are a lot of pulgins provided by the Maven. I would like to pay more attention to the unit testing, the Maven Surefire Plugin and Maven Surefire Report Plugin. Normally the JUnit is supported by default. I also prefer the latest JUnit 4.

Not only the unit testing, but also my most favorite library, the Apache Log4J. I will add it to my project at the same time. I cannot live without Log4J.

Adding New Library To The Project

Previously, without Maven, I’ve faced the trouble about managing my java library. I’ve no idea to organize it as the following scenarios: –

  1. Where is the right place to store the library? The my decided shared folder? The Java project folder? The WEB-INF/lib folder?
  2. Should I set the user library inside my IDE? Which IDE should I use? How to share them across my team?
  3. How to use this structure across my team?
  4. How to ensure the completion when we get the source code from repository or version control?
  5. Blah blah blah….

My trouble is solved by the Maven. They are stored and managed transparently by the Local Repository. There is no any stored library inside my project folder. Only the dependency configuration is required.

Let’s try to add the Log4J

I will show how simple it is. Just open the Project POM file (pom.xml) and add the Log4J dependency, inside the <dependencies> tag. Again I prefer the latest version as always.

<dependencies>
    ................
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

Next we will add the Log4J configuration to our project, by default this configuration file is nice to be stored at the “Project Default Package”, by the way it would be better to be stored at the “CLASSPATH”. Anyhow, regarding to my experience, I prefer to store it at the “Project Default Package”. Please note, it is just a simply copying and pasting to that folder. Then we will configure the Project POM file (pom.xml) so that it knows our configuration by adding the <resources> tag inside the <build> tag.

<resources>
    <resource>
        <directory>${basedir}/src/main/java</directory>
        <includes>
            <include>YOUR_RESOURCE</include>
            <include>YOUR_RESOURCE</include>
        </includes>
    </resource>
</resources>

Please note, you can add more resources as you need.

Writing The Code

I will modify my previous class, the “HelloWorld” application so that it print out the message before returning.

package com.scc.maven.java.prj01;

import org.apache.log4j.Logger;

/**
 * Hello world!
 *
 */
public class App{
    private static final Logger logger = Logger.getLogger(App.class);
    public String says(String name){
        String message = "Hello " + name;
        logger.info("The saying message is: " + message);
        return message;
    }
}

Create TestSuite

At the moment I will be back the unit testing by adding the “TestSuite” to my project. Normally I name it by add the wording “TestSuite” at the end of the class name. You will see the reason why I do like this.

package com.scc.maven.java.prj01;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

/**
 *
 * @author Charlee.Ch
 */
@RunWith(Suite.class)
@Suite.SuiteClasses({com.scc.maven.java.prj01.AppTest.class})
public class MyFirstTestSuite {

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() throws Exception {
    }

    @After
    public void tearDown() throws Exception {
    }

}

It has not been finished yet, The Project POM file (pom.xml) need to be modified by mention the “Maven Surefire Pluginat the <plugins> tag and configure it so that it accept my test suite class.

The key is “**/*TestSuite*.java” and it is a reason why I name it as it is.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <includes>
            <include>
                **/*TestSuite*.java
            </include>
        </includes>
    </configuration>
</plugin>

Building & Testing

As I’ve mentioned before, during the “Build” or “Clean and Build” is executed, the unit testing will be executed automatically. If you would like to explicitly execute, just right clicking at your test class and choose “Test File”.

Configure The Unit Testing Report

I would like to create a summary report for my unit testing by using the “Maven Surefire Report Plugin”. Please note, the report will be created automatically when the maven site is created, anyhow you can explicitly execute. At the moment I prefer running explicitly.

Configure the Maven Surefire Report Plugin

Firstly we will modify the Project POM file (pom.xml) by adding the <reporting> tag and “Maven Surefire Report Plugin” configuration at the same level of the <build> tag.

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.6</version>
        </plugin>
    </plugins>
</reporting>

Add Custom Maven Command

Second I will add the “Custom Maven Command” to the NetBeans Java Project so that the unit testing report can be generated. It is simply action as the following step: –

  1. Go to project properties.
  2. Inside the “Project Properties” windows, under the “Categories”, choose “Actions”.
  3. On the right hand panel, Click “Add Custom..” button.
  4. Enter the “Action Name” as “My.Surefire.Report”.
  5. Enter the “Execure Goal” as “surefire-report:report ”.

Execute The Custom Maven Command

Right click at your project and choose “Custom” –> “My.Surefire.Report”, It will display my previous created “Custom Maven Command”. Please note, the missing resources which are not in your “Local Repository” will be downloaded automatically as usual. The generated report is stored at <Project Folder>/target/site/surefire-report.html. Please look around it.

Summary

Now we are understand about the further Maven configuration, including with adding new resources, configuring the test suite and especially the unit testing report, plus create a custom maven command inside the NetBeans.

Next I will introduce more Maven Configuration, e.g. creating a site, configuring the version control, configuring the issues tracker, make use of them as a release note, and so on. Please stay tuned as always.