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