Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically set Method type and content of a request #54

Open
ravijo opened this issue Nov 25, 2013 · 3 comments
Open

How to dynamically set Method type and content of a request #54

ravijo opened this issue Nov 25, 2013 · 3 comments

Comments

@ravijo
Copy link

ravijo commented Nov 25, 2013

I am newbie here. I have below two questions.

(1) How to set Method type without annotation? Is there any such method which can set the request method i.e. POST/GET?

(2) Most of our REST service, take JSON data as input. How I can set this JSON data without annotation? Since I need to pass these JSON data from an external file dynamically,so I can't use annotation. I saw a sample code here (https://github.com/andreasmihm/restfuse/blob/master/com.eclipsesource.restfuse.example/src/com/eclipsesource/restfuse/example/DynamicBodyTest.java) but I am using latest build of restfuse and unable to get RequestContext.setDynamicBody(String) method.

Please help.

@andreasmihm
Copy link

hi,
restfuse only works annotation-based,
but in this annotation you can specify an external file to be the content by using the file attribute of the HttpTest annotation,

does that solve your problem?

regards

@ravijo
Copy link
Author

ravijo commented Nov 26, 2013

Hi andreasmihm,

Thank you for your kind reply. I am trying to automate some REST services. Some of them are GET HTTP and POST HTTP, which takes json as an input. I am putting all my efforts below-

Here is the code link (http://ideone.com/plain/uinDuZ) or you can have a look below-

@RunWith(HttpJUnitRunner.class)
public class SimpleHttpTest {

@Rule
public Destination restFuse = getDestination();

@Context
private Response response;

@HttpTest(method = Method.POST, content = "{\"username\":\"demouser\", \"password\":\"demopassword\", \"id\":\"application\"}", path = "{path}")
public void login_with_valid_credentail() {
    //Method type is not dynamically configurable :(
    //content is  not dynamically configurable :(
    System.out.println("response=" + response.getBody());
    //dummy code to test
    assertOk(response);
}

private Destination getDestination() {
    //destination is dynamically configurable from here
    final Destination destination = new Destination(this,"http://192.168.16.217:8080");
    RequestContext context = destination.getRequestContext();
    //path is dynamically configurable from here
    context.addPathSegment("path","services/authentication/login");
    //'Content-Type' is dynamically configurable from here
    context.addHeader("Content-Type", "application/json");
    return destination;
}

}

My points questions are below-
(1) How to set method type (GET/POST/PUT/DELETE) dynamically?
(2) How to set content dynamically, which needs to be set for some REST services?

Regards
Ravi

@vikash002
Copy link

please update the maven repo. there is no image of master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants