Inherit Intent Key on compilation
- Added Intent#key() method description
- Inherit key field from parent Intent during Intent
compilation process
- Added assertion to existing unit tests
Change-Id: Iff85c5ec448b3f378957b7a20af865ad96cc3216
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
index 4dc5045..d6333ff 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompilerTest.java
@@ -39,10 +39,12 @@
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.easymock.EasyMock.*;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onosproject.net.NetTestTools.connectPoint;
@@ -80,6 +82,7 @@
private HostId hostTwoId = HostId.hostId(HOST_TWO);
private HostService mockHostService;
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
@@ -188,5 +191,9 @@
egressPoints = ImmutableSet.of(new FilteredConnectPoint(connectPoint(HOP_1, PORT_1)));
assertThat(reverseLCIntent.filteredEgressPoints(), is(egressPoints));
+
+ assertThat("key is inherited",
+ result.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
}
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
index 4c45bb4..3970f8d 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompilerTest.java
@@ -54,6 +54,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.onlab.packet.EthType.EtherType.IPV4;
@@ -116,6 +117,11 @@
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
+
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(links.size()));
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
index 60da118..ce5f3b7 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompilerTest.java
@@ -146,6 +146,7 @@
assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -178,6 +179,7 @@
assertThat(linkIntent.links(), linksHasPath("inner1", "inner2"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -213,6 +215,7 @@
}
assertThat(linkIntent.links(), linksHasPath("n1", egress));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -243,6 +246,7 @@
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
assertThat(linkIntent.links(), linksHasPath("i2", "i3"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -280,6 +284,7 @@
assertThat(linkIntent.links(), linksHasPath("of2", "of3"));
assertThat(linkIntent.links(), linksHasPath("of3", "of4"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
@@ -323,6 +328,7 @@
assertThat(linkIntent.links(), linksHasPath("of3", "of4"));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
index e9f5170..f7579d8 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PathIntentCompilerTest.java
@@ -60,6 +60,7 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
@@ -783,6 +784,10 @@
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
FlowRule rule1 = rules.stream()
@@ -987,8 +992,8 @@
.collect(Collectors.toSet());
assertThat(vlanRules, hasSize(1));
L2ModificationInstruction.ModVlanIdInstruction vlanRule = vlanRules.iterator().next();
- assertThat(vlanRule.vlanId().toShort(), greaterThan((short) VlanId.NO_VID));
- assertThat(vlanRule.vlanId().toShort(), lessThan((short) VlanId.MAX_VLAN));
+ assertThat(vlanRule.vlanId().toShort(), greaterThan(VlanId.NO_VID));
+ assertThat(vlanRule.vlanId().toShort(), lessThan(VlanId.MAX_VLAN));
vlanToEncap = vlanRule.vlanId();
} else if (!isIngress && !isEgress) {
@@ -998,8 +1003,8 @@
.collect(Collectors.toSet());
assertThat(vlanRules, hasSize(1));
L2ModificationInstruction.ModVlanIdInstruction vlanRule = vlanRules.iterator().next();
- assertThat(vlanRule.vlanId().toShort(), greaterThan((short) VlanId.NO_VID));
- assertThat(vlanRule.vlanId().toShort(), lessThan((short) VlanId.MAX_VLAN));
+ assertThat(vlanRule.vlanId().toShort(), greaterThan(VlanId.NO_VID));
+ assertThat(vlanRule.vlanId().toShort(), lessThan(VlanId.MAX_VLAN));
vlanToEncap = vlanRule.vlanId();
} else {
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
index d61e01d..65251dd 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompilerTest.java
@@ -39,10 +39,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
+import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.fail;
@@ -159,6 +161,7 @@
assertThat(forwardIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(forwardIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
+ assertThat("key is inherited", forwardResultIntent.key(), is(intent.key()));
}
/**
@@ -193,6 +196,7 @@
assertThat(reverseLinkCollectionIntent.filteredIngressPoints(), is(ImmutableSet.of(ingressPoint)));
assertThat(reverseLinkCollectionIntent.filteredEgressPoints(), is(ImmutableSet.of(egressPoint)));
}
+ assertThat("key is inherited", reverseResultIntent.key(), is(intent.key()));
}
/**
@@ -215,6 +219,10 @@
List<Intent> compiled = sut.compile(intent, null);
+ assertThat("key is inherited",
+ compiled.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
assertThat(compiled, hasSize(1));
assertThat(compiled.get(0), is(instanceOf(LinkCollectionIntent.class)));
LinkCollectionIntent linkCollectionIntent = (LinkCollectionIntent) compiled.get(0);
@@ -245,6 +253,11 @@
assertThat(compiledIntents, Matchers.notNullValue());
assertThat(compiledIntents, hasSize(1));
+
+ assertThat("key is inherited",
+ compiledIntents.stream().map(Intent::key).collect(Collectors.toList()),
+ everyItem(is(intent.key())));
+
}
/**
diff --git a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
index cb13c68..eec242c 100644
--- a/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
+++ b/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompilerTest.java
@@ -37,7 +37,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -150,6 +149,7 @@
assertThat(linkIntent.links(), linksHasPath("h7", "h8"));
assertThat(linkIntent.links(), linksHasPath("h8", "egress"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -182,6 +182,7 @@
assertThat(linkIntent.links(), linksHasPath("inner2", "egress1"));
assertThat(linkIntent.links(), linksHasPath("inner2", "egress2"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -215,6 +216,7 @@
}
assertThat(linkIntent.links(), linksHasPath(ingress, "n1"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -245,6 +247,7 @@
assertThat(linkIntent.links(), linksHasPath("i1", "i2"));
assertThat(linkIntent.links(), linksHasPath("i1", "i3"));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
/**
@@ -291,6 +294,7 @@
assertThat("Link collection egress points do not match base intent",
linkIntent.filteredEgressPoints().equals(intent.filteredEgressPoints()));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
@@ -342,6 +346,7 @@
linkIntent.filteredEgressPoints().equals(intent.filteredEgressPoints()));
assertThat(linkIntent.selector(), is(ipPrefixSelector));
}
+ assertThat("key is inherited", resultIntent.key(), is(intent.key()));
}
}