Search in sources :

Example 1 with TestClass

use of org.infinispan.rest.TestClass in project infinispan by infinispan.

the class BaseCacheResourceTest method shouldGetOctetStreamValueStoredInSpecificFormat.

@Test
public void shouldGetOctetStreamValueStoredInSpecificFormat() throws Exception {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    putBinaryValueInCache("serialized", "test", convertToBytes(testClass), APPLICATION_SERIALIZED_OBJECT);
    // when
    RestResponse response = join(client.cache("serialized").get("test"));
    TestClass convertedObject = convertFromBytes(response.getBodyAsByteArray());
    // then
    ResponseAssertion.assertThat(response).isOk();
    ResponseAssertion.assertThat(response).hasContentType(APPLICATION_SERIALIZED_OBJECT.toString());
    ResponseAssertion.assertThat(response).hasNoCharset();
    Assertions.assertThat(convertedObject.getName()).isEqualTo("test");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 2 with TestClass

use of org.infinispan.rest.TestClass in project infinispan by infinispan.

the class BaseCacheResourceTest method shouldNegotiateFromDefaultCacheWithBinary.

@Test
public void shouldNegotiateFromDefaultCacheWithBinary() throws Exception {
    TestClass testClass = new TestClass();
    Marshaller marshaller = TestingUtil.createProtoStreamMarshaller(RestTestSCI.INSTANCE);
    byte[] javaSerialized = marshaller.objectToByteBuffer(testClass);
    putBinaryValueInCache("default", "test", javaSerialized, APPLICATION_OCTET_STREAM);
    RestResponse response = get("default", "test", APPLICATION_OCTET_STREAM_TYPE);
    ResponseAssertion.assertThat(response).hasContentType(APPLICATION_OCTET_STREAM_TYPE);
    ResponseAssertion.assertThat(response).hasReturnedBytes(javaSerialized);
}
Also used : Marshaller(org.infinispan.commons.marshall.Marshaller) RestResponse(org.infinispan.client.rest.RestResponse) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 3 with TestClass

use of org.infinispan.rest.TestClass in project infinispan by infinispan.

the class CacheResourceTest method shouldConvertExistingSerializableObjectToJson.

@Test
public void shouldConvertExistingSerializableObjectToJson() {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    RestCacheClient objectCache = client.cache("objectCache");
    join(objectCache.put("test", RestEntity.create(APPLICATION_JSON, testClass.toJson().toString())));
    // when
    CompletionStage<RestResponse> response = objectCache.get("test", APPLICATION_JSON_TYPE);
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType("application/json");
    assertThat(response).hasReturnedText("{\"" + TYPE + "\":\"" + TestClass.class.getName() + "\",\"name\":\"test\"}");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 4 with TestClass

use of org.infinispan.rest.TestClass in project infinispan by infinispan.

the class CacheResourceTest method shouldReadAsJsonWithPojoCache.

@Test
public void shouldReadAsJsonWithPojoCache() {
    // given
    TestClass testClass = new TestClass();
    testClass.setName("test");
    RestCacheClient pojoCache = client.cache("pojoCache");
    join(pojoCache.put("test", RestEntity.create(APPLICATION_JSON, testClass.toJson().toString())));
    // when
    CompletionStage<RestResponse> response = pojoCache.get("test", APPLICATION_JSON_TYPE);
    // then
    assertThat(response).isOk();
    assertThat(response).hasContentType(APPLICATION_JSON_TYPE);
    assertThat(response).hasReturnedText("{\"" + TYPE + "\":\"org.infinispan.rest.TestClass\",\"name\":\"test\"}");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Example 5 with TestClass

use of org.infinispan.rest.TestClass in project infinispan by infinispan.

the class BaseCacheResourceTest method shouldPutSerializedValueInCache.

@Test
public void shouldPutSerializedValueInCache() throws Exception {
    // when
    TestClass testClass = new TestClass();
    testClass.setName("test");
    CompletionStage<RestResponse> response = client.cache("serialized").post("test", RestEntity.create(APPLICATION_SERIALIZED_OBJECT, convertToBytes(testClass)));
    ResponseAssertion.assertThat(response).isOk();
    RestResponse getResponse = join(client.cache("serialized").get("test", APPLICATION_SERIALIZED_OBJECT_TYPE));
    TestClass valueFromCache = convertFromBytes(getResponse.getBodyAsByteArray());
    ResponseAssertion.assertThat(getResponse).hasEtag();
    Assertions.assertThat(valueFromCache.getName()).isEqualTo("test");
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) TestClass(org.infinispan.rest.TestClass) Test(org.testng.annotations.Test)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)8 TestClass (org.infinispan.rest.TestClass)8 Test (org.testng.annotations.Test)8 RestCacheClient (org.infinispan.client.rest.RestCacheClient)5 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)3 Marshaller (org.infinispan.commons.marshall.Marshaller)1