Skip to content

Commit

Permalink
update e2e tests again
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-super committed Nov 25, 2024
1 parent 8521550 commit 631969a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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'"));
}

Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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'"));
}

Expand Down Expand Up @@ -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"));
}

Expand Down Expand Up @@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 631969a

Please sign in to comment.