use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ShellCommandsControllerJUnitTest method testCommandHasRestApiControllerWebServiceEndpoint.
@Test
public void testCommandHasRestApiControllerWebServiceEndpoint() {
List<String> controllerWebServiceEndpoints = getControllerWebServiceEndpoints();
assertNotNull(controllerWebServiceEndpoints);
assertFalse(controllerWebServiceEndpoints.isEmpty());
LinkIndex linkIndex = controller.index("http");
assertNotNull(linkIndex);
assertFalse(linkIndex.isEmpty());
List<String> linkWebServiceEndpoints = new ArrayList<>(linkIndex.size());
for (Link link : linkIndex) {
linkWebServiceEndpoints.add(link.toHttpRequestLine());
}
assertEquals(linkIndex.size(), linkWebServiceEndpoints.size());
List<String> missingControllerWebServiceEndpoints = new ArrayList<>(linkWebServiceEndpoints);
missingControllerWebServiceEndpoints.removeAll(controllerWebServiceEndpoints);
assertTrue(String.format("The Management REST API Web Service Controllers in (%1$s) are missing the following REST API Web Service Endpoint(s): %2$s!", getClass().getPackage().getName(), missingControllerWebServiceEndpoints), missingControllerWebServiceEndpoints.isEmpty());
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method testFindAndResolveLink.
@Test
public void testFindAndResolveLink() throws Exception {
final Map<String, String> commandOptions = new HashMap<>();
commandOptions.put("name", "BarnesN'Noble");
Link link = getOperationInvoker().findLink(createCommandRequest("list-libraries", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries", toString(link.getHref()));
link = getOperationInvoker().findLink(createCommandRequest("get-library", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}", toString(link.getHref()));
commandOptions.put("author", "J.K.Rowling");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}", toString(link.getHref()));
commandOptions.put("category", "sci-fi");
commandOptions.put("year", "1998");
commandOptions.put("bogus", "data");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}/{year}", toString(link.getHref()));
commandOptions.remove("category");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{year}", toString(link.getHref()));
commandOptions.put("category", "fantasy");
commandOptions.put("isbn", "0-123456789");
commandOptions.put("title", "Harry Potter");
link = getOperationInvoker().findLink(createCommandRequest("add-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books", toString(link.getHref()));
commandOptions.remove("isbn");
link = getOperationInvoker().findLink(createCommandRequest("get-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{title}", toString(link.getHref()));
link = getOperationInvoker().findLink(createCommandRequest("remove-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}", toString(link.getHref()));
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class SimpleHttpOperationInvokerJUnitTest method testCreateHttpRequest.
@Test
public void testCreateHttpRequest() throws Exception {
final CommandRequest command = createCommandRequest("save resource --path=/path/to/file --size=1024KB");
final ClientHttpRequest request = getOperationInvoker().createHttpRequest(command);
assertNotNull(request);
assertEquals(SimpleHttpOperationInvoker.USER_AGENT_HTTP_REQUEST_HEADER_VALUE, request.getHeaderValue(HttpHeader.USER_AGENT.getName()));
final Link requestLink = request.getLink();
assertNotNull(requestLink);
assertTrue(toString(requestLink).startsWith("POST"));
assertTrue(toString(requestLink).endsWith(command.getInput()));
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ClientHttpRequestJUnitTest method testGetURLForGet.
@Test
public void testGetURLForGet() throws Exception {
final Link expectedLink = new Link("find", toUri("http://host.domain.com:8080/app/libraries/{name}/books"), HttpMethod.GET);
final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
request.addParameterValues("author", "Rowling");
request.addParameterValues("category", "science-fiction");
assertEquals(expectedLink, request.getLink());
assertEquals("http://host.domain.com:8080/app/libraries/amazon/books?author=Rowling&category=science-fiction", toString(request.getURL(Collections.singletonMap("name", "amazon"))));
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ClientHttpRequestJUnitTest method testSetAndGetParameterValues.
@Test
public void testSetAndGetParameterValues() throws Exception {
final Link expectedLink = new Link("put", toUri("http://host.domain.com:8080/app/libraries"), HttpMethod.PUT);
final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
assertEquals(expectedLink, request.getLink());
assertTrue(request.getParameters().isEmpty());
request.addParameterValues("parameterOne", "value");
request.addParameterValues("parameterTwo", "test", "testing", "tested");
assertEquals("value", request.getParameterValue("parameterOne"));
assertEquals(1, request.getParameterValues("parameterOne").size());
assertEquals("test", request.getParameterValue("parameterTwo"));
assertEquals(3, request.getParameterValues("parameterTwo").size());
assertTrue(request.getParameterValues("parameterTwo").containsAll(Arrays.asList("test", "testing", "tested")));
request.setParameter("parameterTwo", "development");
assertEquals("development", request.getParameterValue("parameterTwo"));
assertEquals(1, request.getParameterValues("parameterTwo").size());
assertTrue(request.getParameterValues("parameterTwo").containsAll(Arrays.asList("development")));
}
Aggregations