0

I'm trying to write integration test with Citrus framework and I keep getting NullPointerException on http() line.

And here is the stacktrace.

java.lang.NullPointerException at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.http(TestNGCitrusTestDesigner.java:438) at com.test.tests.RestProviderIT.testGetUsers(RestAppIT.java:32) 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)

public class RestAppIT extends TestNGCitrusTestDesigner{

@Autowired
private HttpClient restClient;

@Test
@CitrusTest
public void testGetUsers() {
    http()
        .client(restClient)
        .send()
        .get("/comp/users")
        .accept(ContentType.APPLICATION_JSON.getMimeType());

    http()
    .client(restClient)
    .receive()
    .response(HttpStatus.OK)
    .messageType(ContentType.APPLICATION_JSON.getMimeType());
}
}

I have setup the endpointconfig class and defined the restClient there. Can you help me with this issue?

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • 1
    I tried following the Citrus http sample from here (https://github.com/citrusframework/citrus-samples/tree/master/samples-http/sample-http) – savvytester Mar 26 '19 at 16:26
  • I understand NPE if it's its in my code. But this seems to be coming from Citrus framework code and I'm trying to see if I i have missed any setup for HttpActionBuilder com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.http() object. The test stops at line http() which is from TestNGCitrusTestDesigner class. – savvytester Mar 26 '19 at 16:31
  • The obvious place to look is if the values sent to the failing method are null or not, so check `restClient` and the `getMimeType()` using a debugger or a `println()` – Joakim Danielson Mar 26 '19 at 16:44
  • I ran into the same problem. The solution was to remove the following lines from my build.gradle: "test { useTestNG }". When new users are following the tutorials, they are told to add that to their build.gradle but not told that they have to remove it to get their tests to work. – retrovius Sep 10 '19 at 23:27

1 Answers1

0

Looking at the source of the class that is throwing the NPE, TestNGCitrusTestDesigner, line 438 appears to attempt to execute a method on the testDesginer object, so it is likely this is null and that you need to initialise it.

adickinson
  • 553
  • 1
  • 3
  • 14
  • Thank you for your response! In the sample-http given, they are not initializing it anywhere. I'm trying to do the same as that sample to run it on my API. The sample says, once you extend your test with TestNGCitrusTestDesigner, that should take care of it. I just wanted to ask if anybody has seen this issue and how can I initiate that object so I can run the test successfully. – savvytester Mar 26 '19 at 16:47
  • Have you copied just the java source or did you copy the entirety of the config too? – adickinson Mar 26 '19 at 16:50
  • I just copied the java source. – savvytester Mar 26 '19 at 16:54
  • Then that's possibly why, the example has configuration that could set it up, I would look in to copying that too. – adickinson Mar 26 '19 at 16:59
  • Thank you! I will try that. – savvytester Mar 26 '19 at 17:03