Search in sources :

Example 21 with LegacyConfiguredObject

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

the class BindingControllerTest method get.

@Test
public void get() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-exchange", "my-queue", "my-binding");
    final Map<String, List<String>> parameters = Collections.singletonMap("actuals", Collections.singletonList("true"));
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "exchange", "queue", "binding");
    when(_managementController.getCategoryHierarchy(_root, "Binding")).thenReturn(hierarchy);
    final LegacyConfiguredObject exchange1 = mock(LegacyConfiguredObject.class);
    when(exchange1.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("foo");
    when(exchange1.getCategory()).thenReturn("Exchange");
    final LegacyConfiguredObject exchange2 = mock(LegacyConfiguredObject.class);
    when(exchange2.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-exchange");
    when(exchange2.getCategory()).thenReturn("Exchange");
    final LegacyConfiguredObject vh = mock(LegacyConfiguredObject.class);
    when(exchange2.getParent("VirtualHost")).thenReturn(vh);
    final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
    when(queue.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    final Collection<LegacyConfiguredObject> queues = Collections.singletonList(queue);
    when(vh.getChildren("Queue")).thenReturn(queues);
    final Binding binding = mock(Binding.class);
    when(binding.getName()).thenReturn("my-binding");
    when(binding.getDestination()).thenReturn("my-queue");
    when(binding.getBindingKey()).thenReturn("my-binding");
    final Collection<Binding> bindings = Collections.singletonList(binding);
    when(exchange2.getAttribute("bindings")).thenReturn(bindings);
    final Collection<LegacyConfiguredObject> exchanges = Arrays.asList(exchange1, exchange2);
    doReturn(exchanges).when(_nextVersionManagementController).get(any(), eq("exchange"), any(), any());
    final Object readResult = _controller.get(_root, path, parameters);
    assertThat(readResult, is(instanceOf(Collection.class)));
    final Collection<?> exchangeBindings = (Collection<?>) readResult;
    assertThat(exchangeBindings.size(), is(equalTo(1)));
    final Object object = exchangeBindings.iterator().next();
    assertThat(object, is(instanceOf(LegacyConfiguredObject.class)));
    final LegacyConfiguredObject bindingObject = (LegacyConfiguredObject) object;
    assertThat(bindingObject.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-binding")));
}
Also used : Binding(org.apache.qpid.server.model.Binding) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Collection(java.util.Collection) List(java.util.List) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Example 22 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject 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 23 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject 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 24 with LegacyConfiguredObject

use of org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject 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 25 with LegacyConfiguredObject

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

the class ConsumerControllerTest method get.

@Test
public void get() {
    final List<String> path = Arrays.asList("my-vhn", "my-vh", "my-session", "my-queue", "my-consumer");
    final Map<String, List<String>> parameters = Collections.singletonMap("actuals", Collections.singletonList("true"));
    final List<String> hierarchy = Arrays.asList("virtualhostnode", "virtualhost", "session", "queue", "consumer");
    when(_managementController.getCategoryHierarchy(_root, "Consumer")).thenReturn(hierarchy);
    final LegacyConfiguredObject session = mock(LegacyConfiguredObject.class);
    when(session.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-session");
    when(session.getCategory()).thenReturn("Session");
    final LegacyConfiguredObject consumer = mock(LegacyConfiguredObject.class);
    when(consumer.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-consumer");
    when(consumer.getAttribute("session")).thenReturn(session);
    final Collection<LegacyConfiguredObject> consumers = Collections.singletonList(consumer);
    final LegacyConfiguredObject queue1 = mock(LegacyConfiguredObject.class);
    when(queue1.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue1");
    final LegacyConfiguredObject queue2 = mock(LegacyConfiguredObject.class);
    when(queue2.getAttribute(LegacyConfiguredObject.NAME)).thenReturn("my-queue");
    when(queue2.getChildren(ConsumerController.TYPE)).thenReturn(consumers);
    final Collection<LegacyConfiguredObject> queues = Arrays.asList(queue1, queue2);
    doReturn(queues).when(_nextVersionManagementController).get(eq(_root), eq("Queue"), eq(Arrays.asList("my-vhn", "my-vh")), eq(Collections.emptyMap()));
    final Object result = _controller.get(_root, path, parameters);
    assertThat(result, is(instanceOf(Collection.class)));
    Collection<?> consumerItems = (Collection<?>) result;
    assertThat(consumerItems.size(), is(equalTo(1)));
    final Object object = consumerItems.iterator().next();
    assertThat(object, is(instanceOf(LegacyConfiguredObject.class)));
    final LegacyConfiguredObject consumerObject = (LegacyConfiguredObject) object;
    assertThat(consumerObject.getAttribute(LegacyConfiguredObject.NAME), is(equalTo("my-consumer")));
    assertThat(consumerObject.getCategory(), is(equalTo("Consumer")));
}
Also used : LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Collection(java.util.Collection) List(java.util.List) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) LegacyConfiguredObject(org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject) Test(org.junit.Test)

Aggregations

LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)37 Test (org.junit.Test)28 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)22 Collection (java.util.Collection)11 ManagementResponse (org.apache.qpid.server.management.plugin.ManagementResponse)10 HashMap (java.util.HashMap)9 List (java.util.List)7 Map (java.util.Map)7 ControllerManagementResponse (org.apache.qpid.server.management.plugin.controller.ControllerManagementResponse)7 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)6 Binding (org.apache.qpid.server.model.Binding)5 ManagementRequest (org.apache.qpid.server.management.plugin.ManagementRequest)4 LinkedHashMap (java.util.LinkedHashMap)3 CategoryController (org.apache.qpid.server.management.plugin.controller.CategoryController)3 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)3 Broker (org.apache.qpid.server.model.Broker)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ManagementException (org.apache.qpid.server.management.plugin.ManagementException)2