Search in sources :

Example 26 with Link

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());
}
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 27 with Link

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

Example 28 with Link

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

Example 29 with Link

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

Example 30 with Link

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")));
}
Also used : 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