diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2019-12-31 17:31:38 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2019-12-31 17:32:33 +0100 |
commit | eb7fbbd08bb003a47d9788a9f6476695ab46b271 (patch) | |
tree | 7bdd6f9a29877345e538b1cebb99277fa1aa41d4 /src/test/java/pl/edu/mimuw/cloudatlas | |
parent | 17d87268246d32a75407590f8fef118148b87ccd (diff) |
Add message to set a single attribute
Diffstat (limited to 'src/test/java/pl/edu/mimuw/cloudatlas')
-rw-r--r-- | src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java index 495a012..2e1ccea 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java @@ -7,9 +7,10 @@ import java.util.Map.Entry; import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage; import pl.edu.mimuw.cloudatlas.agent.messages.GetStateMessage; -import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage; import pl.edu.mimuw.cloudatlas.agent.messages.RemoveZMIMessage; import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.SetAttributeMessage; +import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage; import pl.edu.mimuw.cloudatlas.agent.messages.UpdateQueriesMessage; import pl.edu.mimuw.cloudatlas.agent.MockExecutor; @@ -236,4 +237,59 @@ public class StanikTest { stanik.getHierarchy().findDescendant("/new"); } + + @Test + public void setOldAttribute() throws Exception { + AttributesMap attributes = new AttributesMap(); + attributes.add("foo", new ValueInt(1337l)); + attributes.add("name", new ValueString("new")); + attributes.add("timestamp", new ValueTime(42l)); + UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); + stanik.handleTyped(message); + + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), new ValueTime(40l)); + stanik.handleTyped(setMessage); + + AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); + assertEquals(3, TestUtil.iterableSize(actualAttributes)); + assertEquals(new ValueInt(43l), actualAttributes.getOrNull("foo")); + assertEquals(new ValueTime(42l), actualAttributes.getOrNull("timestamp")); + } + + @Test + public void setOldAttribute2() throws Exception { + AttributesMap attributes = new AttributesMap(); + attributes.add("foo", new ValueInt(1337l)); + attributes.add("name", new ValueString("new")); + attributes.add("timestamp", new ValueTime(42l)); + UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); + stanik.handleTyped(message); + + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("foo"), new ValueInt(43l), new ValueTime(43l)); + stanik.handleTyped(setMessage); + + AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); + assertEquals(3, TestUtil.iterableSize(actualAttributes)); + assertEquals(new ValueInt(43l), actualAttributes.getOrNull("foo")); + assertEquals(new ValueTime(43l), actualAttributes.getOrNull("timestamp")); + } + + @Test + public void setNewAttribute() throws Exception { + AttributesMap attributes = new AttributesMap(); + attributes.add("foo", new ValueInt(1337l)); + attributes.add("name", new ValueString("new")); + attributes.add("timestamp", new ValueTime(42l)); + UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes); + stanik.handleTyped(message); + + SetAttributeMessage setMessage = new SetAttributeMessage("test_msg2", 0, "/new", new Attribute("bar"), new ValueInt(43l), new ValueTime(43l)); + stanik.handleTyped(setMessage); + + AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes(); + assertEquals(4, TestUtil.iterableSize(actualAttributes)); + assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo")); + assertEquals(new ValueInt(43l), actualAttributes.getOrNull("bar")); + assertEquals(new ValueTime(43l), actualAttributes.getOrNull("timestamp")); + } } |