Search in sources :

Example 1 with MockResponse

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

the class ResponseModifierServiceTest method testEvaluateResponseSamePathFirstReturnOKNextFailed.

@Test
public void testEvaluateResponseSamePathFirstReturnOKNextFailed() throws Throwable {
    MockResponse mockResponse1 = createMockResponse(1, 200, "/path1", "get", "message1", "result");
    MockResponse mockResponse3 = createMockResponse(1, 400, "/path1", "get", "message2");
    underTest.addResponse(mockResponse1);
    underTest.addResponse(mockResponse3);
    String assertPath = "get_/path1";
    String actualPost = underTest.evaluateResponse("get_/path1", String.class, () -> "OK");
    assertEquals(actualPost, "result");
    assertException(assertPath, "400 message2", HttpStatus.BAD_REQUEST);
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) Test(org.junit.jupiter.api.Test)

Example 2 with MockResponse

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

the class ResponseModifierServiceTest method createMockResponse.

private MockResponse createMockResponse(int times, int code, String path, String method, String message, Object obj, Class clss) {
    MockResponse mockResponse = new MockResponse();
    mockResponse.setTimes(times);
    mockResponse.setStatusCode(code);
    mockResponse.setPath(path);
    mockResponse.setHttpMethod(method);
    mockResponse.setMessage(message);
    if (obj != null) {
        mockResponse.setClss(clss.getName());
        mockResponse.setResponse(obj);
    }
    return mockResponse;
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse)

Example 3 with MockResponse

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

the class ResponseModifierServiceTest method testEvaluateResponseNoPreDefinedResponse.

@Test
public void testEvaluateResponseNoPreDefinedResponse() throws Throwable {
    MockResponse mockResponse1 = createMockResponse(0, 200, "/path1", "get", "message1");
    underTest.addResponse(mockResponse1);
    String actualPost = underTest.evaluateResponse("get_/path2", String.class, () -> "OK");
    assertEquals(actualPost, "OK");
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) Test(org.junit.jupiter.api.Test)

Example 4 with MockResponse

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

the class ResponseModifierServiceTest method testEvaluateResponseWhenResponseEntity.

@Test
public void testEvaluateResponseWhenResponseEntity() throws Throwable {
    MockResponse mockResponse1 = createMockResponse(0, 200, "/path1", "get", null, "result");
    underTest.addResponse(mockResponse1);
    ResponseEntity<String> actualPost = underTest.evaluateResponse("get_/path1", ResponseEntity.class, () -> null);
    assertEquals(actualPost.getBody(), "result");
}
Also used : MockResponse(com.sequenceiq.mock.spi.MockResponse) Test(org.junit.jupiter.api.Test)

Example 5 with MockResponse

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

the class ResponseModifierServiceTest method testEvaluateResponseSamePathSameCodesButDifferentMessageAndTimes.

@Test
public // matter the order of the responses with the same path. Can add the response with the same code.
void testEvaluateResponseSamePathSameCodesButDifferentMessageAndTimes() {
    MockResponse mockResponse1 = createMockResponse(2, 400, "/path1", "get", "message1");
    MockResponse mockResponse3 = createMockResponse(1, 400, "/path1", "get", "message2");
    underTest.addResponse(mockResponse1);
    underTest.addResponse(mockResponse3);
    String assertPath = "get_/path1";
    assertException(assertPath, "400 message1", HttpStatus.BAD_REQUEST);
    assertException(assertPath, "400 message1", HttpStatus.BAD_REQUEST);
    assertException(assertPath, "400 message2", 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