DefaultJsonObjectEnvelopeConverter implements JsonObjectEnvelopeConverter { @Override public JsonEnvelope asEnvelope(final JsonObject envelopeJsonObject) { return envelopeFrom( metadataFrom(envelopeJsonObject.getJsonObject(METADATA)), extractPayloadFromEnvelope(envelopeJsonObject)); }  @Override JsonEnvelope asEnvelope(final JsonObject envelopeJsonObject); @Override JsonEnvelope asEnvelope(final String jsonString); @Override JsonObject fromEnvelope(final JsonEnvelope envelope); @Override JsonValue extractPayloadFromEnvelope(final JsonObject envelope); @Override String asJsonString(final JsonEnvelope envelope);  }
@Test public void shouldReturnEnvelope() throws Exception { final JsonEnvelope envelope = jsonObjectEnvelopeConverter.asEnvelope(jsonObjectFromFile("envelope")); assertThat(envelope, notNullValue()); Metadata metadata = envelope.metadata(); JsonObject payload = envelope.payloadAsJsonObject(); assertThat(metadata, notNullValue()); assertThat(payload, notNullValue()); assertThat(metadata.id().toString(), equalTo(ID)); assertThat(metadata.name(), equalTo(NAME)); Optional<String> clientCorrelationId = metadata.clientCorrelationId(); assertThat(clientCorrelationId.get(), equalTo(CLIENT)); assertThat(metadata.sessionId().get(), equalTo(SESSION)); assertThat(metadata.userId().get(), equalTo(USER)); List<UUID> causation = metadata.causation(); assertThat(causation, notNullValue()); assertThat(causation.size(), equalTo(2)); assertThat(causation.get(0).toString(), equalTo(CAUSATION_1)); assertThat(causation.get(1).toString(), equalTo(CAUSATION_2)); }
@Test public void shouldReturnEnvelopeFromString() throws Exception { final JsonEnvelope jsonEnvelope = jsonObjectEnvelopeConverter.asEnvelope(jsonFromFile("envelope")); assertThat(jsonEnvelope.metadata().id(), is(UUID.fromString("861c9430-7bc6-4bf0-b549-6534394b8d65"))); assertThat(jsonEnvelope.metadata().name(), is("test.command.do-something")); assertThat(jsonEnvelope.metadata().clientCorrelationId(), contains("d51597dc-2526-4c71-bd08-5031c79f11e1")); assertThat(jsonEnvelope.metadata().causation(), hasItems(UUID.fromString("cd68037b-2fcf-4534-b83d-a9f08072f2ca"), UUID.fromString("43464b22-04c1-4d99-8359-82dc1934d763"))); assertThat(jsonEnvelope.metadata().sessionId(), contains("45b0c3fe-afe6-4652-882f-7882d79eadd9")); assertThat(jsonEnvelope.metadata().userId(), contains("72251abb-5872-46e3-9045-950ac5bae399")); }