Bad idea: Mixing JUnit Annotations and extends TestCase

I Wasted a good deal of time trying to find out why my simple JUnit tests were not working properly. It boiled down to my stupidity in mixing “public class TestSomeService extends TestCase” and trying to use “@BeforeClass” to initialize some test data.

When combining the JUnit annotations with “extends TestCase”, the annotations are rendered useless. There are no errors of any kind at the console, which makes the problem tough to nail down.

Do not do…

public class TestSomeService extends TestCase {
    @BeforeClass
    public static void beforeAllTestsConfig() throws Exception {
        //config before All tests are run
    }

<pre><code>@AfterClass
public static void afterAllTestsConfig() throws Exception {
    //config after all tests are run
}
</code></pre>

}

Instead…

public class TestSomeService {

<pre><code>@BeforeClass
public static void beforeAllTestsConfig() throws Exception {
    //config before All tests are run
}

@AfterClass
public static void afterAllTestsConfig() throws Exception {
    //config after all tests are run
}

@Before
public void beforeEachTest(){
    //config before each test is run
}

@After
public void afterEachTest() throws IOException{
    //config after each @Test is run
}

@Test
public void test_SimpleEmail() throws Exception {
    assertEquals(x, y);  //static import            
    Assert.assertTrue(true);
}
</code></pre>

}

how to copy jaxb.index properly without ignoring other config files in maven

I was utilizing some simple JAXB for a project that has a jaxb.index full of the java objects that are utilizing the JAXB annotations. I first tried the code below within my pom.xml:

&lt;build&gt;
              &lt;resources&gt; &lt;!-- include jaxb index files --&gt;
                     &lt;resource&gt;
                           &lt;directory&gt;src/main/java&lt;/directory&gt;
                           &lt;includes&gt;
                                  &lt;include&gt;**/*.index&lt;/include&gt;
                           &lt;/includes&gt;
                     &lt;/resource&gt;
              &lt;/resources&gt;
&lt;/build&gt;

However, this appears to override the data within the /src/main/resources/ directory (appConfig.xml, *.properties, etc.). This is what caused the .

I was able to find a maven plugin vi that helped to fix the issue.

&lt;plugin&gt;
    &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt;
    &lt;version&gt;2.5&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;copy-resources&lt;/id&gt;
            &lt;phase&gt;validate&lt;/phase&gt;
            &lt;goals&gt;
                &lt;goal&gt;copy-resources&lt;/goal&gt;
            &lt;/goals&gt;
            &lt;configuration&gt;
                &lt;outputDirectory&gt;${basedir}/target/classes/path/to/model/&lt;/outputDirectory&gt;
                &lt;resources&gt;
                    &lt;resource&gt;
                        &lt;directory&gt;${basedir}/src/main/resources/&lt;/directory&gt;
                        &lt;includes&gt;
                            &lt;include&gt;jaxb.properties&lt;/include&gt;
                        &lt;/includes&gt;
                    &lt;/resource&gt;
                &lt;/resources&gt;
            &lt;/configuration&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt; 

WebSphere 7 app startup exception without a hint

I received the error below after making an update to my app. As you can see there is nothing but IBM specific code in the stack trace. So I had a good idea which app was causing the error, but there is no indication as to which part of my code is the offender. After multiple debug sessions and System.println.out() in the constructor, I was able to find that my .properties files were not being loaded properly.

It’s not that WebSphere is a terrible app server, it’s just that it’s so freakin’ expensive for what you get.


[9/19/13 16:17:55:564 CDT] 0000002e servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper run [Servlet Error]-[class java.lang.NullPointerException: null]: java.lang.ClassNotFoundException: class java.lang.NullPointerException: null
at java.beans.Beans.instantiate(Unknown Source)
at java.beans.Beans.instantiate(Unknown Source)
at com.ibm.ws.webcontainer.servlet.ServletWrapper$1.run(ServletWrapper.java:1909)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java:1900)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:730)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3944)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:931)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1646)