-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update docs, IllegalArgumentExc instead of JsonProcessingException
- Loading branch information
Showing
4 changed files
with
46 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
package customer.domain; | ||
|
||
import com.google.protobuf.Any; | ||
import com.google.protobuf.ByteString; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import akka.javasdk.JsonSupport; | ||
import akka.util.ByteString; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Base64; | ||
|
@@ -15,9 +14,9 @@ | |
class CustomerEventSerializationTest { | ||
|
||
@Test | ||
public void shouldDeserializeWithMandatoryField() { | ||
public void shouldDeserializeWithMandatoryField() throws JsonProcessingException { | ||
//given | ||
Any serialized = JsonSupport.encodeJson(new CustomerEvent.NameChanged("andre")); | ||
ByteString serialized = JsonSupport.encodeToAkkaByteString(new CustomerEvent.NameChanged("andre")); | ||
|
||
//when | ||
NameChanged deserialized = JsonSupport.decodeJson(NameChanged.class, serialized); | ||
|
@@ -32,7 +31,7 @@ public void shouldDeserializeWithMandatoryField() { | |
public void shouldDeserializeWithChangedFieldName() { | ||
//given | ||
Address address = new Address("Wall Street", "New York"); | ||
Any serialized = JsonSupport.encodeJson(new CustomerEvent.AddressChanged(address)); | ||
ByteString serialized = JsonSupport.encodeToAkkaByteString(new CustomerEvent.AddressChanged(address)); | ||
|
||
//when | ||
AddressChanged deserialized = JsonSupport.decodeJson(AddressChanged.class, serialized); | ||
|
@@ -44,7 +43,7 @@ public void shouldDeserializeWithChangedFieldName() { | |
@Test | ||
public void shouldDeserializeWithStructureMigration() { | ||
//given | ||
Any serialized = JsonSupport.encodeJson(new CustomerCreatedOld("[email protected]", "bob", "Wall Street", "New York")); | ||
ByteString serialized = JsonSupport.encodeToAkkaByteString(new CustomerCreatedOld("[email protected]", "bob", "Wall Street", "New York")); | ||
|
||
//when | ||
CustomerEvent.CustomerCreated deserialized = JsonSupport.decodeJson(CustomerEvent.CustomerCreated.class, serialized); | ||
|
@@ -58,19 +57,18 @@ public void shouldDeserializeWithStructureMigration() { | |
@Test | ||
public void shouldDeserializeCustomerCreated_V0() throws InvalidProtocolBufferException { | ||
// tag::testing-deserialization-encoding[] | ||
Any serialized = JsonSupport.encodeJson(new CustomerCreatedOld("[email protected]", "bob", "Wall Street", "New York")); | ||
String encodedBytes = new String(Base64.getEncoder().encode(serialized.toByteArray())); // <1> | ||
ByteString serialized = JsonSupport.encodeToAkkaByteString(new CustomerCreatedOld("[email protected]", "bob", "Wall Street", "New York")); | ||
String encodedBytes = serialized.encodeBase64().utf8String(); // <1> | ||
// end::testing-deserialization-encoding[] | ||
|
||
byte[] bytes = Base64.getDecoder().decode(encodedBytes.getBytes()); // <2> | ||
Any serializedAny = Any.parseFrom(ByteString.copyFrom(bytes)); // <3> | ||
ByteString decodedBytes = ByteString.fromString(encodedBytes).decodeBase64(); // <2> | ||
|
||
CustomerEvent.CustomerCreated deserialized = JsonSupport.decodeJson(CustomerEvent.CustomerCreated.class, | ||
serializedAny); // <4> | ||
decodedBytes); // <3> | ||
|
||
assertEquals("Wall Street", deserialized.address().street()); | ||
assertEquals("New York", deserialized.address().city()); | ||
} | ||
// end::testing-deserialization[] | ||
|
||
} | ||
} |