Search in sources :

Example 11 with MockResponse

use of com.sequenceiq.mock.spi.MockResponse in project cloudbreak by hortonworks.

the class ResponseModifierServiceTest method testEvaluateResponseDifferentPathSameMethodsAndCodes.

@Test
public // doesn't matter the order of the responses
void testEvaluateResponseDifferentPathSameMethodsAndCodes() {
    MockResponse mockResponse1 = createMockResponse(1, 400, "/path1", "get", "message1");
    MockResponse mockResponse2 = createMockResponse(1, 400, "/path2", "get", "message2");
    underTest.addResponse(mockResponse1);
    underTest.addResponse(mockResponse2);
    assertException("get_/path2", "400 message2", HttpStatus.BAD_REQUEST);
    assertException("get_/path1", "400 message1", HttpStatus.BAD_REQUEST);
    assertNull(underTest.getResponse("get_/path1"));
    assertNull(underTest.getResponse("post_/path1"));
    assertNull(underTest.getResponse("delete_/path1"));
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) Test(org.junit.jupiter.api.Test)

Example 12 with MockResponse

use of com.sequenceiq.mock.spi.MockResponse in project cloudbreak by hortonworks.

the class ResponseModifierServiceTest method testEvaluateResponseWhenResponsePublicKeyAndTheReturnTypeAsTheSame.

@Test
public void testEvaluateResponseWhenResponsePublicKeyAndTheReturnTypeAsTheSame() throws Throwable {
    PublicKey publicKey = new PublicKey();
    publicKey.setPublicKey("hash");
    publicKey.setPublicKeyId("id");
    MockResponse mockResponse1 = createMockResponse(0, 200, "/path1", "get", null, publicKey);
    underTest.addResponse(mockResponse1);
    PublicKey actualPost = underTest.evaluateResponse("get_/path1", PublicKey.class, () -> null);
    assertEquals(actualPost.getPublicKey(), "hash");
    assertEquals(actualPost.getPublicKeyId(), "id");
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) PublicKey(com.sequenceiq.mock.spi.controller.PublicKey) Test(org.junit.jupiter.api.Test)

Example 13 with MockResponse

use of com.sequenceiq.mock.spi.MockResponse in project cloudbreak by hortonworks.

the class ResponseModifierServiceTest method testEvaluateResponseSamePathDifferentCodesAndTimes.

@Test
public // matter the order of the responses with the same path. Can add the response with the same code.
void testEvaluateResponseSamePathDifferentCodesAndTimes() {
    MockResponse mockResponse1 = createMockResponse(2, 400, "/path1", "get", "message1");
    MockResponse mockResponse2 = createMockResponse(1, 500, "/path1", "get", "message2");
    MockResponse mockResponse3 = createMockResponse(1, 400, "/path1", "get", "message3");
    underTest.addResponse(mockResponse1);
    underTest.addResponse(mockResponse2);
    underTest.addResponse(mockResponse3);
    String assertPath = "get_/path1";
    assertException(assertPath, "400 message1", HttpStatus.BAD_REQUEST);
    assertException(assertPath, "400 message1", HttpStatus.BAD_REQUEST);
    assertException(assertPath, "500 message2", HttpStatus.INTERNAL_SERVER_ERROR);
    assertException(assertPath, "400 message3", HttpStatus.BAD_REQUEST);
    List<MockResponse> actualResponses = underTest.getResponse(assertPath);
    assertNull(actualResponses);
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockResponse (com.sequenceiq.mock.spi.MockResponse)13 Test (org.junit.jupiter.api.Test)11 PublicKey (com.sequenceiq.mock.spi.controller.PublicKey)2 ApiCommand (com.sequenceiq.mock.swagger.model.ApiCommand)1