m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/pl/edu
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/pl/edu')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java41
1 files changed, 23 insertions, 18 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 12fa531..dd44e8f 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
@@ -1,11 +1,13 @@
package pl.edu.mimuw.cloudatlas.agent.modules;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
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.GetStateMessage;
+import pl.edu.mimuw.cloudatlas.agent.messages.StateMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.ResponseMessage;
import pl.edu.mimuw.cloudatlas.agent.messages.UpdateAttributesMessage;
import pl.edu.mimuw.cloudatlas.agent.MockExecutor;
@@ -13,6 +15,7 @@ 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.ValueQuery;
import pl.edu.mimuw.cloudatlas.model.ValueString;
import pl.edu.mimuw.cloudatlas.model.ValueTime;
import pl.edu.mimuw.cloudatlas.model.ZMI;
@@ -32,34 +35,36 @@ public class StanikTest {
}
@Test
- public void getEmptyHierarchy() throws Exception {
- GetHierarchyMessage message = new GetHierarchyMessage("test_msg", 0, ModuleType.TEST, 42);
+ public void getEmptyState() throws Exception {
+ GetStateMessage message = new GetStateMessage("test_msg", 0, ModuleType.TEST, 42);
stanik.handleTyped(message);
assertEquals(1, executor.messagesToPass.size());
ResponseMessage receivedMessage = (ResponseMessage) executor.messagesToPass.take();
assertEquals(ModuleType.TEST, receivedMessage.getDestinationModule());
- assertEquals(ResponseMessage.Type.HIERARCHY, receivedMessage.getType());
+ assertEquals(ResponseMessage.Type.STATE, receivedMessage.getType());
assertEquals(42, receivedMessage.getRequestId());
- HierarchyMessage hierarchyMessage = (HierarchyMessage) receivedMessage;
- ZMI zmi = hierarchyMessage.getZMI();
+ StateMessage stateMessage = (StateMessage) receivedMessage;
+ ZMI zmi = stateMessage.getZMI();
assertNull(zmi.getFather());
assertTrue(zmi.getSons().isEmpty());
- assertEquals(1, countAttributes(zmi.getAttributes()));
+ assertEquals(1, iterableSize(zmi.getAttributes()));
+ Map<Attribute, Entry<ValueQuery, ValueTime>> queries = stateMessage.getQueries();
+ assertEquals(0, iterableSize(queries.keySet()));
}
@Test
public void hierarchyIsDeepCopy() throws Exception {
- GetHierarchyMessage message = new GetHierarchyMessage("test_msg", 0, ModuleType.TEST, 42);
+ GetStateMessage message = new GetStateMessage("test_msg", 0, ModuleType.TEST, 42);
stanik.handleTyped(message);
- HierarchyMessage receivedMessage = (HierarchyMessage) executor.messagesToPass.poll();
+ StateMessage receivedMessage = (StateMessage) executor.messagesToPass.poll();
assertNotNull(receivedMessage);
AttributesMap attributes = receivedMessage.getZMI().getAttributes();
assertNull(attributes.getOrNull("foo"));
attributes.add("foo", new ValueInt(1337l));
- GetHierarchyMessage newMessage = new GetHierarchyMessage("test_msg2", 123, ModuleType.TEST, 43);
+ GetStateMessage newMessage = new GetStateMessage("test_msg2", 123, ModuleType.TEST, 43);
stanik.handleTyped(newMessage);
- HierarchyMessage newReceivedMessage = (HierarchyMessage) executor.messagesToPass.poll();
+ StateMessage newReceivedMessage = (StateMessage) executor.messagesToPass.poll();
AttributesMap newAttributes = newReceivedMessage.getZMI().getAttributes();
assertNull(newAttributes.getOrNull("foo"));
}
@@ -73,7 +78,7 @@ public class StanikTest {
UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/", attributes);
stanik.handleTyped(message);
AttributesMap actualAttributes = stanik.getHierarchy().getAttributes();
- assertEquals(3, countAttributes(actualAttributes));
+ assertEquals(3, iterableSize(actualAttributes));
assertEquals(new ValueInt(1337l), actualAttributes.get("foo"));
assertEquals(new ValueString("baz"), actualAttributes.get("bar"));
assertEquals(new ValueTime("2012/12/21 04:20:00.000"), actualAttributes.getOrNull("timestamp"));
@@ -89,7 +94,7 @@ public class StanikTest {
UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes);
stanik.handleTyped(message);
AttributesMap actualAttributes = stanik.getHierarchy().findDescendant("/new").getAttributes();
- assertEquals(4, countAttributes(actualAttributes));
+ assertEquals(4, iterableSize(actualAttributes));
assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo"));
assertEquals(new ValueString("baz"), actualAttributes.getOrNull("bar"));
assertEquals(new ValueString("new"), actualAttributes.getOrNull("name"));
@@ -112,7 +117,7 @@ public class StanikTest {
stanik.handleTyped(newMessage);
AttributesMap actualAttributes = stanik.getHierarchy().getAttributes();
- assertEquals(2, countAttributes(actualAttributes));
+ assertEquals(2, iterableSize(actualAttributes));
assertEquals(new ValueInt(1338l), actualAttributes.getOrNull("foo"));
assertEquals(new ValueTime("2012/12/21 04:20:42.000"), actualAttributes.getOrNull("timestamp"));
}
@@ -132,14 +137,14 @@ public class StanikTest {
stanik.handleTyped(newMessage);
AttributesMap actualAttributes = stanik.getHierarchy().getAttributes();
- assertEquals(2, countAttributes(actualAttributes));
+ assertEquals(2, iterableSize(actualAttributes));
assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo"));
assertEquals(new ValueTime("2012/12/21 04:20:00.000"), actualAttributes.getOrNull("timestamp"));
}
- public int countAttributes(AttributesMap attributes) {
+ public <T> int iterableSize(Iterable<T> iterable) {
int count = 0;
- for (Entry<Attribute, Value> attribute : attributes) {
+ for (T attribute : iterable) {
count++;
}