Skip to content

Commit

Permalink
fix: formatting issues and failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Nov 24, 2021
1 parent 99574e2 commit 2134eb5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class EntityService(
.setHeader("Link", httpLinkHeaderBuilder(contextUrl))
.setHeader("Authorization", "Bearer $token")
.build()
return try {
try {
logger.debug("Appending attributes $serializedPayload to entity $entityId")
val response = httpClient.send(request, HttpResponse.BodyHandlers.ofString())
logger.debug("Http response status code: ${response.statusCode()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class TemporalService(
ResourceNotFound("Entity not found").left()
else ContextBrokerError(
"Failed to retrieve entity, " +
"received ${httpResponse.statusCode()} (${httpResponse.body()}) from context broker"
"received ${httpResponse.statusCode()} (${httpResponse.body()}) from context broker"
).left()
} catch (e: IOException) {
val errorMessage = e.message ?: "Error encountered while processing GET request"
Expand Down
8 changes: 4 additions & 4 deletions kngsild/src/main/kotlin/io/egm/kngsild/utils/NgsiLdUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun NgsildEntity.hasAttribute(attributeName: String, datasetId: URI? = null): Bo
it["datasetId"] == null
}?.isNotEmpty() ?: false
}
is Map<*,*> -> {
is Map<*, *> -> {
if (datasetId != null)
attributeEntry["datasetId"] == datasetId.toString()
else
Expand All @@ -149,14 +149,14 @@ fun NgsildEntity.getAttribute(attributeName: String, datasetId: URI? = null): Ng
is List<*> -> {
(attributeEntry as NgsildMultiAttribute?)?.find {
if (datasetId != null)
it["datasetId"] == datasetId.toString()
it["datasetId"] == datasetId
else
it["datasetId"] == null
}
}
is Map<*,*> -> {
is Map<*, *> -> {
val ngsiLdAttribute = attributeEntry as NgsiLdAttribute
if (datasetId != null && ngsiLdAttribute["datasetId"] == datasetId.toString())
if (datasetId != null && ngsiLdAttribute["datasetId"] == datasetId)
ngsiLdAttribute
else if (datasetId == null && !ngsiLdAttribute.containsKey("datasetId"))
ngsiLdAttribute
Expand Down
49 changes: 26 additions & 23 deletions kngsild/src/test/kotlin/io/egm/kngsild/api/EntityServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,20 @@ class EntityServiceTest {

assertTrue(response.isRight())

verify(postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
verify(
postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
{
"volume": {
"type": "Property",
"value": 2.0
}
}
""".trimIndent()
""".trimIndent()
)
)
)
)
}

Expand Down Expand Up @@ -334,10 +335,11 @@ class EntityServiceTest {

assertTrue(response.isRight())

verify(postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
verify(
postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
{
"volume": [{
"type": "Property",
Expand All @@ -348,9 +350,9 @@ class EntityServiceTest {
"datasetId": "urn:ngsi-ld:Dataset:123"
}]
}
""".trimIndent()
""".trimIndent()
)
)
)
)
}

Expand Down Expand Up @@ -392,10 +394,11 @@ class EntityServiceTest {

assertTrue(response.isRight())

verify(postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
verify(
postRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs"))
.withRequestBody(
equalToJson(
"""
{
"volume": {
"type": "Property",
Expand All @@ -406,9 +409,9 @@ class EntityServiceTest {
"value": 23.0
}
}
""".trimIndent()
""".trimIndent()
)
)
)
)
}

Expand Down Expand Up @@ -442,16 +445,16 @@ class EntityServiceTest {

verify(
patchRequestedFor(urlEqualTo("/ngsi-ld/v1/entities/urn:ngsi-ld:Building:01/attrs/temperature"))
.withRequestBody(
equalToJson(
"""
.withRequestBody(
equalToJson(
"""
{
"value": 2.1,
"observedAt": "2021-08-12T09:44:00.80868Z"
}
""".trimIndent()
""".trimIndent()
)
)
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class TemporalServiceTest {
Assertions.assertTrue(response.isRight())

WireMock.verify(
WireMock.postRequestedFor(WireMock.urlEqualTo("/ngsi-ld/v1/temporal/entities/urn:ngsi-ld:Building:01/attrs"))
WireMock.postRequestedFor(
WireMock.urlEqualTo("/ngsi-ld/v1/temporal/entities/urn:ngsi-ld:Building:01/attrs")
)
.withRequestBody(
WireMock.equalToJson(
"""
Expand Down

0 comments on commit 2134eb5

Please sign in to comment.