use of org.apache.qpid.server.management.plugin.ManagementRequest in project qpid-broker-j by apache.
the class LatestManagementControllerAdapterTest method createOrUpdate.
@Test
public void createOrUpdate() 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 Object response = _adapter.createOrUpdate(virtualHost.getBroker(), "queue", Arrays.asList(nodeName, hostName), Collections.singletonMap("name", queueName), true);
assertThat(response, is(instanceOf(LegacyConfiguredObject.class)));
final LegacyConfiguredObject object = (LegacyConfiguredObject) response;
assertThat(object.getAttribute(LegacyConfiguredObject.NAME), is(equalTo(queueName)));
}
use of org.apache.qpid.server.management.plugin.ManagementRequest in project qpid-broker-j by apache.
the class LatestManagementControllerAdapterTest method handlePut.
@Test
public void handlePut() 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, "PUT", "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.ManagementRequest in project qpid-broker-j by apache.
the class RestServlet method doPost.
@Override
protected void doPost(final HttpServletRequest httpServletRequest, final HttpServletResponse httpServletResponse, final ConfiguredObject<?> managedObject) throws IOException {
try {
final ManagementRequest request = new ServletManagementRequest(managedObject, httpServletRequest);
final ManagementController controller = getManagementController();
final ManagementResponse response = controller.handlePost(request);
sendResponse(request, response, httpServletRequest, httpServletResponse, controller);
} catch (ManagementException e) {
sendResponse(e, httpServletRequest, httpServletResponse);
}
}
Aggregations