@Test public void pubSubTextData() throws IOException { Event legacyEvent = legacyEventForResource("pubsub_text.json"); CloudEvent cloudEvent = GcfEvents.convertToCloudEvent(legacyEvent); Map<String, Object> data = cloudEventDataJson(cloudEvent); Map<?, ?> message = (Map<?, ?>) data.get("message"); assertThat(message).isNotNull(); assertThat(message).containsKey("data"); String base64 = (String) message.get("data"); byte[] bytes = Base64.getDecoder().decode(base64); String text = new String(bytes, UTF_8); assertThat(text).isEqualTo("test message 3"); assertThat(message).containsEntry("attributes", Map.of("attr1", "attr1-value")); }
static CloudEvent convertToCloudEvent(Event legacyEvent) { String eventType = legacyEvent.getContext().eventType(); EventAdapter eventAdapter = EVENT_TYPE_MAPPING.get(eventType); if (eventAdapter == null) { throw new IllegalArgumentException("Unrecognized event type \"" + eventType + "\""); } return eventAdapter.convertToCloudEvent(legacyEvent); }
GcfEvents { static CloudEvent convertToCloudEvent(Event legacyEvent) { String eventType = legacyEvent.getContext().eventType(); EventAdapter eventAdapter = EVENT_TYPE_MAPPING.get(eventType); if (eventAdapter == null) { throw new IllegalArgumentException("Unrecognized event type \"" + eventType + "\""); } return eventAdapter.convertToCloudEvent(legacyEvent); } }
GcfEvents { static CloudEvent convertToCloudEvent(Event legacyEvent) { String eventType = legacyEvent.getContext().eventType(); EventAdapter eventAdapter = EVENT_TYPE_MAPPING.get(eventType); if (eventAdapter == null) { throw new IllegalArgumentException("Unrecognized event type \"" + eventType + "\""); } return eventAdapter.convertToCloudEvent(legacyEvent); }  }
GcfEvents { static CloudEvent convertToCloudEvent(Event legacyEvent) { String eventType = legacyEvent.getContext().eventType(); EventAdapter eventAdapter = EVENT_TYPE_MAPPING.get(eventType); if (eventAdapter == null) { throw new IllegalArgumentException("Unrecognized event type \"" + eventType + "\""); } return eventAdapter.convertToCloudEvent(legacyEvent); }   }
GcfEvents { static CloudEvent convertToCloudEvent(Event legacyEvent) { String eventType = legacyEvent.getContext().eventType(); EventAdapter eventAdapter = EVENT_TYPE_MAPPING.get(eventType); if (eventAdapter == null) { throw new IllegalArgumentException("Unrecognized event type \"" + eventType + "\""); } return eventAdapter.convertToCloudEvent(legacyEvent); }    }