Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Bug fix for META_ATTRIBUTE_WRITE_VALUE_CONVERTER in Protocols

Rich Turner56ade88d4a59
diff --git a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
index 20c4c037d..a9323e6a7 100644
--- a/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
+++ b/agent/src/main/java/org/openremote/agent/protocol/Protocol.java
@@ -588,6 +588,8 @@ public interface Protocol extends ContainerService {
if (converterResult.key) {
return converterResult;
}
+
+ value = converterResult.value;
}
// dynamic value insertion
diff --git a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
index d659f9049..33263abfe 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/http/HttpClientProtocolTest.groovy
@@ -69,6 +69,7 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
private int pollCountSlow = 0
private boolean putRequestWithHeadersCalled = false
private int successFailureCount = 0
+ private String dynamicPathParam = ""
@Override
void filter(ClientRequestContext requestContext) throws IOException {
@@ -215,7 +216,12 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
}
}
break
- case "https://mockapi/value/50/set":
+ case "https://mockapi/value/on/set":
+ dynamicPathParam = "on"
+ requestContext.abortWith(Response.ok().build())
+ return
+ case "https://mockapi/value/off/set":
+ dynamicPathParam = "off"
requestContext.abortWith(Response.ok().build())
return
case "https://mockapi/get_poll_slow":
@@ -484,10 +490,14 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
)
),
// attribute that sends requests to the server using GET with dynamic path
- new AssetAttribute("getRequestWithDynamicPath", AttributeValueType.OBJECT)
+ new AssetAttribute("getRequestWithDynamicPath", AttributeValueType.BOOLEAN)
.addMeta(
new MetaItem(MetaItemType.AGENT_LINK, new AttributeRef(agent.id, "protocolConfig").toArrayValue()),
- new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create('value/{$value}/set'))
+ new MetaItem(HttpClientProtocol.META_ATTRIBUTE_PATH, Values.create('value/{$value}/set')),
+ new MetaItem(Protocol.META_ATTRIBUTE_WRITE_VALUE_CONVERTER, Values.parse("{\n" +
+ " \"TRUE\": \"on\",\n" +
+ " \"FALSE\": \"off\"\n" +
+ "}").get())
),
// attribute that polls the server using GET and uses regex filter on response
new AssetAttribute("getPollSlow", AttributeValueType.NUMBER)
@@ -547,6 +557,30 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
assert mockServer.putRequestWithHeadersCalled
}
+ when: "a linked attribute value is updated to true the path should contain the dynamic mapped value of 'on'"
+ def count = mockServer.successFailureCount
+ attributeEvent = new AttributeEvent(asset.id,
+ "getRequestWithDynamicPath",
+ Values.create(true))
+ assetProcessingService.sendAttributeEvent(attributeEvent)
+
+ then: "the server should have received the request and returned a 200"
+ conditions.eventually {
+ assert mockServer.dynamicPathParam == "on"
+ }
+
+ when: "a linked attribute value is updated to false the path should contain the dynamic mapped value of 'off'"
+ count = mockServer.successFailureCount
+ attributeEvent = new AttributeEvent(asset.id,
+ "getRequestWithDynamicPath",
+ Values.create(false))
+ assetProcessingService.sendAttributeEvent(attributeEvent)
+
+ then: "the server should have received the request and returned a 200"
+ conditions.eventually {
+ assert mockServer.dynamicPathParam == "off"
+ }
+
when: "a protocol configurations are added to the agent that don't use ping mechanism"
agent.addAttributes(
initProtocolConfiguration(new AssetAttribute("protocolConfig2"), HttpClientProtocol.PROTOCOL_NAME)
@@ -675,8 +709,10 @@ class HttpClientProtocolTest extends Specification implements ManagerContainerTr
assert agentService.getProtocolConnectionStatus(new AttributeRef(agent.id, "protocolConfig3")) == ConnectionStatus.DISABLED
}
- and: "the poll request will no longer reach the server"
- def count = mockServer.successFailureCount
+ when: "the success/failure count is stored"
+ count = mockServer.successFailureCount
+
+ then: "the poll request will no longer reach the server (the success/failure count shouldn't change)"
Thread.sleep(50)
assert mockServer.successFailureCount == count