Search in sources :

Example 1 with Link

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());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) Link(org.apache.geode.management.internal.web.domain.Link) Before(org.junit.Before)

Example 2 with Link

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()));
}
Also used : CommandRequest(org.apache.geode.management.internal.cli.CommandRequest) Link(org.apache.geode.management.internal.web.domain.Link) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with Link

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());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) ArrayList(java.util.ArrayList) Link(org.apache.geode.management.internal.web.domain.Link) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with Link

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());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Link(org.apache.geode.management.internal.web.domain.Link) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 5 with Link

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)));
}
Also used : HashMap(java.util.HashMap) Link(org.apache.geode.management.internal.web.domain.Link) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

Link (org.apache.geode.management.internal.web.domain.Link)38 Test (org.junit.Test)31 UnitTest (org.apache.geode.test.junit.categories.UnitTest)30 HashMap (java.util.HashMap)5 LinkIndex (org.apache.geode.management.internal.web.domain.LinkIndex)5 ClientHttpRequest (org.apache.geode.management.internal.web.http.ClientHttpRequest)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 MultiValueMap (org.springframework.util.MultiValueMap)3 URI (java.net.URI)2 CommandRequest (org.apache.geode.management.internal.cli.CommandRequest)2 HttpEntity (org.springframework.http.HttpEntity)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 ObjectName (javax.management.ObjectName)1 QueryExp (javax.management.QueryExp)1 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)1 QueryParameterSource (org.apache.geode.management.internal.web.domain.QueryParameterSource)1