diff --git a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_event_type.sql b/deployment/postgres-init-db/sql/tables/merlin/external_events/external_event_type.sql index f9eb84fe1c..2e4f966d46 100644 --- a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_event_type.sql +++ b/deployment/postgres-init-db/sql/tables/merlin/external_events/external_event_type.sql @@ -1,6 +1,6 @@ create table merlin.external_event_type ( name text not null, - attribute_schema jsonb, + attribute_schema jsonb not null, constraint external_event_type_pkey primary key (name) diff --git a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type.sql b/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type.sql index 8a073e562b..16da3e4916 100644 --- a/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type.sql +++ b/deployment/postgres-init-db/sql/tables/merlin/external_events/external_source_type.sql @@ -1,6 +1,6 @@ create table merlin.external_source_type ( name text not null, - attribute_schema jsonb, + attribute_schema jsonb not null, constraint external_source_type_pkey primary key (name) diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java index 45c59eedee..04bcfdf5d6 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/ExternalEventsTests.java @@ -14,6 +14,7 @@ import javax.json.JsonObjectBuilder; import java.io.IOException; +import static java.lang.System.exit; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -37,39 +38,46 @@ void beforeAll() { // need a method to upload external event and source types void uploadExternalSourceEventTypes() throws IOException { - final String schema = """ + + final String event_types = """ { - "event_types": { - "TestEventType": { - "type": "object", - "required": ["projectUser", "code"], - "properties": { - "projectUser": { - "type": "string" - }, - "code": { - "type": "string" - } + "TestEventType": { + "type": "object", + "required": ["projectUser", "code"], + "properties": { + "projectUser": { + "type": "string" + }, + "code": { + "type": "string" } } - }, - "source_types": { - "TestSourceType": { - "type": "object", - "properties": { - "version": { - "type": "number" - }, - "operator": { - "type": "string" - } + } + } + """; + + final String source_types = """ + { + "TestSourceType": { + "type": "object", + "properties": { + "version": { + "type": "number" }, - "required": ["version", "operator"] - } + "operator": { + "type": "string" + } + }, + "required": ["version", "operator"] } } """; + final JsonObject schema = Json.createObjectBuilder() + .add("event_types", event_types) + .add("source_types", source_types) + .build(); + try (final var gateway = new GatewayRequests(playwright)) { gateway.uploadExternalSourceEventTypes(schema); } @@ -178,7 +186,7 @@ void sourceMissingAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should have required property 'operator'")); } @@ -221,7 +229,7 @@ void sourceExtraAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should NOT have additional properties")); } @@ -264,7 +272,7 @@ void sourceWrongTypeAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should be number")); } @@ -306,7 +314,7 @@ void eventMissingAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should have required property 'code'")); } @@ -350,7 +358,7 @@ void eventExtraAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should NOT have additional properties")); } @@ -393,7 +401,7 @@ void eventWrongTypeAttribute() throws IOException { .build(); final var gateway = new GatewayRequests(playwright); - final IOException ex = assertThrows(IOException.class, () -> gateway.uploadExternalSource(externalSource)); + final RuntimeException ex = assertThrows(RuntimeException.class, () -> gateway.uploadExternalSource(externalSource)); assertTrue(ex.getMessage().contains("should be string")); } } diff --git a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GatewayRequests.java b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GatewayRequests.java index e646ba189b..eb64928232 100644 --- a/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GatewayRequests.java +++ b/e2e-tests/src/test/java/gov/nasa/jpl/aerie/e2e/utils/GatewayRequests.java @@ -99,37 +99,31 @@ public int uploadJarFile(String jarPath) throws IOException { } - public void uploadExternalSourceEventTypes(String schema) throws IOException { + public void uploadExternalSourceEventTypes(JsonObject schema) throws RuntimeException { final var response = request.post("/uploadExternalSourceEventTypes", RequestOptions.create() .setHeader("Authorization", "Bearer "+token) .setHeader("Content-Type", "application/json") - .setData(schema)); + .setData(schema.toString())); // Process Response - if(!response.ok()){ - throw new IOException(response.statusText()); - } try(final var reader = Json.createReader(new StringReader(response.text()))){ final JsonObject bodyJson = reader.readObject(); - if(!bodyJson.containsKey("data")){ + if(!(bodyJson.containsKey("createExternalEventTypes") && bodyJson.containsKey("createExternalSourceTypes"))){ System.err.println("Upload failed"); throw new RuntimeException(bodyJson.toString()); } } } - public void uploadExternalSource(JsonObject externalSource) throws IOException { + public void uploadExternalSource(JsonObject externalSource) throws RuntimeException { final var response = request.post("/uploadExternalSource", RequestOptions.create() .setHeader("Authorization", "Bearer "+token) .setHeader( "Content-Type", "application/json") .setData(externalSource.toString())); - if (!response.ok()) { - throw new IOException(response.statusText() + "\n" + response.text()); - } try (final var reader = Json.createReader(new StringReader(response.text()))) { final JsonObject bodyJson = reader.readObject(); - if (!bodyJson.containsKey("data")) { + if (!bodyJson.containsKey("createExternalSource")) { System.err.println("Upload failed"); throw new RuntimeException(bodyJson.toString()); }