Search in sources :

Example 16 with Person

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

the class CodeFirstRestTemplate method testModelFieldIgnore.

private 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) JAXBPerson(org.apache.servicecomb.demo.jaxbbean.JAXBPerson) Person(org.apache.servicecomb.demo.compute.Person)

Example 17 with Person

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

the class SpringMvcIntegrationTestBase method ableToPostObjectAsJson.

@Test
public void ableToPostObjectAsJson() throws Exception {
    Map<String, String> personFieldMap = new HashMap<>();
    personFieldMap.put("name", "person name from map");
    Person person = restTemplate.postForObject(codeFirstUrl + "sayhello", jsonRequest(personFieldMap), Person.class);
    assertThat(person.toString(), is("hello person name from map"));
    Person input = new Person();
    input.setName("person name from Object");
    person = restTemplate.postForObject(codeFirstUrl + "sayhello", jsonRequest(input), Person.class);
    assertThat(person.toString(), is("hello person name from Object"));
    ListenableFuture<ResponseEntity<Person>> listenableFuture = asyncRestTemplate.postForEntity(codeFirstUrl + "sayhello", jsonRequest(personFieldMap), Person.class);
    ResponseEntity<Person> futureResponse = listenableFuture.get();
    person = futureResponse.getBody();
    assertThat(person.toString(), is("hello person name from map"));
    listenableFuture = asyncRestTemplate.postForEntity(codeFirstUrl + "sayhello", jsonRequest(input), Person.class);
    futureResponse = listenableFuture.get();
    person = futureResponse.getBody();
    assertThat(person.toString(), is("hello person name from Object"));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) Person(org.apache.servicecomb.demo.compute.Person) Test(org.junit.Test)

Example 18 with Person

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

the class SpringMvcIntegrationTestBase method ableToPostWithHeader.

@Test
public void ableToPostWithHeader() throws Exception {
    Person person = new Person();
    person.setName("person name");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(APPLICATION_JSON);
    headers.add("prefix", "prefix  prefix");
    HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
    ResponseEntity<String> responseEntity = restTemplate.postForEntity(codeFirstUrl + "saysomething", requestEntity, String.class);
    assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix  prefix person name"));
    ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate.postForEntity(codeFirstUrl + "saysomething", requestEntity, String.class);
    responseEntity = listenableFuture.get();
    assertThat(jsonOf(responseEntity.getBody(), String.class), is("prefix  prefix person name"));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) Person(org.apache.servicecomb.demo.compute.Person) Test(org.junit.Test)

Example 19 with Person

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

the class JaxrsIntegrationTestBase method ableToPostObjectAsJson.

@Test
public void ableToPostObjectAsJson() {
    Map<String, String> personFieldMap = new HashMap<>();
    personFieldMap.put("name", "person name from map");
    for (String url : urls) {
        Person person = restTemplate.postForObject(url + "sayhello", jsonRequest(personFieldMap), Person.class);
        assertEquals("hello person name from map", person.toString());
        Person input = new Person();
        input.setName("person name from Object");
        person = restTemplate.postForObject(url + "sayhello", jsonRequest(input), Person.class);
        assertEquals("hello person name from Object", person.toString());
    }
}
Also used : HashMap(java.util.HashMap) Person(org.apache.servicecomb.demo.compute.Person) Test(org.junit.Test)

Example 20 with Person

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

the class JaxrsIntegrationTestBase method ableToPostWithHeaderWithIdentifier.

@Test
public void ableToPostWithHeaderWithIdentifier() {
    Person person = new Person();
    person.setName("person name");
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(APPLICATION_JSON);
    headers.add("prefix-test", "prefix  prefix");
    HttpEntity<Person> requestEntity = new HttpEntity<>(person, headers);
    for (String url : urls) {
        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url + "saysomething1", requestEntity, String.class);
        assertEquals("prefix  prefix person name", jsonBodyOf(responseEntity, String.class));
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) Person(org.apache.servicecomb.demo.compute.Person) Test(org.junit.Test)

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