use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testUpdateFunctionUploadFailure.
@Test
public void testUpdateFunctionUploadFailure() throws Exception {
mockStatic(Utils.class);
doThrow(new IOException("upload failure")).when(Utils.class);
Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
Response response = updateDefaultFunction();
assertEquals(Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
assertEquals(new ErrorData("upload failure").reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testDeregisterFunctionFailure.
@Test
public void testDeregisterFunctionFailure() throws Exception {
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
RequestResult rr = new RequestResult().setSuccess(false).setMessage("function failed to deregister");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.deregisterFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(requestResult);
Response response = deregisterDefaultFunction();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(new ErrorData(rr.getMessage()).reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testGetFunctionMissingArguments.
private void testGetFunctionMissingArguments(String tenant, String namespace, String function, String missingFieldName) throws IOException {
Response response = resource.getFunctionInfo(tenant, namespace, function);
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(new ErrorData(missingFieldName + " is not provided").reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testUpdateFunctionFailure.
@Test
public void testUpdateFunctionFailure() throws Exception {
mockStatic(Utils.class);
doNothing().when(Utils.class);
Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
RequestResult rr = new RequestResult().setSuccess(false).setMessage("function failed to register");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
Response response = updateDefaultFunction();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(new ErrorData(rr.getMessage()).reason, ((ErrorData) response.getEntity()).reason);
}
use of org.apache.pulsar.common.policies.data.ErrorData in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testRegisterFunctionFailure.
@Test
public void testRegisterFunctionFailure() throws Exception {
mockStatic(Utils.class);
doNothing().when(Utils.class);
Utils.uploadToBookeeper(any(Namespace.class), any(InputStream.class), anyString());
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(false);
RequestResult rr = new RequestResult().setSuccess(false).setMessage("function failed to register");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
Response response = registerDefaultFunction();
assertEquals(Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertEquals(new ErrorData(rr.getMessage()).reason, ((ErrorData) response.getEntity()).reason);
}
Aggregations