Search in sources :

Example 26 with Person

use of org.apache.servicecomb.demo.compute.Person in project incubator-servicecomb-java-chassis by apache.

the class JaxrsClient method testExchange.

private static void testExchange(RestTemplate template, String cseUrlPrefix) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON);
    Person person = new Person();
    person.setName("world");
    HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
    ResponseEntity<Person> resEntity = template.exchange(cseUrlPrefix + "/compute/sayhello", HttpMethod.POST, requestEntity, Person.class);
    TestMgr.check("hello world", resEntity.getBody());
    ResponseEntity<String> resEntity2 = template.exchange(cseUrlPrefix + "/compute/addstring?s=abc&s=def", HttpMethod.DELETE, null, String.class);
    TestMgr.check("abcdef", resEntity2.getBody());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Person(org.apache.servicecomb.demo.compute.Person)

Example 27 with Person

use of org.apache.servicecomb.demo.compute.Person in project incubator-servicecomb-java-chassis by apache.

the class JaxrsClient method testPost.

private static void testPost(RestTemplate template, String cseUrlPrefix) {
    Map<String, String> params = new HashMap<>();
    params.put("a", "5");
    params.put("b", "3");
    int result = template.postForObject(cseUrlPrefix + "/compute/add", params, Integer.class);
    TestMgr.check(8, result);
    Person person = new Person();
    person.setName("world");
    Person resultPerson = template.postForObject(cseUrlPrefix + "/compute/sayhello", person, Person.class);
    TestMgr.check("hello world", resultPerson.getName());
    HttpHeaders headers = new HttpHeaders();
    headers.add("prefix", "haha");
    HttpEntity<Person> reqEntity = new HttpEntity<>(person, headers);
    TestMgr.check("haha world", template.postForObject(cseUrlPrefix + "/compute/saysomething", reqEntity, String.class));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) HashMap(java.util.HashMap) Person(org.apache.servicecomb.demo.compute.Person)

Example 28 with Person

use of org.apache.servicecomb.demo.compute.Person in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstPojoClient method testCodeFirstSayHello.

protected void testCodeFirstSayHello(CodeFirstPojoIntf codeFirst) {
    Person input = new Person();
    input.setName("person name");
    Person result = codeFirst.sayHello(input);
    TestMgr.check("hello person name", result.getName());
}
Also used : Person(org.apache.servicecomb.demo.compute.Person)

Example 29 with Person

use of org.apache.servicecomb.demo.compute.Person in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstRestTemplate method testModelFieldIgnore.

protected void testModelFieldIgnore(RestTemplate template, String cseUrlPrefix) {
    InputModelForTestIgnore input = new InputModelForTestIgnore("input_id_rest", "input_id_content", new Person("inputSomeone"), new JsonObject("{\"InputJsonKey\" : \"InputJsonValue\"}"), () -> {
    });
    OutputModelForTestIgnore output = template.postForObject(cseUrlPrefix + "ignore", input, OutputModelForTestIgnore.class);
    TestMgr.check(null, output.getInputId());
    TestMgr.check(input.getContent(), output.getContent());
    TestMgr.check(null, output.getOutputId());
    TestMgr.check(null, output.getInputIgnoreInterface());
    TestMgr.check(null, output.getInputJsonObject());
    TestMgr.check(null, output.getInputObject());
    TestMgr.check(null, output.getOutputIgnoreInterface());
    TestMgr.check(null, output.getOutputJsonObject());
    TestMgr.check(null, output.getOutputObject());
}
Also used : InputModelForTestIgnore(org.apache.servicecomb.demo.ignore.InputModelForTestIgnore) OutputModelForTestIgnore(org.apache.servicecomb.demo.ignore.OutputModelForTestIgnore) JsonObject(io.vertx.core.json.JsonObject) Person(org.apache.servicecomb.demo.compute.Person)

Example 30 with Person

use of org.apache.servicecomb.demo.compute.Person in project incubator-servicecomb-java-chassis by apache.

the class CodeFirstRestTemplate method testCodeFirstSayHello.

protected void testCodeFirstSayHello(RestTemplate template, String cseUrlPrefix) {
    Map<String, String> persionFieldMap = new HashMap<>();
    persionFieldMap.put("name", "person name from map");
    Person result = template.postForObject(cseUrlPrefix + "sayhello", persionFieldMap, Person.class);
    TestMgr.check("hello person name from map", result);
    Person input = new Person();
    input.setName("person name from Object");
    result = template.postForObject(cseUrlPrefix + "sayhello", input, Person.class);
    TestMgr.check("hello person name from Object", result);
}
Also used : HashMap(java.util.HashMap) Person(org.apache.servicecomb.demo.compute.Person)

Aggregations

Person (org.apache.servicecomb.demo.compute.Person)36 Test (org.junit.Test)16 HttpEntity (org.springframework.http.HttpEntity)13 HttpHeaders (org.springframework.http.HttpHeaders)12 HashMap (java.util.HashMap)8 GenericParam (org.apache.servicecomb.demo.compute.GenericParam)4 JAXBPerson (org.apache.servicecomb.demo.jaxbbean.JAXBPerson)3 ResponseEntity (org.springframework.http.ResponseEntity)3 JsonObject (io.vertx.core.json.JsonObject)2 ArrayList (java.util.ArrayList)2 InputModelForTestIgnore (org.apache.servicecomb.demo.ignore.InputModelForTestIgnore)2 OutputModelForTestIgnore (org.apache.servicecomb.demo.ignore.OutputModelForTestIgnore)2 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2