0 Replies Latest reply on Dec 31, 2009 7:59 AM by Chao Cui

    Problems When Testing Resteasy Class

    Chao Cui Newbie
      I got a problem when I'm trying to test the resteasy interface,but when I browse the url:http://localhost:8080/cmanager/seam/resource/rest/record/24, it works well.
      actually I follow the steps in the seam_reference.I use the junit4 to test it.
      Any insight would be appreciated!

      error:
      java.lang.NullPointerException
           at org.jboss.seam.resteasy.testfwk.ResourceSeamTest$ResourceRequest.run(ResourceSeamTest.java:126)
           at com.mydomain.cmanager.test.MyTest.test(MyTest.java:37)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           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.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
           at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
           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:220)
           at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
           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)


      My test class is :

      package com.mydomain.cmanager.test;
      import java.util.HashMap;
      import java.util.Map;
      import org.jboss.seam.resteasy.testfwk.ResourceSeamTest;
      import org.jboss.seam.resteasy.testfwk.MockHttpServletResponse;
      import org.jboss.seam.resteasy.testfwk.MockHttpServletRequest;
      import org.junit.Test;
      public class MyTest extends ResourceSeamTest {
           @Override
           public Map<String, Object> getDefaultHeaders()
           {
                return new HashMap<String, Object>()
                {{
                     put("Accept", "text/plain");
                }};
           }
           @Test
           public void test() throws Exception
           {
                new ResourceRequest(Method.GET, "http://localhost:8080/cmanager/seam/resource/rest/record/24")
                {
                     @Override
                     protected void prepareRequest(MockHttpServletRequest request)
                     {
                          request.addHeader("Accept-Language", "en_US, de");
                     }
                     @Override
                     protected void onResponse(MockHttpServletResponse response)
                     {
                          assert response.getStatus() == 200;                                  }
                }.run();
                 }
      }