Example usage for org.springframework.http HttpEntity getClass

List of usage examples for org.springframework.http HttpEntity getClass

Introduction

In this page you can find the example usage for org.springframework.http HttpEntity getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:gateway.test.ServiceTests.java

/**
 * Test PUT /service/{serviceId}//  w  ww  .  j  a  v a  2s  .co  m
 */
@Test
public void testUpdateMetadata() {
    // Mock
    HttpEntity<Service> request = new HttpEntity<Service>(null, null);
    doReturn(new ResponseEntity<PiazzaResponse>(new SuccessResponse("Yes", "Gateway"), HttpStatus.OK))
            .when(restTemplate).exchange(any(String.class), eq(HttpMethod.PUT), any(request.getClass()),
                    eq(SuccessResponse.class));

    // Test
    ResponseEntity<PiazzaResponse> entity = serviceController.updateService("123456", mockService, user);

    // Verify
    assertTrue(entity.getBody() instanceof SuccessResponse);

    // Test Exception
    doThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR)).when(restTemplate).exchange(
            any(String.class), eq(HttpMethod.PUT), any(request.getClass()), eq(SuccessResponse.class));
    ResponseEntity<PiazzaResponse> entity2 = serviceController.updateService("123456", mockService, user);
    assertTrue(entity2.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR));
    assertTrue(entity2.getBody() instanceof ErrorResponse);
}