Skip to content

Instantly share code, notes, and snippets.

@matzew
Created June 19, 2018 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/138ecb821ebf4d6c971cebff0d417ca1 to your computer and use it in GitHub Desktop.
Save matzew/138ecb821ebf4d6c971cebff0d417ca1 to your computer and use it in GitHub Desktop.
// given
final Map<String, Object> storagePayload = (MAPPER.readValue(Thread.currentThread().getContextClassLoader().getResourceAsStream("pvc.json"), Map.class));
final CloudEvent<Map<String, Object>> storageCloudEventWrapper = new CloudEventBuilder<Map<String, Object>>()
.eventType("ProvisioningSucceeded")
.eventTypeVersion("2.0")
.source(URI.create("/scheduler"))
.eventID(UUID.randomUUID().toString())
.data(storagePayload)
.build();
// when
final String httpSerializedPayload = MAPPER.writeValueAsString(storageCloudEventWrapper);
assertThat(httpSerializedPayload).contains("PersistentVolumeClaim");
//PARSE into real object, on the other side
final CloudEvent<GlusterVolumeClaim> event = MAPPER.readValue(httpSerializedPayload, new TypeReference<CloudEvent<GlusterVolumeClaim>>() {});
// then
assertThat(event.getData().get()).isNotNull();
assertThat(event.getData().get().getSpec().getCapacity().get("storage")).isEqualTo("2Gi");
assertThat(event.getData().get().getSpec().getAccessModes()).containsExactly("ReadWriteMany");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment