diff options
Diffstat (limited to 'utils-test')
3 files changed, 14 insertions, 37 deletions
diff --git a/utils-test/pom.xml b/utils-test/pom.xml index c32085e2..405b7275 100644 --- a/utils-test/pom.xml +++ b/utils-test/pom.xml @@ -3,7 +3,7 @@ ONAP Policy Engine - Common Modules ================================================================================ Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved. - Modificaitons Copyright (C) 2023 Nordix Foundation. + Modificaitons Copyright (C) 2023-2024 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -42,12 +42,10 @@ <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpkix-fips</artifactId> - <version>1.0.7</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-jexl3</artifactId> - <version>3.1</version> </dependency> <dependency> <groupId>org.onap.policy.common</groupId> diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java index 4aedf872..8276ea4c 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java @@ -3,6 +3,7 @@ * policy-management * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,7 +42,6 @@ import lombok.Getter; import org.apache.commons.jexl3.JexlBuilder; import org.apache.commons.jexl3.JexlContext; import org.apache.commons.jexl3.JexlEngine; -import org.apache.commons.jexl3.JexlException; import org.apache.commons.jexl3.MapContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -201,24 +201,19 @@ public class GsonTestUtils { while (mat.find(ilast)) { // append segment that appears between last match and this int inext = mat.start(); - bldr.append(text.substring(ilast, inext)); + bldr.append(text, ilast, inext); // next match begins after the current match ilast = mat.end(); // interpolate the script String script = mat.group(1); - try { - /* - * Note: must use "eng" instead of "engineInstance" to ensure that we use - * the same engine that's associated with the bindings. - */ - Object result = eng.createExpression(script).evaluate(context); - bldr.append(result == null ? "null" : result.toString()); - - } catch (JexlException e) { - throw new JsonParseException("cannot expand element: " + mat.group(), e); - } + /* + * Note: must use "eng" instead of "engineInstance" to ensure that we use + * the same engine that's associated with the bindings. + */ + Object result = eng.createExpression(script).evaluate(context); + bldr.append(result == null ? "null" : result.toString()); } // append final segment diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java index 9de586d6..51522ec0 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +36,8 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import lombok.Getter; +import lombok.Setter; import lombok.ToString; -import org.apache.commons.jexl3.JexlException; import org.junit.Before; import org.junit.Test; @@ -139,11 +140,7 @@ public class GsonTestUtilsTest { data.setText(null); result = utils.applyScripts("use ${obj.text} this", data); assertEquals("use null this", result); - - assertThatThrownBy(() -> utils.applyScripts("use ${obj.text} this", null)) - .isInstanceOf(JsonParseException.class) - .hasCauseInstanceOf(JexlException.class) - .hasMessage("cannot expand element: ${obj.text}"); + assertEquals("use null this", utils.applyScripts("use ${obj.text} this", null)); } @Test @@ -227,25 +224,12 @@ public class GsonTestUtilsTest { assertEquals("[300,{'objE':true,'objEStr':'obj-e-string'},false]".replace('\'', '"'), jsonEl.toString()); } + @Setter + @Getter @ToString public static class Data { private int id; private String text; - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } } } |