Search in sources :

Example 1 with ManagementRequest

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

the class LatestManagementControllerAdapterTest method handleDelete.

@Test
public void handleDelete() throws Exception {
    final String hostName = "test";
    final String queueName = "foo";
    final QueueManagingVirtualHost<?> virtualHost = createTestVirtualHost(hostName);
    virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, queueName));
    assertThat(virtualHost.getQueueCount(), is(equalTo(1L)));
    final String nodeName = virtualHost.getParent().getName();
    final ManagementRequest request = mockManagementRequest(virtualHost.getBroker(), "DELETE", "queue", Arrays.asList(nodeName, hostName), Collections.singletonMap("name", Collections.singletonList("foo")));
    final ManagementResponse response = _adapter.handleDelete(request);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(200)));
    assertThat(virtualHost.getQueueCount(), is(equalTo(0L)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Test(org.junit.Test)

Example 2 with ManagementRequest

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

the class LatestManagementControllerAdapterTest method mockManagementRequest.

private ManagementRequest mockManagementRequest(ConfiguredObject<?> root, String method, String category, List<String> path, Map<String, List<String>> parameters) {
    final ManagementRequest request = mock(ManagementRequest.class);
    when(request.getCategory()).thenReturn(category);
    doReturn(root).when(request).getRoot();
    when(request.getPath()).thenReturn(path);
    when(request.getParameters()).thenReturn(parameters);
    when(request.getMethod()).thenReturn(method);
    return request;
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest)

Example 3 with ManagementRequest

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

the class LatestManagementControllerAdapterTest method handlePost.

@Test
public void handlePost() 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, "POST", "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 4 with ManagementRequest

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

the class AbstractLegacyConfiguredObjectControllerTest method getRequestType.

@Test
public void getRequestType() {
    final Map<String, List<String>> parameters = Collections.singletonMap("name", Collections.singletonList("test"));
    final ManagementRequest managementRequest = mock(ManagementRequest.class);
    doReturn(_root).when(managementRequest).getRoot();
    when(managementRequest.getMethod()).thenReturn("GET");
    when(managementRequest.getParameters()).thenReturn(parameters);
    when(managementRequest.getPath()).thenReturn(Collections.singletonList("test"));
    when(managementRequest.getCategory()).thenReturn(TEST_CATEGORY_2);
    when(_controller.getCategory(_root)).thenReturn(TEST_CATEGORY);
    final RequestType requestType = _controller.getRequestType(managementRequest);
    assertThat(requestType, is(equalTo(RequestType.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) List(java.util.List) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 5 with ManagementRequest

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

the class LatestManagementControllerTest method getRequestTypeForGetAndVisiblePreferences.

@Test
public void getRequestTypeForGetAndVisiblePreferences() throws Exception {
    final String hostName = "test";
    final QueueManagingVirtualHost<?> virtualHost = createVirtualHostWithQueue(hostName, "foo", "bar");
    final ManagementRequest request = mock(ManagementRequest.class);
    when(request.getCategory()).thenReturn("queue");
    doReturn(virtualHost.getBroker()).when(request).getRoot();
    List<String> path = Arrays.asList(virtualHost.getParent().getName(), hostName, "bar", "visiblepreferences");
    when(request.getPath()).thenReturn(path);
    when(request.getParameters()).thenReturn(Collections.emptyMap());
    when(request.getMethod()).thenReturn("GET");
    final RequestType type = _controller.getRequestType(request);
    assertThat(type, is(equalTo(RequestType.VISIBLE_PREFERENCES)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Aggregations

ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)18 Test (org.junit.Test)13 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)11 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)6 RequestType (org.apache.qpid.server.management.plugin.RequestType)5 ManagementController (org.apache.qpid.server.management.plugin.ManagementController)4 ManagementException (org.apache.qpid.server.management.plugin.ManagementException)4 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)4 Collection (java.util.Collection)3 Broker (org.apache.qpid.server.model.Broker)3 Iterator (java.util.Iterator)1 List (java.util.List)1 Queue (org.apache.qpid.server.model.Queue)1