Search in sources :

Example 1 with ManagementResponse

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

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

the class LatestManagementControllerAdapterTest method invoke.

@Test
public void invoke() throws Exception {
    final String hostName = "test";
    final String queueName = "foo";
    final QueueManagingVirtualHost<?> virtualHost = createTestVirtualHost(hostName);
    Queue queue = virtualHost.createChild(Queue.class, Collections.singletonMap(Queue.NAME, queueName));
    assertThat(virtualHost.getQueueCount(), is(equalTo(1L)));
    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 = _adapter.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)));
    assertThat(queue.getQueueDepthMessages(), is(equalTo(1)));
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Queue(org.apache.qpid.server.model.Queue) Test(org.junit.Test)

Example 3 with ManagementResponse

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

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

the class SessionControllerTest method convertNextVersionLegacyConfiguredObject.

@Test
public void convertNextVersionLegacyConfiguredObject() {
    final UUID sessionID = UUID.randomUUID();
    final LegacyConfiguredObject nextVersionSession = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject nextVersionConsumer = mock(LegacyConfiguredObject.class);
    when(nextVersionSession.getCategory()).thenReturn(SessionController.TYPE);
    when(nextVersionSession.getAttribute(LegacyConfiguredObject.ID)).thenReturn(sessionID);
    final ManagementResponse operationResult = new ControllerManagementResponse(ResponseType.MODEL_OBJECT, Collections.singletonList(nextVersionConsumer));
    when(nextVersionSession.invoke(eq("getConsumers"), eq(Collections.emptyMap()), eq(true))).thenReturn(operationResult);
    final LegacyConfiguredObject convertedConsumer = mock(LegacyConfiguredObject.class);
    when(_legacyManagementController.convertFromNextVersion(nextVersionConsumer)).thenReturn(convertedConsumer);
    final LegacyConfiguredObject convertedSession = _sessionController.convertNextVersionLegacyConfiguredObject(nextVersionSession);
    assertThat(convertedSession.getAttribute(LegacyConfiguredObject.ID), is(equalTo(sessionID)));
    final Collection<LegacyConfiguredObject> consumers = convertedSession.getChildren(ConsumerController.TYPE);
    assertThat(consumers, is(notNullValue()));
    assertThat(consumers.size(), is(equalTo(1)));
    assertThat(consumers.iterator().next(), is(equalTo(convertedConsumer)));
}
Also used : 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with ManagementResponse

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

the class GenericLegacyConfiguredObjectTest method invoke.

@Test
public void invoke() {
    final String operationName = "testOperation";
    final Map<String, Object> operationArguments = Collections.singletonMap("arg", "argValue");
    final String operationResult = "testOperationResult";
    final ControllerManagementResponse managementResponse = new ControllerManagementResponse(ResponseType.DATA, operationResult);
    when(_nextVersionLegacyConfiguredObject.invoke(operationName, operationArguments, true)).thenReturn(managementResponse);
    final ManagementResponse result = _object.invoke(operationName, operationArguments, true);
    assertThat(result, is(notNullValue()));
    assertThat(result.getResponseCode(), is(equalTo(200)));
    assertThat(result.getBody(), is(equalTo(operationResult)));
}
Also used : ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) Test(org.junit.Test)

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