Making reusable web service calls

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Making reusable web service calls

hkoko
Hi,
We would like to make calls with Citrus framework according to the http-sample.
   
 @Test
    @Parameters("context")
    @CitrusTest(name = "Get tokens")
    public void login(@Optional @CitrusResource final TestContext context) {
        WSRepository ws = new WSRepository();
        ws.login("","");
    }

I removed all test annotations except for content and I put everything on a separated class with parameters to the functions. Only in this case the  http()
.client(...) call is exiting with:

java.lang.NullPointerException
        at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.http(TestNGCitrusTestDesigner.java:489)
        at com.consol.citrus.rest.WebServiceCallingRepository.login(WSRepository.java:89)
        at com.consol.citrus.rest.FrontToEndTest_new.login(FrontToEndTest_new.java:34)
        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:498)
        at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:216)
        at com.consol.citrus.dsl.testng.TestNGCitrusTest.invokeTestMethod(TestNGCitrusTest.java:121)
        at com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner.invokeTestMethod(TestNGCitrusTestDesigner.java:73)
        at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:100)
        at com.consol.citrus.dsl.testng.TestNGCitrusTest.run(TestNGCitrusTest.java:58)
        at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:209)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
        at org.testng.TestRunner.privateRun(TestRunner.java:782)
        at org.testng.TestRunner.run(TestRunner.java:632)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
        at org.testng.SuiteRunner.run(SuiteRunner.java:268)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
        at org.testng.TestNG.run(TestNG.java:1064)
        at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
        at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:127)

Do you have idea what I may do wrongly?
Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Making reusable web service calls

Christoph Deppisch
Administrator
By removing the annotations you are breaking the test initialization steps and this leads to the non initialized test state.

You can simply use the soap() Java DSL for making SOAP calls in Citrus. http://www.citrusframework.org/reference/html/soap.html 
Reply | Threaded
Open this post in threaded view
|

Re: Making reusable web service calls

hkoko
These are REST calls, however I think the structure is the same.
Unfortunately I don`t know what I do wrongly.

package com.consol.citrus.rest;

import com.consol.citrus.context.TestContext;
import com.consol.citrus.http.client.HttpClient;
import com.consol.citrus.message.Message;
import com.consol.citrus.validation.callback.ValidationCallback;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.ReadContext;
import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import static com.consol.citrus.dsl.endpoint.CitrusEndpoints.http;
import static com.consol.citrus.message.MessageType.JSON;

public class WebServiceTestRepository {

    private Logger LOGGER;
    private HttpClient authService;


    public void login(String username, String password) {
        http().client(authService)
              .send()....;

    }
}

On the authService in IntelliJ idea there is an error, which says client() in ClientServerEndPointBuilder cannot be applied to com.consol.citrus.http.client.HttpClient.

Thank you.
Best regards,
Kornel