Add unit tests for FlowEntryWithLoad class

Change-Id: I9663ef207555a6b7371fbf59f2bbe2c0b169c83d
diff --git a/core/api/src/test/java/org/onosproject/net/flow/FlowEntryAdapter.java b/core/api/src/test/java/org/onosproject/net/flow/FlowEntryAdapter.java
new file mode 100644
index 0000000..6937647
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/flow/FlowEntryAdapter.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.flow;
+
+import java.util.concurrent.TimeUnit;
+
+import org.onosproject.core.GroupId;
+import org.onosproject.net.DeviceId;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.*;
+
+/**
+ * Adapter for the flow entry interface.
+ */
+public class FlowEntryAdapter implements FlowEntry {
+    @Override
+    public FlowEntryState state() {
+        return FlowEntryState.ADDED;
+    }
+
+    @Override
+    public long life() {
+        return life(SECONDS);
+    }
+
+    @Override
+    public FlowLiveType liveType() {
+        return null;
+    }
+
+    @Override
+    public long life(TimeUnit timeUnit) {
+        return SECONDS.convert(0, timeUnit);
+    }
+
+    @Override
+    public long packets() {
+        return 0;
+    }
+
+    @Override
+    public long bytes() {
+        return 0;
+    }
+
+    @Override
+    public long lastSeen() {
+        return 0;
+    }
+
+    @Override
+    public int errType() {
+        return 0;
+    }
+
+    @Override
+    public int errCode() {
+        return 0;
+    }
+
+    @Override
+    public FlowId id() {
+        return FlowId.valueOf(0);
+    }
+
+    @Override
+    public GroupId groupId() {
+        return new GroupId(3);
+    }
+
+    @Override
+    public short appId() {
+        return 1;
+    }
+
+    @Override
+    public int priority() {
+        return 0;
+    }
+
+    @Override
+    public DeviceId deviceId() {
+        return null;
+    }
+
+    @Override
+    public TrafficSelector selector() {
+        return null;
+    }
+
+    @Override
+    public TrafficTreatment treatment() {
+        return null;
+    }
+
+    @Override
+    public int timeout() {
+        return 0;
+    }
+
+    @Override
+    public int hardTimeout() {
+        return 0;
+    }
+
+    @Override
+    public FlowRule.FlowRemoveReason reason() {
+        return FlowRule.FlowRemoveReason.NO_REASON;
+    }
+
+    @Override
+    public boolean isPermanent() {
+        return false;
+    }
+
+    @Override
+    public int tableId() {
+        return 0;
+    }
+
+    @Override
+    public boolean exactMatch(FlowRule rule) {
+        return false;
+    }
+
+    @Override
+    public FlowRuleExtPayLoad payLoad() {
+        return null;
+    }
+
+}
diff --git a/core/api/src/test/java/org/onosproject/net/flow/StoredFlowEntryAdapter.java b/core/api/src/test/java/org/onosproject/net/flow/StoredFlowEntryAdapter.java
new file mode 100644
index 0000000..908bd6f
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/flow/StoredFlowEntryAdapter.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.flow;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Testing adapter for stored flow entry class.
+ */
+public class StoredFlowEntryAdapter extends FlowEntryAdapter implements StoredFlowEntry {
+    @Override
+    public void setLastSeen() {
+
+    }
+
+    @Override
+    public void setState(FlowEntryState newState) {
+
+    }
+
+    @Override
+    public void setLife(long lifeSecs) {
+
+    }
+
+    @Override
+    public void setLife(long life, TimeUnit timeUnit) {
+
+    }
+
+    @Override
+    public void setLiveType(FlowLiveType liveType) {
+
+    }
+
+    @Override
+    public void setPackets(long packets) {
+
+    }
+
+    @Override
+    public void setBytes(long bytes) {
+
+    }
+}
diff --git a/core/api/src/test/java/org/onosproject/net/statistic/FlowEntryWithLoadTest.java b/core/api/src/test/java/org/onosproject/net/statistic/FlowEntryWithLoadTest.java
new file mode 100644
index 0000000..cbf3a05
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/statistic/FlowEntryWithLoadTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.net.statistic;
+
+import org.junit.Test;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.NetTestTools;
+import org.onosproject.net.flow.FlowEntry;
+import org.onosproject.net.flow.StoredFlowEntry;
+import org.onosproject.net.flow.StoredFlowEntryAdapter;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+
+/**
+ * Unit tests for flow entry with load.
+ */
+public class FlowEntryWithLoadTest {
+    class MockFlowEntry extends StoredFlowEntryAdapter {
+        FlowLiveType liveType;
+
+        public MockFlowEntry(FlowLiveType liveType) {
+            this.liveType = liveType;
+        }
+
+        @Override
+        public FlowLiveType liveType() {
+            return liveType;
+        }
+    }
+
+    @Test
+    public void testConstructionCpFeLoad() {
+        ConnectPoint cp = NetTestTools.connectPoint("id1", 1);
+        StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
+        Load load = new DefaultLoad();
+        FlowEntryWithLoad underTest = new FlowEntryWithLoad(cp, fe, load);
+
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), is(load));
+        assertThat(underTest.storedFlowEntry(), is(fe));
+    }
+
+    @Test
+    public void testConstructionDEfaultLoad() {
+        ConnectPoint cp = NetTestTools.connectPoint("id1", 1);
+        StoredFlowEntry fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
+        FlowEntryWithLoad underTest;
+
+        fe = new MockFlowEntry(FlowEntry.FlowLiveType.IMMEDIATE);
+        underTest = new FlowEntryWithLoad(cp, fe);
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), instanceOf(DefaultLoad.class));
+        assertThat(underTest.storedFlowEntry(), is(fe));
+
+        fe = new MockFlowEntry(FlowEntry.FlowLiveType.LONG);
+        underTest = new FlowEntryWithLoad(cp, fe);
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), instanceOf(DefaultLoad.class));
+
+        fe = new MockFlowEntry(FlowEntry.FlowLiveType.MID);
+        underTest = new FlowEntryWithLoad(cp, fe);
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), instanceOf(DefaultLoad.class));
+
+        fe = new MockFlowEntry(FlowEntry.FlowLiveType.SHORT);
+        underTest = new FlowEntryWithLoad(cp, fe);
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), instanceOf(DefaultLoad.class));
+
+        fe = new MockFlowEntry(FlowEntry.FlowLiveType.UNKNOWN);
+        underTest = new FlowEntryWithLoad(cp, fe);
+        assertThat(underTest.connectPoint(), is(cp));
+        assertThat(underTest.load(), instanceOf(DefaultLoad.class));
+    }
+}