m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-27 21:08:44 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-12-27 21:08:44 +0100
commit5f7e37d7b26832b3b512f9dda310cb9bc92c93fb (patch)
tree0886802b0b472f466697b4fc05c72e3d1d87b2c2 /src/test/java
parent614e4e0d4fd07967f928fac122cc36b66a513944 (diff)
Create new zones with UpdateAttributes message
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java38
1 files changed, 38 insertions, 0 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 1c1e216..31b701d 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,11 +7,13 @@ import pl.edu.mimuw.cloudatlas.agent.messages.AgentMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.GetHierarchyMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.HierarchyMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage;
import pl.edu.mimuw.cloudatlas.agent.MockExecutor;
import pl.edu.mimuw.cloudatlas.model.Attribute;
import pl.edu.mimuw.cloudatlas.model.AttributesMap;
import pl.edu.mimuw.cloudatlas.model.Value;
import pl.edu.mimuw.cloudatlas.model.ValueInt;
+import pl.edu.mimuw.cloudatlas.model.ValueString;
import pl.edu.mimuw.cloudatlas.model.ZMI;
import org.junit.Before;
@@ -65,4 +67,40 @@ public class StanikTest {
AttributesMap newAttributes = newReceivedMessage.getZMI().getAttributes();
assertNull(newAttributes.getOrNull("foo"));
}
+
+ @Test
+ public void updateRootAttributes() throws Exception {
+ AttributesMap attributes = new AttributesMap();
+ attributes.add("foo", new ValueInt(1337l));
+ attributes.add("bar", new ValueString("baz"));
+ UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/", attributes);
+ stanik.handleTyped(message);
+ AttributesMap actualAttributes = stanik.getHierarchy().getAttributes();
+ assertEquals(2, countAttributes(actualAttributes));
+ assertEquals(new ValueInt(1337l), actualAttributes.get("foo"));
+ assertEquals(new ValueString("baz"), actualAttributes.get("bar"));
+ }
+
+ @Test
+ public void updateWithNewZone() throws Exception {
+ AttributesMap attributes = new AttributesMap();
+ attributes.add("foo", new ValueInt(1337l));
+ attributes.add("bar", new ValueString("baz"));
+ attributes.add("name", new ValueString("new"));
+ UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes);
+ stanik.handleTyped(message);
+ AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes();
+ assertEquals(3, countAttributes(actualAttributes));
+ assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo"));
+ assertEquals(new ValueString("baz"), actualAttributes.getOrNull("bar"));
+ }
+
+ public int countAttributes(AttributesMap attributes) {
+ int count = 0;
+ for (Entry<Attribute, Value> attribute : attributes) {
+ count++;
+ }
+
+ return count;
+ }
}