Skip to content

carlfei/spring-boot-simple-test-endPoint-api-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@Test void testStateRestBuilderAll(){

    URI uri = UriComponentsBuilder
            .fromHttpUrl("http://127.0.0.1:9090/coches/all")
            .build().encode().toUri();
    RequestEntity<Object> requestEntity = new RequestEntity<>(HttpMethod.GET, uri);
    ResponseEntity<String> responseEntity = new RestTemplate().exchange(requestEntity, String.class);
    String response = responseEntity.getBody();

    Gson gson = new Gson();
    String jsonString = gson.toJson(methodCreation());
    assertEquals(jsonString,response);
}

imagen

@Test
void testStateRestBuilderId(){
    int indice = 1;
    URI uri = UriComponentsBuilder
            .fromHttpUrl("http://127.0.0.1:9090/coches/"+""+indice)
            .build().encode().toUri();
    RequestEntity<Object> requestEntity = new RequestEntity<>(HttpMethod.GET, uri);
    ResponseEntity<String> responseEntity = new RestTemplate().exchange(requestEntity, String.class);
    String response = responseEntity.getBody();

    assertEquals(methodCreation(indice),response);

}

imagen

imagen

About

Simple testing endpoint api-rest in spring-boot with RestTemplate

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages