Loading src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java +28 −8 Original line number Diff line number Diff line package org.etsi.osl.osom.lcm; import java.io.File; import java.io.IOException; import java.time.LocalDate; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.ArrayList; Loading @@ -11,15 +14,20 @@ import java.util.function.Consumer; import javax.net.ssl.SSLException; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.exc.StreamWriteException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.DatabindException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.node.ArrayNode; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Option; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.text.StringEscapeUtils; import org.etsi.osl.osom.partnerservices.GenericClient; import org.etsi.osl.tmf.common.model.Any; import org.etsi.osl.tmf.common.model.EValueType; Loading Loading @@ -126,7 +134,7 @@ public abstract class LcmBaseExecutor { } private Optional<Characteristic> getCharacteristicByName(String charName) { protected Optional<Characteristic> getCharacteristicByName(String charName) { List<Characteristic> serviceCharacteristic; if (lcmspec.getLcmrulephase().equals("PRE_PROVISION") || this.vars.getService() == null) { Loading Loading @@ -225,20 +233,32 @@ public abstract class LcmBaseExecutor { return -1; } public String getCharValAsString(String charName) { logger.debug("getCharValAsString " + charName); Optional<Characteristic> c = getCharacteristicByName(charName); Optional<Characteristic> characteristic = getCharacteristicByName(charName); if (c.isPresent()) { logger.debug("getCharValAsString " + c.get().getValue().getValue()); return c.get().getValue().getValue(); logger.info("Getting characteristic value as a string..."); if (characteristic.isPresent()) { return characteristic.get().getValue().getValue(); } return null; } logger.debug("getCharValAsString NULL "); public String escapeText(String s) { if (s == null || s.isEmpty()) { logger.debug("escapeText NULL "); return null; } logger.info("Escaping string..."); return "\"" + StringEscapeUtils.escapeJava(s) + "\""; } public Boolean getCharValFromBooleanType(String charName) { logger.debug("getCharValFromBooleanType " + charName); Optional<Characteristic> c = getCharacteristicByName(charName); Loading src/test/java/org/etsi/osl/osom/LcmBaseExecutorTest.java 0 → 100644 +62 −0 Original line number Diff line number Diff line package org.etsi.osl.osom; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import java.util.Optional; import org.etsi.osl.tmf.common.model.Any; import org.etsi.osl.tmf.common.model.service.Characteristic; import org.etsi.osl.osom.LcmBaseExecutorTest.TestLcmBaseExecutor; import org.etsi.osl.osom.lcm.LcmBaseExecutor; import org.junit.Before; import org.junit.Test; public class LcmBaseExecutorTest { private LcmBaseExecutor executor; @Before public void setUp() { executor = spy(new TestLcmBaseExecutor()); } @Test public void testGetCharValAsString() { // Test the method String result = executor.getCharValAsString("Parameter"); String expected = "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]"; assertEquals(expected, result); } @Test public void testEscapeText() { String input = "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]"; String expected = "\"" + input.replace("\"", "\\\"") + "\""; String result = executor.escapeText(input); assertEquals(expected, result); } static class TestLcmBaseExecutor extends LcmBaseExecutor { @Override public void exec() { } @Override protected Optional<Characteristic> getCharacteristicByName(String charName) { Any anyValue = new Any(); anyValue.setValue( "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]" ); Characteristic characteristic = new Characteristic(); characteristic.setName("Parameter"); characteristic.setValue(anyValue); return Optional.of(characteristic); } } } Loading
src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java +28 −8 Original line number Diff line number Diff line package org.etsi.osl.osom.lcm; import java.io.File; import java.io.IOException; import java.time.LocalDate; import java.time.LocalTime; import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.ArrayList; Loading @@ -11,15 +14,20 @@ import java.util.function.Consumer; import javax.net.ssl.SSLException; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.exc.StreamWriteException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.DatabindException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.node.ArrayNode; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.Option; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.text.StringEscapeUtils; import org.etsi.osl.osom.partnerservices.GenericClient; import org.etsi.osl.tmf.common.model.Any; import org.etsi.osl.tmf.common.model.EValueType; Loading Loading @@ -126,7 +134,7 @@ public abstract class LcmBaseExecutor { } private Optional<Characteristic> getCharacteristicByName(String charName) { protected Optional<Characteristic> getCharacteristicByName(String charName) { List<Characteristic> serviceCharacteristic; if (lcmspec.getLcmrulephase().equals("PRE_PROVISION") || this.vars.getService() == null) { Loading Loading @@ -225,20 +233,32 @@ public abstract class LcmBaseExecutor { return -1; } public String getCharValAsString(String charName) { logger.debug("getCharValAsString " + charName); Optional<Characteristic> c = getCharacteristicByName(charName); Optional<Characteristic> characteristic = getCharacteristicByName(charName); if (c.isPresent()) { logger.debug("getCharValAsString " + c.get().getValue().getValue()); return c.get().getValue().getValue(); logger.info("Getting characteristic value as a string..."); if (characteristic.isPresent()) { return characteristic.get().getValue().getValue(); } return null; } logger.debug("getCharValAsString NULL "); public String escapeText(String s) { if (s == null || s.isEmpty()) { logger.debug("escapeText NULL "); return null; } logger.info("Escaping string..."); return "\"" + StringEscapeUtils.escapeJava(s) + "\""; } public Boolean getCharValFromBooleanType(String charName) { logger.debug("getCharValFromBooleanType " + charName); Optional<Characteristic> c = getCharacteristicByName(charName); Loading
src/test/java/org/etsi/osl/osom/LcmBaseExecutorTest.java 0 → 100644 +62 −0 Original line number Diff line number Diff line package org.etsi.osl.osom; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import java.util.Optional; import org.etsi.osl.tmf.common.model.Any; import org.etsi.osl.tmf.common.model.service.Characteristic; import org.etsi.osl.osom.LcmBaseExecutorTest.TestLcmBaseExecutor; import org.etsi.osl.osom.lcm.LcmBaseExecutor; import org.junit.Before; import org.junit.Test; public class LcmBaseExecutorTest { private LcmBaseExecutor executor; @Before public void setUp() { executor = spy(new TestLcmBaseExecutor()); } @Test public void testGetCharValAsString() { // Test the method String result = executor.getCharValAsString("Parameter"); String expected = "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]"; assertEquals(expected, result); } @Test public void testEscapeText() { String input = "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]"; String expected = "\"" + input.replace("\"", "\\\"") + "\""; String result = executor.escapeText(input); assertEquals(expected, result); } static class TestLcmBaseExecutor extends LcmBaseExecutor { @Override public void exec() { } @Override protected Optional<Characteristic> getCharacteristicByName(String charName) { Any anyValue = new Any(); anyValue.setValue( "[{\"device\": {\"ipv4Address\": {}, \"networkAccessIdentifier\": \"123456789@domain.com\", \"phoneNumber\": \"+123456789\"}, \"provisioningId\": \"3fa85f64-5717-4562-b3fc-2c963f66afa6\", \"qosProfile\": \"QOS_A\", \"status\": \"AVAILABLE\", \"startedAt\": \"2024-12-12T09:52:26Z\"}]" ); Characteristic characteristic = new Characteristic(); characteristic.setName("Parameter"); characteristic.setValue(anyValue); return Optional.of(characteristic); } } }