Search in sources :

Example 6 with ManagementResponse

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")));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Queue(org.apache.qpid.server.model.Queue) Test(org.junit.Test)

Example 7 with ManagementResponse

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)));
}
Also used : HashMap(java.util.HashMap) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 8 with ManagementResponse

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())));
}
Also used : Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 9 with ManagementResponse

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);
    }
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ManagementController(org.apache.qpid.server.management.plugin.ManagementController)

Example 10 with ManagementResponse

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);
    }
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementException(org.apache.qpid.server.management.plugin.ManagementException) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ManagementController(org.apache.qpid.server.management.plugin.ManagementController)

Aggregations

ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)23 Test (org.junit.Test)17 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)14 ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)11 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)11 ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)7 HashMap (java.util.HashMap)5 ManagementController (org.apache.qpid.server.management.plugin.ManagementController)5 ManagementException (org.apache.qpid.server.management.plugin.ManagementException)5 Collection (java.util.Collection)4 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UUID (java.util.UUID)2 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)2 Binding (org.apache.qpid.server.model.Binding)2 Broker (org.apache.qpid.server.model.Broker)2 Queue (org.apache.qpid.server.model.Queue)2 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1