use of org.infinispan.cloudevents.impl.StructuredEventBuilder.DATACONTENTTYPE in project infinispan by infinispan.
the class CacheEntryCloudEventsTest method assertEntryEventSent.
private void assertEntryEventSent(Object key, Object value, TestWriteOperation op) {
byte[] expectedKeyBytes = getKeyBytes(key);
byte[] expectedValueBytes = getValueBytes(value);
String type = translateType(op);
Optional<ProducerRecord<byte[], byte[]>> record = mockSender.getProducer().history().stream().filter(r -> Arrays.equals(r.key(), expectedKeyBytes)).findFirst();
assertTrue(record.isPresent());
byte[] eventBytes = record.get().value();
Json json = Json.read(new String(eventBytes));
assertEquals("1.0", json.at(SPECVERSION).asString());
assertEquals(type, json.at(TYPE).asString());
String source = json.at(SOURCE).asString();
assertTrue(source.startsWith("/infinispan"));
assertTrue(source.endsWith("/" + CACHE_NAME));
Instant.parse(json.at(TIME).asString());
boolean keyIsBase64 = json.at(INFINISPAN_SUBJECT_ISBASE64, false).asBoolean();
assertEquals(expectedContentType(keyIsBase64).toString(), json.at(INFINISPAN_SUBJECT_CONTENTTYPE, APPLICATION_JSON_TYPE).asString());
String subject = json.at(SUBJECT).asString();
byte[] keyBytes = keyIsBase64 ? Base64.getDecoder().decode(subject) : subject.getBytes(StandardCharsets.UTF_8);
assertEquals(expectedKeyBytes, keyBytes);
String data = json.at(DATA).asString();
boolean valueIsBase64 = json.at(INFINISPAN_DATA_ISBASE64, false).asBoolean();
assertEquals(expectedContentType(valueIsBase64).toString(), json.at(DATACONTENTTYPE, APPLICATION_JSON_TYPE).asString());
byte[] valueBytes = valueIsBase64 ? Base64.getDecoder().decode(data) : data.getBytes(StandardCharsets.UTF_8);
assertEquals(expectedValueBytes, valueBytes);
}
Aggregations