@Test public void firestoreComplexData() throws IOException { Event legacyEvent = legacyEventForResource("firestore_complex.json"); CloudEvent cloudEvent = GcfEvents.convertToCloudEvent(legacyEvent); Map<String, Object> data = cloudEventDataJson(cloudEvent); Map<?, ?> value = (Map<?, ?>) data.get("value"); Map<?, ?> fields = (Map<?, ?>) value.get("fields"); Map<String, Object> expectedFields = Map.of( "arrayValue", Map.of("arrayValue", Map.of("values", List.of(Map.of("integerValue", "1"), Map.of("integerValue", "2")))), "booleanValue", Map.of("booleanValue", true), "geoPointValue", Map.of("geoPointValue", Map.of("latitude", 51.4543, "longitude", -0.9781)), "intValue", Map.of("integerValue", "50"), "doubleValue", Map.of("doubleValue", 5.5), "nullValue", Map.of(), "referenceValue", Map.of("referenceValue", "projects/project-id/databases/(default)/documents/foo/bar/baz/qux"), "stringValue", Map.of("stringValue", "text"), "timestampValue", Map.of("timestampValue", "2020-04-23T14:23:53.241Z"), "mapValue", Map.of("mapValue", Map.of("fields", Map.of("field1", Map.of("stringValue", "x"), "field2", Map.of("arrayValue", Map.of("values", List.of(Map.of("stringValue", "x"), Map.of("integerValue", "1"))))))) ); assertThat(fields).containsExactlyEntriesIn(expectedFields); }
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); }    }