0

I am getting this error:

   Class not found com.apache.camel.example.tests.ReportIncidentRoutesTest
java.lang.ClassNotFoundException: com.apache.camel.example.tests.ReportIncidentRoutesTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

This is the updated stack trace for the new error that I am receiving. In the run configuration I do have it pointing to this class so I am not sure why I am still getting this error.

EDIT: ----------------------------------------------------------------------------------- Copy of my Test Class:

package com.apache.camel.example.tests;

import org.apache.camel.CamelContext;
import org.apache.camel.example.reportincident.InputReportIncident;
import org.apache.camel.example.reportincident.OutputReportIncident;
import org.apache.camel.example.reportincident.ReportIncidentEndpoint;
import org.apache.camel.example.reportincident.ReportIncidentRoutes;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.jvnet.mock_javamail.Mailbox;

import junit.framework.Test;
import junit.framework.TestCase;

/** * Unit test of our routes */

   public class ReportIncidentRoutesTest extends TestCase {

private CamelContext camel;

// should be the same address as we have in our route
private static String ADDRESS = "http://localhost:8080/part-five/webservices/incident";

protected void startCamel() throws Exception {
    camel = new DefaultCamelContext();
    camel.addRoutes(new ReportIncidentRoutes());
    camel.start();
}

protected static ReportIncidentEndpoint createCXFClient() {
    // we use CXF to create a client for us as its easier than JAXWS and works
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(ReportIncidentEndpoint.class);
    factory.setAddress(ADDRESS);
    return (ReportIncidentEndpoint) factory.create();
}

public void testRendportIncident() throws Exception {
    // start camel
    startCamel();

    // assert mailbox is empty before starting
    Mailbox inbox = Mailbox.get("blah@blah.com");
    assertEquals("Should not have mails", 0, inbox.size());

    // create input parameter
    InputReportIncident input = new InputReportIncident();
    input.setIncidentId("123");
    input.setIncidentDate("2008-08-18");
    input.setGivenName("Patrick");
    input.setFamilyName("joe");
    input.setSummary("Blah");
    input.setDetails("Blah blah");
    input.setEmail("blah@blah.com");
    input.setPhone("845 2962 7576");

    // create the webservice client and send the request
    ReportIncidentEndpoint client = createCXFClient();
    OutputReportIncident out = client.reportIncident(input);

    // assert we got a OK back
    assertEquals("0", out.getCode());

    // let some time pass to allow Camel to pickup the file and send it as an email
    Thread.sleep(3000);

    // assert mail box
    assertEquals("Should have got 1 mail", 1, inbox.size());

    // stop camel
    camel.stop();
}

}

parchambeau
  • 1,141
  • 9
  • 34
  • 56
  • How do you run unit test? How do you build your release jar? – Taky Jan 17 '13 at 15:19
  • I am just doing an eclipse Run as --> JUnit Test – parchambeau Jan 17 '13 at 15:20
  • And my release jar is going to packaged in a WAR file deployed to a tomcat server – parchambeau Jan 17 '13 at 15:21
  • 1
    Thanks. Try to check default runner in our Run configuration Eclipse JUnit runner for your class. Also be sure that the valid JUnit jar is in your classpath for particular running configuration. – Taky Jan 17 '13 at 15:24
  • Ah, yes it seems that it wasn't in the classpath of the run configuration, I am getting a different error now saying that "Class not found" for the test, even though I have it explicity stated in the run config – parchambeau Jan 17 '13 at 15:26
  • please add also stack trace – Taky Jan 17 '13 at 15:46
  • okay, will edit the old stack trace with new one. thank you for your help! – parchambeau Jan 17 '13 at 15:49
  • Check is it cannot be solution for you: http://stackoverflow.com/questions/5716308/junit-test-class-in-eclipse-java-lang-classnotfoundexception – Taky Jan 17 '13 at 19:55

1 Answers1

0

It seems junit 3 is in the classpath when compiling (assuming you don't get compile errors for any use of junit api) but not when running, so there is some classpath mismatch involved.

It seems you run the test through the eclipse test runner, is that configured to the same junit version as the tests are written for?

Rasmus Kaj
  • 4,224
  • 1
  • 20
  • 23
  • Yea, I was getting a different error before and I looked in the run configurations to find that it was set to JUNIT 4 so I changed it to 3, but then this error started popping up. – parchambeau Jan 17 '13 at 15:24
  • The I would guess that the eclipse configuration has a bad path to the junit 3 .jar file, but I don't know how to find and fix that configuration, sorry. – Rasmus Kaj Jan 17 '13 at 15:31