use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.
the class LatestManagementControllerTest method handleGetForBrokerRootAndQueueSingletonPath.
@Test
public void handleGetForBrokerRootAndQueueSingletonPath() throws Exception {
final String hostName = "test";
final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
final String nodeName = virtualHost.getParent().getName();
final ManagementRequest request = mock(ManagementRequest.class);
when(request.getCategory()).thenReturn("queue");
doReturn(virtualHost.getBroker()).when(request).getRoot();
when(request.getPath()).thenReturn(Arrays.asList(nodeName, hostName, "foo"));
when(request.getMethod()).thenReturn("GET");
final ManagementResponse response = _controller.handleGet(request);
assertThat(response, is(notNullValue()));
assertThat(response.getResponseCode(), is(equalTo(200)));
assertThat(response.getBody(), is(notNullValue()));
assertThat(response.getBody(), is(instanceOf(Queue.class)));
final Queue data = (Queue) response.getBody();
assertThat(data.getName(), is(equalTo("foo")));
}
use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.
the class LatestManagementControllerTest method invoke.
@Test
public void invoke() throws Exception {
final String hostName = "test";
final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
List<String> path = Arrays.asList(virtualHost.getParent().getName(), hostName);
Map<String, Object> message = new HashMap<>();
message.put("address", "foo");
message.put("persistent", "false");
message.put("content", "Test Content");
message.put("mimeType", "text/plain");
ManagementResponse response = _controller.invoke(virtualHost.getBroker(), "virtualhost", path, "publishMessage", Collections.singletonMap("message", message), true, true);
assertThat(response, is(notNullValue()));
assertThat(response.getResponseCode(), is(equalTo(200)));
Object body = response.getBody();
assertThat(body, is(instanceOf(Number.class)));
assertThat(((Number) body).intValue(), is(equalTo(1)));
}
use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.
the class BindingControllerTest method invoke.
@Test
public void invoke() {
final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
final String operationName = "getStatistics";
final Map<String, Object> parameters = Collections.emptyMap();
final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
when(_managementController.getCategoryHierarchy(_root, "Binding")).thenReturn(hierarchy);
final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
when(exchange.getCategory()).thenReturn("Exchange");
final LegacyConfiguredObject vh = mock(LegacyConfiguredObject.class);
when(exchange.getParent("VirtualHost")).thenReturn(vh);
final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
final Collection<LegacyConfiguredObject> queues = Collections.singletonList(queue);
when(vh.getChildren("Queue")).thenReturn(queues);
final Binding binding = mock(Binding.class);
when(binding.getName()).thenReturn("my-binding");
when(binding.getDestination()).thenReturn("my-queue");
when(binding.getBindingKey()).thenReturn("my-binding");
final Collection<Binding> bindings = Collections.singletonList(binding);
when(exchange.getAttribute("bindings")).thenReturn(bindings);
final Collection<LegacyConfiguredObject> exchanges = Collections.singletonList(exchange);
doReturn(exchanges).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
final ManagementResponse result = _controller.invoke(_root, path, operationName, parameters, true, true);
assertThat(result, is(notNullValue()));
assertThat(result.getResponseCode(), is(equalTo(200)));
assertThat(result.getBody(), is(notNullValue()));
assertThat(result.getBody(), is(equalTo(Collections.emptyMap())));
}
use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.
the class RestServlet method doDelete.
@Override
protected void doDelete(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
try {
final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
final ManagementController controller = getManagementController();
final ManagementResponse response = controller.handleDelete(request);
sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
} catch (ManagementException e) {
sendResponse(e, httpServletRequest, httpServletResponse);
}
}
use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.
the class RestServlet method doPut.
@Override
protected void doPut(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
try {
final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
final ManagementController controller = getManagementController();
final ManagementResponse response = controller.handlePut(request);
sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
} catch (ManagementException e) {
sendResponse(e, httpServletRequest, httpServletResponse);
}
}
Aggregations