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/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
index 0ce0b3c..9b131ae 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompiler.java
@@ -244,6 +244,10 @@
             // Create optical connectivity intent
             connectivityIntent = OpticalConnectivityIntent.builder()
                     .appId(appId)
+                    // TODO New top-level Intent created and submitted
+                    // during compilation.
+                    // We'll need to track inter-Intent dependency,
+                    // but `key` field cannot be used for the purpose.
                     .src(srcCP)
                     .dst(dstCP)
                     .signalType(ochPorts.getLeft().signalType())
@@ -324,7 +328,7 @@
             rules.add(connectPorts(higherIntent.getDst(), lowerIntent.getDst(), higherIntent.priority(), slots));
         }
 
-        return new FlowRuleIntent(appId, rules, higherIntent.resources());
+        return new FlowRuleIntent(appId, higherIntent.key(), rules, higherIntent.resources());
     }
 
     /**
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
index f48b844..de25fda 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalConnectivityIntentCompiler.java
@@ -189,6 +189,7 @@
 
         return OpticalPathIntent.builder()
                 .appId(parentIntent.appId())
+                .key(parentIntent.key())
                 .src(parentIntent.getSrc())
                 .dst(parentIntent.getDst())
                 // calling paths.iterator().next() is safe because of non-empty set
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
index 2da9a40..1d60875 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompiler.java
@@ -175,7 +175,7 @@
                 rules.addAll(createRules(intent, intent.getDst(), intent.getSrc(), path, slotsMap, true));
             }
 
-            return Collections.singletonList(new FlowRuleIntent(appId,
+            return Collections.singletonList(new FlowRuleIntent(appId, intent.key(),
                     rules, ImmutableSet.copyOf(path.links())));
         }
 
diff --git a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
index dc99574..26196b7 100644
--- a/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
+++ b/apps/optical-model/src/main/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompiler.java
@@ -79,7 +79,10 @@
             rules.addAll(createReverseRules(intent));
         }
 
-        return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+        return Collections.singletonList(new FlowRuleIntent(appId,
+                                                            intent.key(),
+                                                            rules,
+                                                            intent.resources()));
     }
 
     /**
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
index 353925e..1c0eceb 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalCircuitIntentCompilerTest.java
@@ -87,6 +87,7 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
@@ -94,6 +95,7 @@
 import static org.easymock.EasyMock.expectLastCall;
 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.junit.Assert.assertEquals;
@@ -432,6 +434,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()
@@ -505,6 +511,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()
@@ -573,6 +583,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();
 
         FlowRule rule1 = rules.stream()
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
index 810e897..f3d3e43 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalOduIntentCompilerTest.java
@@ -78,11 +78,13 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import static org.easymock.EasyMock.createMock;
 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.junit.Assert.assertEquals;
@@ -309,6 +311,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();
 
         // 1st Device
@@ -395,6 +401,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();
 
         // 1st Device
diff --git a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
index 1fe306d..0c2d25e 100644
--- a/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
+++ b/apps/optical-model/src/test/java/org/onosproject/net/optical/intent/impl/compiler/OpticalPathIntentCompilerTest.java
@@ -38,12 +38,15 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static org.easymock.EasyMock.createMock;
 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.junit.Assert.assertEquals;
 import static org.onosproject.net.Link.Type.DIRECT;
 import static org.onosproject.net.NetTestTools.PID;
@@ -108,6 +111,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();
         rules.stream()
                 .filter(x -> x.deviceId().equals(d1p1.deviceId()))
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Intent.java b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
index f4293ce..4df13a6 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Intent.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Intent.java
@@ -155,7 +155,7 @@
     }
 
     /**
-     * Returns the intent identifier.
+     * Returns the intent object identifier.
      *
      * @return intent fingerprint
      */
@@ -241,6 +241,16 @@
         }
     }
 
+    /**
+     * Returns the key to identify an "Intent".
+     * <p>
+     * When an Intent is updated,
+     * (e.g., flow is re-routed in reaction to network topology change)
+     * related Intent object's {@link IntentId} may change,
+     * but the key will remain unchanged.
+     *
+     * @return key
+     */
     public Key key() {
         return key;
     }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index 427d56d..dad8e3b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -122,6 +122,7 @@
                 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
         return PathIntent.builder()
                 .appId(intent.appId())
+                .key(intent.key())
                 .selector(selector)
                 .treatment(intent.treatment())
                 .path(path)
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
index d93764b..969372d 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentCompiler.java
@@ -123,7 +123,7 @@
                     labels)
             );
         }
-        return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+        return Collections.singletonList(new FlowRuleIntent(appId, intent.key(), rules, intent.resources()));
     }
 
     @Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
index 0a15097..6a0081f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/LinkCollectionIntentFlowObjectiveCompiler.java
@@ -119,7 +119,7 @@
             });
         }
         return Collections.singletonList(
-                new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
+                new FlowObjectiveIntent(appId, intent.key(), devices, objectives, intent.resources()));
     }
 
     @Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
index 9c4f535..9c84853 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java
@@ -94,7 +94,10 @@
         Map<LinkKey, MplsLabel> labels = assignMplsLabel(intent);
         List<FlowRule> rules = generateRules(intent, labels);
 
-        return Collections.singletonList(new FlowRuleIntent(appId, rules, intent.resources()));
+        return Collections.singletonList(new FlowRuleIntent(appId,
+                                                            intent.key(),
+                                                            rules,
+                                                            intent.resources()));
     }
 
     @Activate
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index f9b236f..cac5d68 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -119,6 +119,7 @@
 
         Intent result = LinkCollectionIntent.builder()
                 .appId(intent.appId())
+                .key(intent.key())
                 .treatment(intent.treatment())
                 .selector(intent.selector())
                 .links(Sets.newHashSet(links.values()))
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
index f719a00..a2c26dd 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentCompiler.java
@@ -83,7 +83,12 @@
         List<DeviceId> devices = new LinkedList<>();
         compile(this, intent, rules, devices);
 
-        return ImmutableList.of(new FlowRuleIntent(appId, null, rules, intent.resources(), intent.type()));
+
+        return ImmutableList.of(new FlowRuleIntent(appId,
+                                                   intent.key(),
+                                                   rules,
+                                                   intent.resources(),
+                                                   intent.type()));
     }
 
     @Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
index 3f0fc19..521d6fc 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PathIntentFlowObjectiveCompiler.java
@@ -89,7 +89,11 @@
         List<DeviceId> devices = new LinkedList<>();
         compile(this, intent, objectives, devices);
 
-        return ImmutableList.of(new FlowObjectiveIntent(appId, devices, objectives, intent.resources()));
+        return ImmutableList.of(new FlowObjectiveIntent(appId,
+                                                        intent.key(),
+                                                        devices,
+                                                        objectives,
+                                                        intent.resources()));
     }
 
     @Override
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index 02b8865..a6fac6f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -256,6 +256,7 @@
             createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
 
             FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(),
+                                                         intent.key(),
                                                          createFailoverFlowRules(intent),
                                                          asList(ingressPoint.deviceId()),
                                                          PathIntent.ProtectionType.FAILOVER);
@@ -312,6 +313,7 @@
                                     PathIntent.ProtectionType type) {
         return PathIntent.builder()
                 .appId(intent.appId())
+                .key(intent.key())
                 .selector(intent.selector())
                 .treatment(intent.treatment())
                 .path(path)
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()));
 
     }
 }