I have a test with an Error that gives no good information. The only piece of the stack that involves my code is the method call in the test which fails.
-------------------------------------------------------------------------------
Test set: com.example.ExampleServiceTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.258 sec <<< FAILURE!
testGetNoHeaders(com.example.ExampleServiceTest) Time elapsed: 0.256 sec <<< ERROR!
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:957)
at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:784)
at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:91)
at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:672)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:424)
at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:668)
at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:397)
at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:297)
at com.example.ExampleServiceTest.testGet(ExampleServiceTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Test class:
package com.example;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.mvc.mustache.MustacheMvcFeature;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.Test;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Application;
public class FakeSiteminderServiceTest extends JerseyTest {
#Override
protected Application configure() {
final ResourceConfig rc = new ResourceConfig().property(
MustacheMvcFeature.TEMPLATE_BASE_PATH, "templates"
).register(
MustacheMvcFeature.class
).packages("com.example");
return rc;
}
#Test
public void testGet() {
System.out.println("111111111111111111111111111111111111");
WebTarget t = target("/api/url");
System.out.println(t.toString());
Invocation.Builder b = t.request();
System.out.println(b.toString());
String respString = b.get(String.class); // <-- ERROR IS HERE
System.out.println("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
System.out.println(respString);
}
}
The class I'm trying to test works fine when I run it with grizzly and render it manually with a browser.
#Path("url")
public class FakeSiteminderService {
#GET
#Produces(MediaType.TEXT_HTML)
#Template(name = "/foo")
public Map<String, String> get(
#Context HttpHeaders hh
) {
Map<String, String> ctx = new HashMap<>();
if (hh.getRequestHeader("FULLNAME") != null) {
ctx.put("FULLNAME", hh.getRequestHeader("FULLNAME").get(0));
ctx.put("EMAIL", hh.getRequestHeader("EMAIL").get(0));
}
return ctx;
}
You may be able to get some more information out or a different traceback if you put some code like this somewhere in your package:
#Provider
public class CustomExceptionMapper implements
ExceptionMapper<Throwable> {
#Override
public Response toResponse(Throwable ex) {
System.out.println("EXCEPTIONMAPPER!!!!!!!!!!!!!!!!!!!!");
System.out.println(Exceptions.getStackTraceAsString(ex)); // <--
return Response.status(500).entity(
Exceptions.getStackTraceAsString(ex)
).type("text/plain").build();
}
}
Related
I am writing unit-test class using Junit and I am also using power-mocking concept to mock the objects which are created inside the method.
Test Class :
#PowerMockIgnore("javax.management.*")
#RunWith(PowerMockRunner.class)
#PrepareForTest(Client.class)
public class ClientTest {
private static final Logger logger = LoggerFactory
.getLogger(ClientTest.class);
private static Client client;
private static DetailsDao detailsDao;
public static Session session;
private static IDevicesDao devicesDao;
private static IUserDao userDao;
private static IDao dao;
private static IValidator validator;
#BeforeClass
public static void setup() throws Exception {
logger.info("*************** Testing ClientTest Started *******************");
session = Connection.get(); // Here getting error
detailsDao = mock(DetailsDao.class);
devicesDao = mock(IDevicesDao.class);
userDao = mock(UserDao.class);
validator = mock(IValidator.class);
dao= mock(IDao.class);
client = new Client(detailsDao, session, devicesDao, userDao, dao, validator);
}
If I romove #RunWith(PowerMockRunner.class) then its working fine... But I have to run this test using PowerMockRunner only.
Exception :
[10:45:50] sumanth nama: Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.234 sec <<< FAILURE!
com.service.clientTest Time elapsed: 1.234 sec <<< ERROR!
FSWriteError in target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log
at org.apache.cassandra.io.util.FileUtils.deleteWithConfirm(FileUtils.java:135)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:381)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377)
at org.apache.cassandra.io.util.FileUtils.deleteRecursive(FileUtils.java:377)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.rmdir(EmbeddedCassandraSer verHelper.java:266)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:81)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:64)
at org.cassandraunit.utils.EmbeddedCassandraServerHelper.startEmbeddedCassandra(EmbeddedCassandraServerHelper.java:56)
at com.charter.aesd.crossmso.wifi.dao.Connection.get(Connection.java:26)
at com.service.ClientTest.setup(ClientTest.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.internal.runners.ClassRoadie.runBefores(ClassRoadie.java:57)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at o rg.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: java.nio.file.FileSystemException: target\embeddedCassandra\commitlog\CommitLog-4-1470892233532.log: The process cannot access the file because it is being used by another process.
I am not getting ... why it is not able to create cassandra session using power mock runner....
Mocked the session also, then it runs without any errors.
replaced
session = Connection.get();
with
session = mock(Session.class);
I can't get Powermock work with TestNG. The same code adjusted to JUnit works fine, but somehow in TestNG it fails.
TestNG version is 6.8.21
Powermockito version is 1.6.1
package p;
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
#PrepareForTest({FooTest.class})
public class FooTest {
#BeforeTest
public void setup() {
mockStatic(FooTest.class);
MockitoAnnotations.initMocks(this);
}
#Test
public void test() throws Exception {
PowerMockito.doNothing().when(FooTest.class,"foo");
FooTest.foo();
Assert.assertEquals(1, 1);
}
public static void foo() throws Exception {
throw new Exception("huh?");
}
}
The exception I get is on the when method:
java.lang.Exception: huh?
at p.FooTest.foo(FooTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:1873)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:773)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:753)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:466)
at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:106)
at p.FooTest.test(FooTest.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:696)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:882)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1189)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
at org.testng.SuiteRunner.run(SuiteRunner.java:254)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:125)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:130)
===============================================
Custom suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
So what am I missing here?
I suspect this may be the same issue and solution as this question. In other words make sure you are using the org.powermock.modules.testng.PowerMockObjectFactory. But as #fge says, you should #PrepareForTest the class containing the static method(s) to mock, which should not be the test class itself...
I've written a simple RestEasy client proxy to perform an iTunes search. It looks like this:
#Path("/")
public interface AppleAppStoreLookupClient {
/**
* Attempts to lookup an apple app store item by its ID
*
* #param id
* The item ID
* #return The app details
*/
#GET
#Path("/lookup")
#Produces(value = { "text/javascript" })
public AppleAppDetailsResponse lookupByID(#QueryParam("id") String id);
}
My JSON model class is simple, as well. In fact, for the first call all I want is the "resultCount" value, just to make sure connectivity works.
#XmlRootElement
#XmlAccessorType(XmlAccessType.NONE)
public class AppleAppDetailsResponse implements Serializable {
private static final long serialVersionUID = 8881587082097337598L;
#XmlElement
private int resultCount = -1;
...getters and setters...
}
However, when I run a simple test, I get the following Exception:
org.jboss.resteasy.client.ClientResponseFailure: Unable to find a MessageBodyReader of content-type text/javascript;charset="utf-8" and type class net.odyssi.mms.appstore.apple.AppleAppDetailsResponse
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:523)
at org.jboss.resteasy.client.core.BaseClientResponse.createResponseFailure(BaseClientResponse.java:514)
at org.jboss.resteasy.client.core.BaseClientResponse.readFrom(BaseClientResponse.java:415)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:377)
at org.jboss.resteasy.client.core.BaseClientResponse.getEntity(BaseClientResponse.java:350)
at org.jboss.resteasy.client.core.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
at org.jboss.resteasy.client.core.ClientInvoker.invoke(ClientInvoker.java:126)
at org.jboss.resteasy.client.core.ClientProxy.invoke(ClientProxy.java:88)
at $Proxy21.lookupByID(Unknown Source)
at net.odyssi.mms.appstore.apple.test.AppleAppStoreLookupClientTest.testLookupByID(AppleAppStoreLookupClientTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
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)
I'm running RestEasy 2.3.6. Any idea what could be causing such an error?
Do you have a json provider on your classpath? If you are using maven, try adding this dependency:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jettison-provider</artifactId>
<version>2.3.6.Final</version>
</dependency>
http://docs.jboss.org/resteasy/docs/2.3.6.Final/userguide/html_single/#JAXB_+_JSON_provider
EDIT:
Normally, one would use the content type application/json and not text/javascript. I'm not sure why you are using text/javascript?
Anyways, if your endpoint returns only text/javascript, you can always modify the Content-Type-header in an interceptor:
ResteasyProviderFactory factory = new ResteasyProviderFactory();
RegisterBuiltin.register(factory);
factory.getClientExecutionInterceptorRegistry().register(
new ClientExecutionInterceptor() {
#Override
public ClientResponse execute(ClientExecutionContext ctx) throws Exception {
ClientResponse response = ctx.proceed();
if("text/javascript".equals(response.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE))){
response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
}
return response;
}
});
ProxyFactory.create(Service.class, URI.create("http://url-to-your-sevice"), new ApacheHttpClient4Executor(), factory);
I am trying to implement a JUnit test to test an actor.
I have this ActorTest :
import org.junit.Test;
import play.libs.Akka;
import playtests.PlayFrameworkTest;
import akka.actor.Actor;
import akka.actor.Props;
import akka.actor.UntypedActorFactory;
import akka.testkit.TestActorRef;
public class ActorTest {
public static FakeApplication dummy;
#BeforeClass
public static void startApp() {
dummy = Helpers.fakeApplication(Helpers.inMemoryDatabase());
Helpers.start(dummy);
}
#AfterClass
public static void stopApp() {
Helpers.stop(dummy);
}
#Test
public void test() throws Exception {
final String myParameter = "someParameter";
#SuppressWarnings("serial")
TestActorRef<MyActor> actorRef = TestActorRef.create(Akka.system(), new Props(new UntypedActorFactory() {
#Override
public Actor create() {
return new MyActor(myParameter);
}
}), "testActor");
MyActor actor = actorRef.underlyingActor();
String message = "message";
actor.apply(message);
actor.receive();
}
}
When I try to run it (both on eclipse and with 'play test' commandline) is I get this exception thrown at the line of the TestActorRef.create()
java.lang.NoClassDefFoundError: scala/concurrent/duration/Duration
at persistence.actors.ActorTest.test(ActorTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
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)
Caused by: java.lang.ClassNotFoundException: scala.concurrent.duration.Duration
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)
... 26 more
I have looked http://doc.akka.io/docs/akka/snapshot/java/testing.html
and
http://doc.akka.io/docs/akka/snapshot/scala/testing.html
and all I could find on the play framework page.
What am I missing? Why is it not running? I get the same exception if I get my system from Akka.system() and ActorSystem.apply() ... same thing when I pass it my fakeApplication or not.
(To summarise the comments aboveā¦) The class scala.concurrent.duration.Duration was first included with Scala 2.10. At the time of writing Akka 2.1 and Play 2.1 are the best releases to work with Scala 2.10.
I am testing a simple thing in my DB-Application. To create a product. For this I use Junit tests and here is the test that always fail, instead the expected result to turn green(passes)...
#Test
public void testCreate(){
Produkt test = new Produkt(20, "junit", "junitk", false, 900.67, true, true);
handler.createProdukt(test);
}
when I try it out simply with a main method(just creating a new Produkt and look if that works...) the create function works great and created this Produkt.
What am I doing wrong?
PS.: here is the code where I set up the tests:
#Before
public void setUp() throws SQLException, ClassNotFoundException{
try {
this.shandler = new ServiceHandler();
this.setServiceHandler(shandler);
manager.getConnection();
manager.getConnection().setAutoCommit(false);
} catch (SQLException ex) {
System.err.println("ERROR:");
ex.printStackTrace();
}
}
#After
public void tearDown() throws SQLException, ClassNotFoundException{
manager.getConnection().rollback();
manager.closeConnection();
}
UPDATE
I guess you mean the failure trace:
java.lang.NullPointerException at
tests.JUnitAbstractTests.testCreate(JUnitAbstractTests.java:35) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at
org.junit.runners.ParentRunner.run(ParentRunner.java:300) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
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)
Assuming your code snippets are accurate, your setUp() method instantiates a shandler field while your testCreate() test uses a handler field. And the stacktrace clearly shows that you have a NullPointerException in testCreate(). So the thing that you are doing wrong is trying to call a method on an object whose value is null.