m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMartin <marcin.j.chrzanowski@gmail.com>2020-01-12 22:32:59 +0100
committerGitHub <noreply@github.com>2020-01-12 22:32:59 +0100
commit0f31d1f5c267f893d765ccd848b95fc111009de5 (patch)
treecf54497163b95e32fc8932b0ba13acc3fe2ca503 /src/test/java
parent32bfe8f7efc1f4fb99ddf827a19ab466724dac06 (diff)
parentcd247e8d64b2ef0aed7f0afdccd711008cd60fcd (diff)
Merge pull request #116 from m-chrzan/required-attributes
Required attributes
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/pl/edu/mimuw/cloudatlas/agent/modules/StanikTest.java36
1 files changed, 31 insertions, 5 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 f3ea0b0..92ba051 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
@@ -39,7 +39,7 @@ public class StanikTest {
@Before
public void setupLocals() {
- stanik = new Stanik(freshnessPeriod);
+ stanik = new Stanik(new PathName("/new"), freshnessPeriod);
executor = new MockExecutor(stanik);
testTime = ValueUtils.currentTime();
}
@@ -57,9 +57,11 @@ public class StanikTest {
ZMI zmi = stateMessage.getZMI();
assertNull(zmi.getFather());
assertTrue(zmi.getSons().isEmpty());
- assertEquals(1, TestUtil.iterableSize(zmi.getAttributes()));
+ assertEquals(3, TestUtil.iterableSize(zmi.getAttributes()));
+ assertEquals(new ValueInt(0l), zmi.getAttributes().getOrNull("level"));
+ assertEquals(new ValueString("/new"), zmi.getAttributes().getOrNull("owner"));
Map<Attribute, Entry<ValueQuery, ValueTime>> queries = stateMessage.getQueries();
- assertEquals(0, TestUtil.iterableSize(queries.keySet()));
+ assertEquals(2, TestUtil.iterableSize(queries.keySet()));
}
@Test
@@ -112,6 +114,30 @@ public class StanikTest {
}
@Test
+ public void newZoneHasNewLevel() throws Exception {
+ AttributesMap attributes = new AttributesMap();
+ attributes.add("foo", new ValueInt(1337l));
+ attributes.add("bar", new ValueString("baz"));
+ attributes.add("name", new ValueString("new"));
+ attributes.add("timestamp", testTime);
+ UpdateAttributesMessage message = new UpdateAttributesMessage("test_msg", 0, "/new", attributes);
+ stanik.handleTyped(message);
+ GetStateMessage newMessage = new GetStateMessage("test_msg2", 123, ModuleType.TEST, 43);
+ stanik.handleTyped(newMessage);
+
+ StateMessage newReceivedMessage = (StateMessage) executor.messagesToPass.poll();
+ AttributesMap actualAttributes = newReceivedMessage.getZMI().findDescendant("/new").getAttributes();
+ assertEquals(7, TestUtil.iterableSize(actualAttributes));
+ assertEquals(new ValueInt(1337l), actualAttributes.getOrNull("foo"));
+ assertEquals(new ValueString("baz"), actualAttributes.getOrNull("bar"));
+ assertEquals(new ValueString("new"), actualAttributes.getOrNull("name"));
+ assertEquals(new ValueString("/new"), actualAttributes.getOrNull("owner"));
+ assertEquals(new ValueInt(1l), actualAttributes.getOrNull("cardinality"));
+ assertEquals(testTime, actualAttributes.getOrNull("timestamp"));
+ assertEquals(new ValueInt(1l), actualAttributes.getOrNull("level"));
+ }
+
+ @Test
public void updateWithRemovedAttributes() throws Exception {
AttributesMap attributes = new AttributesMap();
attributes.add("foo", new ValueInt(1337l));
@@ -198,7 +224,7 @@ public class StanikTest {
stanik.handleTyped(message);
HashMap<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries();
- assertEquals(1, TestUtil.iterableSize(actualQueries.keySet()));
+ assertEquals(3, TestUtil.iterableSize(actualQueries.keySet()));
assertTrue(actualQueries.containsKey(new Attribute("&query")));
Entry<ValueQuery, ValueTime> timestampedQuery = actualQueries.get(new Attribute("&query"));
assertEquals(new ValueTime(42l), timestampedQuery.getValue());
@@ -222,7 +248,7 @@ public class StanikTest {
stanik.handleTyped(otherMessage);
HashMap<Attribute, Entry<ValueQuery, ValueTime>> actualQueries = stanik.getQueries();
- assertEquals(4, TestUtil.iterableSize(actualQueries.keySet()));
+ assertEquals(6, TestUtil.iterableSize(actualQueries.keySet()));
assertTrue(actualQueries.containsKey(new Attribute("&query1")));
assertTrue(actualQueries.containsKey(new Attribute("&query2")));
assertTrue(actualQueries.containsKey(new Attribute("&query3")));