Search in sources :

Example 21 with ManagementResponse

use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.

the class LatestManagementControllerAdapterTest method handleGet.

@Test
public void handleGet() throws Exception {
    final String hostName = "test";
    final String queueName = "foo";
    final QueueManagingVirtualHost<?> virtualHost = createTestVirtualHost(hostName);
    virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, queueName));
    final String nodeName = virtualHost.getParent().getName();
    final ManagementRequest request = mockManagementRequest(virtualHost.getBroker(), "GET", "queue", Arrays.asList(nodeName, hostName), Collections.singletonMap("name", Collections.singletonList("foo")));
    final ManagementResponse response = _adapter.handleGet(request);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(200)));
    assertThat(response.getBody(), is(notNullValue()));
    assertThat(response.getBody(), is(instanceOf(Collection.class)));
    final Collection data = (Collection) response.getBody();
    assertThat(data.size(), is(equalTo(1)));
    final Object object = data.iterator().next();
    assertThat(object, is(notNullValue()));
    assertThat(object, is(instanceOf(LegacyConfiguredObject.class)));
    assertThat(((LegacyConfiguredObject) object).getAttribute(LegacyConfiguredObject.NAME), is(equalTo("foo")));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Collection(java.util.Collection) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 22 with ManagementResponse

use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.

the class LatestManagementControllerAdapterTest method handlePut.

@Test
public void handlePut() throws Exception {
    final String hostName = "test";
    final String queueName = "foo";
    final QueueManagingVirtualHost<?> virtualHost = createTestVirtualHost(hostName);
    final String nodeName = virtualHost.getParent().getName();
    final Broker root = virtualHost.getBroker();
    final ManagementRequest request = mockManagementRequest(root, "PUT", "queue", Arrays.asList(nodeName, hostName), Collections.emptyMap());
    when(request.getBody(LinkedHashMap.class)).thenReturn(new LinkedHashMap<String, Object>(Collections.singletonMap("name", queueName)));
    when(request.getRequestURL()).thenReturn("test");
    final ManagementResponse response = _adapter.handlePut(request);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(201)));
    assertThat(response.getBody(), is(notNullValue()));
    assertThat(response.getBody(), is(instanceOf(LegacyConfiguredObject.class)));
    final LegacyConfiguredObject object = (LegacyConfiguredObject) response.getBody();
    assertThat(object.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("foo")));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Broker(org.apache.qpid.server.model.Broker) 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 23 with ManagementResponse

use of org.apache.qpid.server.management.plugin.ManagementResponse in project qpid-broker-j by apache.

the class RestServlet method doPost.

@Override
protected void doPost(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.handlePost(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