Search in sources :

Example 16 with ManagementResponse

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

the class BindingControllerTest method delete.

@Test
public void delete() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    doReturn(hierarchy).when(_managementController).getCategoryHierarchy(_root, "Binding");
    final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
    when(exchange.getCategory()).thenReturn("Exchange");
    when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    final ManagementResponse unbindingResult = new ControllerManagementResponse(ResponseType.DATA, Boolean.TRUE);
    when(exchange.invoke(eq("unbind"), any(), eq(true))).thenReturn(unbindingResult);
    doReturn(exchange).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    int result = _controller.delete(_root, path, Collections.emptyMap());
    assertThat(result, is(equalTo(1)));
    verify(exchange).invoke(eq("unbind"), any(), eq(true));
}
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) Test(org.junit.Test)

Example 17 with ManagementResponse

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

the class BindingControllerTest method createOrUpdate.

@Test
public void createOrUpdate() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange");
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", "my-binding");
    attributes.put("queue", "my-queue");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    doReturn(hierarchy).when(_managementController).getCategoryHierarchy(_root, "Binding");
    final LegacyConfiguredObject exchange = mock(LegacyConfiguredObject.class);
    when(exchange.getCategory()).thenReturn("Exchange");
    when(exchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    final ManagementResponse bindingResult = new ControllerManagementResponse(ResponseType.DATA, Boolean.TRUE);
    when(exchange.invoke(eq("bind"), any(), eq(true))).thenReturn(bindingResult);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(queue.getCategory()).thenReturn("Queue");
    when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    doReturn(exchange).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    doReturn(queue).when(_nextVersionManagementController).get(any(), eq("queue"), any(), any());
    when(_managementController.convertFromNextVersion(exchange)).thenReturn(exchange);
    when(_managementController.convertFromNextVersion(queue)).thenReturn(queue);
    final LegacyConfiguredObject binding = _controller.createOrUpdate(_root, path, attributes, true);
    assertThat(binding, is(notNullValue()));
    assertThat(binding.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-binding")));
    Object queueObject = binding.getAttribute("queue");
    Object exchangeObject = binding.getAttribute("exchange");
    assertThat(queueObject, is(instanceOf(LegacyConfiguredObject.class)));
    assertThat(exchangeObject, is(instanceOf(LegacyConfiguredObject.class)));
    assertThat(((LegacyConfiguredObject) queueObject).getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-queue")));
    assertThat(((LegacyConfiguredObject) exchangeObject).getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-exchange")));
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) HashMap(java.util.HashMap) 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) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Test(org.junit.Test)

Example 18 with ManagementResponse

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

the class ConsumerControllerTest method invoke.

@Test
public void invoke() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-session", "my-queue", "my-consumer");
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "session", "queue", "consumer");
    when(_managementController.getCategoryHierarchy(_root, "Consumer")).thenReturn(hierarchy);
    final LegacyConfiguredObject consumer = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    final LegacyConfiguredObject session = mock(LegacyConfiguredObject.class);
    when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    when(consumer.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-consumer");
    when(consumer.getAttribute("session")).thenReturn(session);
    when(session.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-session");
    final Object stats = mock(Object.class);
    final ManagementResponse statistics = new ControllerManagementResponse(ResponseType.DATA, stats);
    when(consumer.invoke(eq("getStatistics"), eq(Collections.emptyMap()), eq(false))).thenReturn(statistics);
    final Collection<LegacyConfiguredObject> consumers = Collections.singletonList(consumer);
    when(queue.getChildren(ConsumerController.TYPE)).thenReturn(consumers);
    final Collection<LegacyConfiguredObject> queues = Collections.singletonList(queue);
    doReturn(queues).when(_nextVersionManagementController).get(eq(_root), eq("Queue"), eq(Arrays.asList("my-vhn", "my-vh")), eq(Collections.emptyMap()));
    ManagementResponse response = _controller.invoke(_root, path, "getStatistics", Collections.emptyMap(), false, false);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(200)));
    assertThat(response.getBody(), is(notNullValue()));
    assertThat(response.getBody(), is(equalTo(stats)));
}
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) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) ControllerManagementResponse(org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse) Test(org.junit.Test)

Example 19 with ManagementResponse

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

the class AbstractLegacyConfiguredObjectControllerTest method invoke.

@Test
public void invoke() {
    final List<String> path = Collections.singletonList("test");
    final Map<String, Object> parameters = Collections.singletonMap("name", "test");
    final Object operationResult = mock(Object.class);
    final String operationName = "testOperation";
    final ManagementResponse managementResponse = new ControllerManagementResponse(ResponseType.DATA, operationResult);
    when(_categoryController2.invoke(_root, path, operationName, parameters, true, true)).thenReturn(managementResponse);
    final ManagementResponse result = _controller.invoke(_root, TEST_CATEGORY_2, path, operationName, parameters, true, true);
    assertThat(result, is(notNullValue()));
    assertThat(result.getResponseCode(), is(equalTo(200)));
    assertThat(result.getBody(), is(equalTo(operationResult)));
    verify(_categoryController2).invoke(_root, path, operationName, parameters, true, true);
}
Also used : ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 20 with ManagementResponse

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

the class GenericCategoryControllerTest method invoke.

@Test
public void invoke() {
    final List<String> path = Arrays.asList("test1", "test2");
    final String operationName = "testOperation";
    final Map<String, Object> operationParameters = Collections.singletonMap("testParam", "testValue");
    final LegacyConfiguredObject result = mock(LegacyConfiguredObject.class);
    when(result.getAttribute(LegacyConfiguredObject.TYPE)).thenReturn(DEFAULT_TYPE);
    final LegacyConfiguredObject convertedResult = mock(LegacyConfiguredObject.class);
    when(_nextVersionManagementController.get(eq(_root), eq(TEST_CATEGORY), eq(path), eq(Collections.emptyMap()))).thenReturn(result);
    when(_typeController.convertFromNextVersion(result)).thenReturn(convertedResult);
    final Object operationValue = "testValue";
    final ManagementResponse operationResult = new ControllerManagementResponse(ResponseType.DATA, operationValue);
    when(convertedResult.invoke(operationName, operationParameters, true)).thenReturn(operationResult);
    final ManagementResponse response = _controller.invoke(_root, path, operationName, operationParameters, true, true);
    assertThat(response, is(notNullValue()));
    assertThat(response.getResponseCode(), is(equalTo(200)));
    assertThat(response.getBody(), is(equalTo(operationValue)));
    verify(_nextVersionManagementController).get(_root, TEST_CATEGORY, path, Collections.emptyMap());
    verify(convertedResult).invoke(operationName, operationParameters, true);
}
Also used : ManagementResponse(org.apache.qpid.server.management.plugin.ManagementResponse) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) 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