use of org.apache.pulsar.functions.worker.request.RequestResult in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testRegisterFunctionSuccess.
@Test
public void testRegisterFunctionSuccess() 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(true).setMessage("function registered");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.updateFunction(any(FunctionMetaData.class))).thenReturn(requestResult);
Response response = registerDefaultFunction();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
use of org.apache.pulsar.functions.worker.request.RequestResult in project incubator-pulsar by apache.
the class FunctionApiV2ResourceTest method testDeregisterFunctionSuccess.
@Test
public void testDeregisterFunctionSuccess() throws Exception {
when(mockedManager.containsFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(true);
RequestResult rr = new RequestResult().setSuccess(true).setMessage("function deregistered");
CompletableFuture<RequestResult> requestResult = CompletableFuture.completedFuture(rr);
when(mockedManager.deregisterFunction(eq(tenant), eq(namespace), eq(function))).thenReturn(requestResult);
Response response = deregisterDefaultFunction();
assertEquals(Status.OK.getStatusCode(), response.getStatus());
assertEquals(rr.toJson(), response.getEntity());
}
use of org.apache.pulsar.functions.worker.request.RequestResult 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.functions.worker.request.RequestResult 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.functions.worker.request.RequestResult 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