use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method setUp.
@Before
public void setUp() throws Exception {
final Link listLibraries = new Link("list-libraries", toUri("http://host.domain.com/service/v1/libraries"));
final Link getLibrary = new Link("get-library", toUri("http://host.domain.com/service/v1/libraries/{name}"));
final Link listBooks = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books"));
final Link listBooksByAuthor = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}"));
final Link listBooksByAuthorAndCategory = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}"));
final Link listBooksByAuthorAndYear = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{year}"));
final Link listBooksByAuthorCategoryAndYear = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}/{year}"));
final Link addBook = new Link("add-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books"), HttpMethod.POST);
final Link getBookByIsbn = new Link("get-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}"));
final Link getBookByTitle = new Link("get-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{title}"));
final Link removeBook = new Link("remove-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}"), HttpMethod.DELETE);
linkIndex = new LinkIndex();
linkIndex.addAll(listLibraries, getLibrary, listBooks, listBooksByAuthor, listBooksByAuthorAndCategory, listBooksByAuthorAndYear, listBooksByAuthorCategoryAndYear, addBook, getBookByIsbn, getBookByTitle, removeBook);
assertEquals(11, linkIndex.size());
operationInvoker = new RestHttpOperationInvoker(linkIndex);
assertSame(linkIndex, operationInvoker.getLinkIndex());
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class SimpleHttpOperationInvokerJUnitTest method testCreateLink.
@Test
public void testCreateLink() throws Exception {
final CommandRequest command = createCommandRequest("delete resource --id=1");
final Link actualLink = getOperationInvoker().createLink(command);
assertNotNull(actualLink);
assertEquals(SimpleHttpOperationInvoker.LINK_RELATION, actualLink.getRelation());
assertEquals(HttpMethod.POST, actualLink.getMethod());
assertTrue(toString(actualLink.getHref()).endsWith(command.getInput()));
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ShellCommandsControllerJUnitTest method testIndex.
@Test
public void testIndex() {
List<String> commands = getCliCommands();
assertNotNull(commands);
assertFalse(commands.isEmpty());
LinkIndex linkIndex = controller.index("https");
assertNotNull(linkIndex);
assertFalse(linkIndex.isEmpty());
List<String> linkCommands = new ArrayList<>(linkIndex.size());
for (Link link : linkIndex) {
linkCommands.add(link.getRelation());
}
assertEquals(linkIndex.size(), linkCommands.size());
List<String> missingLinkCommands = new ArrayList<>(commands);
missingLinkCommands.removeAll(linkCommands);
assertTrue(String.format("The GemFire Management REST API Link Index is missing Link(s) for the following command(s): %1$s", missingLinkCommands), missingLinkCommands.isEmpty());
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ClientHttpRequestJUnitTest method testCreateRequestEntityForPut.
@Test
@SuppressWarnings("unchecked")
public void testCreateRequestEntityForPut() throws Exception {
final Link expectedLink = new Link("put", toUri("http://host.domain.com:8080/app/libraries/{name}/books/{isbn}"), HttpMethod.PUT);
final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
assertEquals(expectedLink, request.getLink());
final MultiValueMap<String, Object> expectedRequestParameters = new LinkedMultiValueMap<String, Object>(4);
expectedRequestParameters.add("year", "1979");
request.addHeaderValues(HttpHeader.ACCEPT.getName(), MediaType.TEXT_XML_VALUE);
request.addHeaderValues(HttpHeader.CONTENT_TYPE.getName(), MediaType.APPLICATION_FORM_URLENCODED_VALUE);
request.addParameterValues("year", expectedRequestParameters.getFirst("year"));
final HttpEntity<MultiValueMap<String, Object>> requestEntity = (HttpEntity<MultiValueMap<String, Object>>) request.createRequestEntity();
assertNotNull(requestEntity);
assertNotNull(requestEntity.getHeaders());
assertEquals(Collections.singletonList(MediaType.TEXT_XML), requestEntity.getHeaders().getAccept());
assertEquals(MediaType.APPLICATION_FORM_URLENCODED, requestEntity.getHeaders().getContentType());
assertEquals(expectedRequestParameters, requestEntity.getBody());
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ClientHttpRequestJUnitTest method testGetURLForGetWithQueryParametersNoBody.
@Test
public void testGetURLForGetWithQueryParametersNoBody() throws Exception {
final Link expectedLink = new Link("find", toUri("http://host.domain.com:8080/app/libraries/{name}/books/{author}"), HttpMethod.GET);
final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
request.addParameterValues("author", "Rowling");
request.addParameterValues("category", "science-fiction");
request.addParameterValues("name", "Boston");
request.addParameterValues("year", "2007");
final Map<String, Object> uriVariables = new HashMap<String, Object>(4);
uriVariables.put("author", "Rowling");
uriVariables.put("category", "mystery");
uriVariables.put("isbn", "0-123456789");
uriVariables.put("name", "Amazon");
assertEquals(expectedLink, request.getLink());
assertEquals("http://host.domain.com:8080/app/libraries/Amazon/books/Rowling?category=science-fiction&year=2007", toString(request.getURL(uriVariables)));
}
Aggregations