Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
org.etsi.osl.osom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSL
code
org.etsi.osl.osom
Commits
d9166599
Commit
d9166599
authored
4 months ago
by
Eduardo Santos
Browse files
Options
Downloads
Patches
Plain Diff
Fixed LCM escape method
parent
7ca7331d
No related branches found
Branches containing commit
No related tags found
2 merge requests
!24
Added new textEscape method
,
!23
Added new textEscape method
Pipeline
#11285
passed
4 months ago
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java
+28
-8
28 additions, 8 deletions
src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java
src/test/java/org/etsi/osl/osom/LcmBaseExecutorTest.java
+62
-0
62 additions, 0 deletions
src/test/java/org/etsi/osl/osom/LcmBaseExecutorTest.java
with
90 additions
and
8 deletions
src/main/java/org/etsi/osl/osom/lcm/LcmBaseExecutor.java
+
28
−
8
View file @
d9166599
package
org.etsi.osl.osom.lcm
;
package
org.etsi.osl.osom.lcm
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.time.LocalDate
;
import
java.time.LocalTime
;
import
java.time.OffsetDateTime
;
import
java.time.OffsetDateTime
;
import
java.time.ZoneOffset
;
import
java.time.ZoneOffset
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -11,15 +14,20 @@ import java.util.function.Consumer;
...
@@ -11,15 +14,20 @@ import java.util.function.Consumer;
import
javax.net.ssl.SSLException
;
import
javax.net.ssl.SSLException
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
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.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.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectWriter
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.Configuration
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.Option
;
import
com.jayway.jsonpath.Option
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.text.StringEscapeUtils
;
import
org.etsi.osl.osom.partnerservices.GenericClient
;
import
org.etsi.osl.osom.partnerservices.GenericClient
;
import
org.etsi.osl.tmf.common.model.Any
;
import
org.etsi.osl.tmf.common.model.Any
;
import
org.etsi.osl.tmf.common.model.EValueType
;
import
org.etsi.osl.tmf.common.model.EValueType
;
...
@@ -126,7 +134,7 @@ public abstract class LcmBaseExecutor {
...
@@ -126,7 +134,7 @@ public abstract class LcmBaseExecutor {
}
}
pr
ivate
Optional
<
Characteristic
>
getCharacteristicByName
(
String
charName
)
{
pr
otected
Optional
<
Characteristic
>
getCharacteristicByName
(
String
charName
)
{
List
<
Characteristic
>
serviceCharacteristic
;
List
<
Characteristic
>
serviceCharacteristic
;
if
(
lcmspec
.
getLcmrulephase
().
equals
(
"PRE_PROVISION"
)
||
this
.
vars
.
getService
()
==
null
)
{
if
(
lcmspec
.
getLcmrulephase
().
equals
(
"PRE_PROVISION"
)
||
this
.
vars
.
getService
()
==
null
)
{
...
@@ -225,19 +233,31 @@ public abstract class LcmBaseExecutor {
...
@@ -225,19 +233,31 @@ public abstract class LcmBaseExecutor {
return
-
1
;
return
-
1
;
}
}
public
String
getCharValAsString
(
String
charName
)
{
public
String
getCharValAsString
(
String
charName
)
{
logger
.
debug
(
"getCharValAsString "
+
charName
);
Optional
<
Characteristic
>
characteristic
=
getCharacteristicByName
(
charName
);
Optional
<
Characteristic
>
c
=
getCharacteristicByName
(
charName
);
if
(
c
.
isPresent
())
{
logger
.
info
(
"Getting characteristic value as a string..."
);
logger
.
debug
(
"getCharValAsString "
+
c
.
get
().
getValue
().
getValue
());
return
c
.
get
().
getValue
().
getValue
();
if
(
characteristic
.
isPresent
())
{
return
characteristic
.
get
().
getValue
().
getValue
();
}
}
logger
.
debug
(
"getCharValAsString NULL "
);
return
null
;
return
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
)
{
public
Boolean
getCharValFromBooleanType
(
String
charName
)
{
logger
.
debug
(
"getCharValFromBooleanType "
+
charName
);
logger
.
debug
(
"getCharValFromBooleanType "
+
charName
);
...
...
This diff is collapsed.
Click to expand it.
src/test/java/org/etsi/osl/osom/LcmBaseExecutorTest.java
0 → 100644
+
62
−
0
View file @
d9166599
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
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment