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));
}
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")));
}
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)));
}
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);
}
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);
}
Aggregations