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");
}
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);
}
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\"}");
}
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\"}");
}
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");
}
Aggregations