|
9 | 9 | import com.commercetools.api.models.message.CustomerLastNameSetMessagePayload;
|
10 | 10 | import com.commercetools.api.models.message.MessagePayload;
|
11 | 11 | import com.commercetools.api.models.message.OrderCreatedMessagePayload;
|
12 |
| -import com.commercetools.api.models.subscription.DeliveryPayload; |
13 |
| -import com.commercetools.api.models.subscription.MessageDeliveryPayload; |
| 12 | +import com.commercetools.api.models.subscription.*; |
14 | 13 |
|
15 | 14 | import io.vrap.rmf.base.client.utils.json.JsonUtils;
|
16 | 15 |
|
|
19 | 18 |
|
20 | 19 | public class MessagePayloadTest {
|
21 | 20 |
|
| 21 | + @Test |
| 22 | + public void delivery() { |
| 23 | + String messagePayload = "{\n" + " \"notificationType\":\"Message\",\n" |
| 24 | + + " \"projectKey\":\"<project_key>\",\n" + " \"id\":\"<message_id>\",\n" + " \"version\":1,\n" |
| 25 | + + " \"sequenceNumber\":2,\n" + " \"resource\":{\n" + " \"typeId\":\"customer\",\n" |
| 26 | + + " \"id\":\"<customer_id>\"\n" + " },\n" + " \"resourceVersion\":2,\n" |
| 27 | + + " \"resourceUserProvidedIdentifiers\":{},\n" + " \"type\":\"CustomerLastNameSet\",\n" |
| 28 | + + " \"lastName\":\"Doe\",\n" + " \"createdAt\":\"2022-10-25T13:30:09.760Z\",\n" |
| 29 | + + " \"lastModifiedAt\":\"2022-10-25T13:30:09.760Z\"\n" + "}"; |
| 30 | + SubscriptionNotification deserializedObject = JsonUtils.fromJsonString(messagePayload, |
| 31 | + SubscriptionNotification.class); |
| 32 | + Assertions.assertThat(deserializedObject).isInstanceOf(MessageDeliveryPayload.class); |
| 33 | + |
| 34 | + deserializedObject = JsonUtils.fromJsonString(messagePayload, DeliveryPayload.class); |
| 35 | + Assertions.assertThat(deserializedObject).isInstanceOf(MessageDeliveryPayload.class); |
| 36 | + |
| 37 | + String eventPayload = "{\n" + " \"id\": \"3b364ca2-cbe5-42b4-a85a-37d4e57d659e\",\n" |
| 38 | + + " \"notificationType\": \"Event\",\n" + " \"type\": \"ImportContainerCreated\",\n" |
| 39 | + + " \"resourceType\": \"import-api\",\n" + " \"data\": {\n" + " \"version\": 1,\n" |
| 40 | + + " \"key\": \"my-import-container\",\n" + " \"createdAt\": \"2025-03-26T17:28:20.376Z\",\n" |
| 41 | + + " \"lastModifiedAt\": \"2025-03-26T17:28:20.376Z\"\n" + " },\n" |
| 42 | + + " \"createdAt\": \"2025-03-26T17:28:20.397Z\"\n" + "}\n"; |
| 43 | + deserializedObject = JsonUtils.fromJsonString(eventPayload, SubscriptionNotification.class); |
| 44 | + Assertions.assertThat(deserializedObject).isInstanceOf(EventDeliveryPayload.class); |
| 45 | + |
| 46 | + String changePayload = "{\n" + " \"notificationType\":\"ResourceCreated\",\n" |
| 47 | + + " \"projectKey\":\"<project_key>\",\n" + " \"resource\":{\n" + " \"typeId\":\"product\",\n" |
| 48 | + + " \"id\":\"<product_id>\"\n" + " },\n" + " \"resourceUserProvidedIdentifiers\":{\n" |
| 49 | + + " \"key\":\"example-product-key\",\n" + " \"slug\":{\n" + " \"en\":\"example-slug\"\n" |
| 50 | + + " }\n" + " },\n" + " \"version\":1,\n" + " \"modifiedAt\":\"2022-10-25T13:23:05.384Z\"\n" |
| 51 | + + "}\n"; |
| 52 | + deserializedObject = JsonUtils.fromJsonString(changePayload, SubscriptionNotification.class); |
| 53 | + Assertions.assertThat(deserializedObject).isInstanceOf(ResourceCreatedDeliveryPayload.class); |
| 54 | + |
| 55 | + deserializedObject = JsonUtils.fromJsonString(changePayload, DeliveryPayload.class); |
| 56 | + Assertions.assertThat(deserializedObject).isInstanceOf(ResourceCreatedDeliveryPayload.class); |
| 57 | + |
| 58 | + } |
| 59 | + |
22 | 60 | @Test
|
23 | 61 | public void deserializeOrderCreatedMessageFromString() throws IOException {
|
24 | 62 | String payload = "{\"type\": \"OrderCreated\", \"order\": {}}";
|
|
0 commit comments