Search in sources :

Example 36 with Link

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

the class ClientHttpRequestJUnitTest method testCreateRequestEntityOnPut.

@Test
public void testCreateRequestEntityOnPut() throws Exception {
    final Book mockBook = mockContext.mock(Book.class, "testCreateRequestEntityOnPut.Book");
    final Link expectedLink = new Link("put", toUri("http://host.domain.com:8080/app/libraries/{name}/books/{id}"), HttpMethod.PUT);
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    assertEquals(expectedLink, request.getLink());
    assertTrue(request.isPut());
    assertNull(request.getContent());
    request.setContent(mockBook);
    request.addParameterValues("isbn", "0-123456789");
    request.addParameterValues("category", "science-fiction", "sci-fi", "fiction");
    assertSame(mockBook, request.getContent());
    assertEquals("0-123456789", request.getParameterValue("isbn"));
    assertTrue(request.getParameterValues("category").containsAll(Arrays.asList("science-fiction", "sci-fi", "fiction")));
    final HttpEntity<?> requestEntity = request.createRequestEntity();
    assertNotNull(requestEntity);
    assertTrue(requestEntity.getBody() instanceof MultiValueMap);
    assertEquals(MediaType.APPLICATION_FORM_URLENCODED, requestEntity.getHeaders().getContentType());
}
Also used : 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 37 with Link

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

the class ClientHttpRequestJUnitTest method testGetURLForPost.

@Test
public void testGetURLForPost() throws Exception {
    final Link expectedLink = new Link("post", toUri("http://host.domain.com:8080/app/libraries/{name}/books"), HttpMethod.POST);
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    request.addParameterValues("author", "Douglas Adams");
    request.addParameterValues("title", "The Hitchhiker's Guide to the Galaxy");
    request.addParameterValues("year", "1979");
    request.addParameterValues("isbn", "0345453743");
    assertEquals(expectedLink, request.getLink());
    assertEquals("http://host.domain.com:8080/app/libraries/royal/books", toString(request.getURL(Collections.singletonMap("name", "royal"))));
}
Also used : Link(org.apache.geode.management.internal.web.domain.Link) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 38 with Link

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

the class ClientHttpRequestJUnitTest method testGetURLForPut.

@Test
public void testGetURLForPut() 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);
    request.addParameterValues("year", "1983");
    final Map<String, String> uriVariables = new HashMap<String, String>(2);
    uriVariables.put("name", "royal");
    uriVariables.put("isbn", "0345453743");
    assertEquals(expectedLink, request.getLink());
    assertEquals("http://host.domain.com:8080/app/libraries/royal/books/0345453743", 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