private void writeCurrencyViaJson(String key, String description, int rank) throws IOException { EntityEnclosingMethod put = new PutMethod(restEndpoint + "/" + key); ObjectNode currency = MAPPER.createObjectNode(); currency.put(TYPE, getEntityName()); currency.put("description", description); currency.put("rank", rank); put.setRequestEntity(new StringRequestEntity(currency.toString(), "application/json", "UTF-8")); restClient.executeMethod(put); System.out.println(put.getResponseBodyAsString()); assertEquals(put.getStatusCode(), HttpStatus.SC_OK); }
public void testRestPutEmbeddedHotRodGet() throws Exception { final String key = "1"; // 1. Put with REST EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key); put.setRequestEntity(new ByteArrayRequestEntity( "<hey>ho</hey>".getBytes(), MediaType.TEXT_PLAIN_TYPE)); HttpClient restClient = cacheFactory.getRestClient(); restClient.executeMethod(put); assertEquals(HttpStatus.SC_OK, put.getStatusCode()); assertEquals("", put.getResponseBodyAsString().trim()); // 2. Get with Embedded assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key)); // 3. Get with Hot Rod assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key)); }
public void testRestPutEmbeddedHotRodGet() throws Exception { final String key = "1"; // 1. Put with REST EntityEnclosingMethod put = new PutMethod(cacheFactory1.getRestUrl() + "/" + key); put.setRequestEntity(new ByteArrayRequestEntity( "<hey>ho</hey>".getBytes(), MediaType.TEXT_PLAIN_TYPE)); HttpClient restClient = cacheFactory1.getRestClient(); restClient.executeMethod(put); assertEquals(HttpStatus.SC_OK, put.getStatusCode()); assertEquals("", put.getResponseBodyAsString().trim()); // 2. Get with Embedded Cache embeddedCache = cacheFactory2.getEmbeddedCache().getAdvancedCache(); assertEquals("<hey>ho</hey>", embeddedCache.get(key)); // 3. Get with Hot Rod assertEquals("<hey>ho</hey>", cacheFactory2.getHotRodCache().get(key)); }
public void testRestPutStringHotRodGet() throws Exception { final String key = "1"; // 1. Put text content with REST EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key); put.setRequestEntity(new StringRequestEntity("<hey>ho</hey>", "text/plain", "UTF-8")); HttpClient restClient = cacheFactory.getRestClient(); restClient.executeMethod(put); assertEquals(HttpStatus.SC_OK, put.getStatusCode()); assertEquals("", put.getResponseBodyAsString().trim()); // 3. Get with Hot Rod assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key)); final String newKey = "2"; final String newValue = "<let's>go</let's>"; //4. Put text content with Hot Rod RemoteCache<String, Object> hotRodCache = cacheFactory.getHotRodCache(); hotRodCache.put(newKey, newValue); //5. Read with rest HttpMethod get = new GetMethod(cacheFactory.getRestUrl() + "/" + newKey); cacheFactory.getRestClient().executeMethod(get); assertEquals(HttpStatus.SC_OK, get.getStatusCode()); assertEquals(newValue, get.getResponseBodyAsString()); }
public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception { final String key = "3"; // 1. Put with REST EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key); put.setRequestEntity(new ByteArrayRequestEntity( "<hey>ho</hey>".getBytes(), MediaType.TEXT_PLAIN_TYPE)); HttpClient restClient = cacheFactory.getRestClient(); restClient.executeMethod(put); assertEquals(HttpStatus.SC_OK, put.getStatusCode()); assertEquals("", put.getResponseBodyAsString().trim()); // 2. Get with Embedded (given a marshaller, it can unmarshall the result) assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key)); // 3. Get with Memcached (given a marshaller, it can unmarshall the result) assertEquals("<hey>ho</hey>", cacheFactory.getMemcachedClient().get(key)); // 4. Get with Hot Rod (given a marshaller, it can unmarshall the result) assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key)); }
@Test public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception { final String key = "3"; final Object value = "<hey>ho</hey>"; final Marshaller marshaller = cacheFactory.getMarshaller(); // 1. Put with REST byte[] bytes = marshaller.objectToByteBuffer(value); EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key); put.setRequestEntity(new ByteArrayRequestEntity(bytes, marshaller.mediaType().toString())); HttpClient restClient = cacheFactory.getRestClient(); restClient.executeMethod(put); assertEquals(HttpStatus.SC_OK, put.getStatusCode()); assertEquals("", put.getResponseBodyAsString().trim()); // 2. Get with Embedded (given a marshaller, it can unmarshall the result) assertEquals(value, cacheFactory.getEmbeddedCache().get(key)); // 3. Get with Memcached (given a marshaller, it can unmarshall the result) assertEquals(value, cacheFactory.getMemcachedClient().get(key)); // 4. Get with Hot Rod assertEquals(value, cacheFactory.getHotRodCache().get(key)); } }