Search in sources :

Example 6 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 7 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)

Example 8 with Link

use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.

the class ClientHttpRequestJUnitTest method testGetPathVariablesWithUriHavingNoPathVariables.

@Test
public void testGetPathVariablesWithUriHavingNoPathVariables() throws Exception {
    final Link expectedLink = new Link("test", toUri("http://host.domain.com:8080/app/service"));
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    assertEquals(expectedLink, request.getLink());
    final List<String> actualPathVariables = request.getPathVariables();
    assertNotNull(actualPathVariables);
    assertTrue(actualPathVariables.isEmpty());
}
Also used : Link(org.apache.geode.management.internal.web.domain.Link) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 9 with Link

use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.

the class ClientHttpRequestJUnitTest method testCreateClientHttpRequest.

@Test
public void testCreateClientHttpRequest() throws Exception {
    final Link expectedLink = new Link("test", toUri("http://host.domain.com:8080/app/service"));
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    assertNotNull(request);
    assertEquals(expectedLink, request.getLink());
}
Also used : Link(org.apache.geode.management.internal.web.domain.Link) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 10 with Link

use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.

the class ClientHttpRequestJUnitTest method testGetMethod.

@Test
public void testGetMethod() throws Exception {
    Link link = new Link("get-resource", toUri("http://host.domain.com:8080/app/resources/{id}"));
    ClientHttpRequest request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.GET, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app/resources/{id}"), HttpMethod.DELETE);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.DELETE, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app/service"), HttpMethod.HEAD);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.HEAD, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app/service"), HttpMethod.OPTIONS);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.OPTIONS, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app/resources"), HttpMethod.POST);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.POST, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app/resources"), HttpMethod.PUT);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.PUT, request.getMethod());
    link = new Link("delete-resource", toUri("http://host.domain.com:8080/app"), HttpMethod.TRACE);
    request = new ClientHttpRequest(link);
    assertEquals(link, request.getLink());
    assertEquals(org.springframework.http.HttpMethod.TRACE, request.getMethod());
}
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