From ad05040009fd1b3f61f850f33ab174a90714bd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20Pedersen?= Date: Thu, 28 Sep 2023 23:54:21 +0200 Subject: [PATCH] Adds a test to verify Action logic and removes the null check, fixes #642 --- .../io/hyperfoil/tools/horreum/svc/ActionServiceImpl.java | 2 +- .../io/hyperfoil/tools/horreum/svc/BaseServiceTest.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ActionServiceImpl.java b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ActionServiceImpl.java index 983634fd4..3f22d938b 100644 --- a/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ActionServiceImpl.java +++ b/horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/ActionServiceImpl.java @@ -194,7 +194,7 @@ public Action add(Action action){ return action; } - public JsonNode ensureNotNull(@NotNull JsonNode node) { + public JsonNode ensureNotNull(JsonNode node) { return node == null || node.isNull() || node.isMissingNode() ? JsonNodeFactory.instance.objectNode() : node; } diff --git a/horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/BaseServiceTest.java b/horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/BaseServiceTest.java index 751f205c0..af6f14084 100644 --- a/horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/BaseServiceTest.java +++ b/horreum-backend/src/test/java/io/hyperfoil/tools/horreum/svc/BaseServiceTest.java @@ -828,6 +828,13 @@ protected void populateDataFromFiles() throws IOException { assertEquals(1, variables.size()); jsonRequest().body(variables).post("/api/alerting/variables?test=" + t.id).then().statusCode(204); + Action a = new ObjectMapper().readValue( + readFile(p.resolve("new_run_action.json").toFile()), Action.class); + assertEquals("run/new", a.event); + //This request should return a bad request as the url is not set + jsonRequest().auth().oauth2(getAdminToken()).body(a).post("/api/action").then().statusCode(400); + + Run r = mapper.readValue( readFile(p.resolve("roadrunner_run.json").toFile()), Run.class); assertEquals("dev-team", r.owner);