Search in sources :

Example 11 with ManagementRequest

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

the class LatestManagementControllerTest method handleGetForBrokerRootAndQueuePathWithFilter.

@Test
public void handleGetForBrokerRootAndQueuePathWithFilter() 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));
    when(request.getParameters()).thenReturn(Collections.singletonMap("name", Collections.singletonList("bar")));
    when(request.getMethod()).thenReturn("GET");
    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(Collection.class)));
    Collection data = (Collection) response.getBody();
    assertThat(data.size(), is(equalTo(1)));
    Object object = data.iterator().next();
    assertThat(object, is(notNullValue()));
    assertThat(object, is(instanceOf(Queue.class)));
    assertThat(((Queue) object).getName(), is(equalTo("bar")));
}
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) Test(org.junit.Test)

Example 12 with ManagementRequest

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

the class LatestManagementControllerTest method getRequestTypeForGetAndModelObjectWithFullPath.

@Test
public void getRequestTypeForGetAndModelObjectWithFullPath() 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();
    final List<String> path = Arrays.asList(virtualHost.getParent().getName(), hostName, "bar");
    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.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 13 with ManagementRequest

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

the class LatestManagementControllerTest method getRequestTypeForGetAndModelObjectWithNotFullPath.

@Test
public void getRequestTypeForGetAndModelObjectWithNotFullPath() 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();
    when(request.getPath()).thenReturn(Arrays.asList("*", hostName));
    when(request.getParameters()).thenReturn(Collections.emptyMap());
    when(request.getMethod()).thenReturn("GET");
    final RequestType type = _controller.getRequestType(request);
    assertThat(type, is(equalTo(RequestType.MODEL_OBJECT)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 14 with ManagementRequest

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

the class LatestManagementControllerTest method getRequestTypeForGetAndUserPreferences.

@Test
public void getRequestTypeForGetAndUserPreferences() 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", "userpreferences");
    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.USER_PREFERENCES)));
}
Also used : ManagementRequest(org.apache.qpid.server.management.plugin.ManagementRequest) RequestType(org.apache.qpid.server.management.plugin.RequestType) Test(org.junit.Test)

Example 15 with ManagementRequest

use of org.apache.qpid.server.management.plugin.ManagementRequest 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)

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