FlowRule equals() incorporates FlowId to factor in treatment.
Reference: ONOS-481 Change-Id: Ia1fcba3f827c662c89801afc84916ffef78af66d
Showing
3 changed files
with
38 additions
and
8 deletions
| ... | @@ -203,7 +203,8 @@ public class DefaultFlowRule implements FlowRule { | ... | @@ -203,7 +203,8 @@ public class DefaultFlowRule implements FlowRule { |
| 203 | DefaultFlowRule that = (DefaultFlowRule) obj; | 203 | DefaultFlowRule that = (DefaultFlowRule) obj; |
| 204 | return Objects.equals(deviceId, that.deviceId) && | 204 | return Objects.equals(deviceId, that.deviceId) && |
| 205 | Objects.equals(priority, that.priority) && | 205 | Objects.equals(priority, that.priority) && |
| 206 | - Objects.equals(selector, that.selector); | 206 | + Objects.equals(selector, that.selector) && |
| 207 | + Objects.equals(id, that.id()); | ||
| 207 | 208 | ||
| 208 | } | 209 | } |
| 209 | return false; | 210 | return false; | ... | ... |
| ... | @@ -17,12 +17,15 @@ | ... | @@ -17,12 +17,15 @@ |
| 17 | package org.onosproject.net.flow; | 17 | package org.onosproject.net.flow; |
| 18 | 18 | ||
| 19 | import org.junit.Test; | 19 | import org.junit.Test; |
| 20 | +import org.onosproject.net.PortNumber; | ||
| 21 | +import org.onosproject.net.flow.instructions.Instructions; | ||
| 20 | import org.onosproject.net.intent.IntentTestsMocks; | 22 | import org.onosproject.net.intent.IntentTestsMocks; |
| 21 | 23 | ||
| 22 | import com.google.common.testing.EqualsTester; | 24 | import com.google.common.testing.EqualsTester; |
| 23 | 25 | ||
| 24 | import static org.hamcrest.MatcherAssert.assertThat; | 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| 25 | import static org.hamcrest.Matchers.is; | 27 | import static org.hamcrest.Matchers.is; |
| 28 | +import static org.hamcrest.Matchers.not; | ||
| 26 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; | 29 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass; |
| 27 | import static org.onosproject.net.NetTestTools.APP_ID; | 30 | import static org.onosproject.net.NetTestTools.APP_ID; |
| 28 | import static org.onosproject.net.NetTestTools.did; | 31 | import static org.onosproject.net.NetTestTools.did; |
| ... | @@ -33,8 +36,12 @@ import static org.onosproject.net.NetTestTools.did; | ... | @@ -33,8 +36,12 @@ import static org.onosproject.net.NetTestTools.did; |
| 33 | public class DefaultFlowRuleTest { | 36 | public class DefaultFlowRuleTest { |
| 34 | private static final IntentTestsMocks.MockSelector SELECTOR = | 37 | private static final IntentTestsMocks.MockSelector SELECTOR = |
| 35 | new IntentTestsMocks.MockSelector(); | 38 | new IntentTestsMocks.MockSelector(); |
| 36 | - private static final IntentTestsMocks.MockTreatment TREATMENT = | 39 | + private static final IntentTestsMocks.MockTreatment TREATMENT1 = |
| 37 | - new IntentTestsMocks.MockTreatment(); | 40 | + new IntentTestsMocks.MockTreatment( |
| 41 | + Instructions.createOutput(PortNumber.portNumber(1))); | ||
| 42 | + private static final IntentTestsMocks.MockTreatment TREATMENT2 = | ||
| 43 | + new IntentTestsMocks.MockTreatment( | ||
| 44 | + Instructions.createOutput(PortNumber.portNumber(2))); | ||
| 38 | 45 | ||
| 39 | final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1); | 46 | final FlowRule flowRule1 = new IntentTestsMocks.MockFlowRule(1); |
| 40 | final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1); | 47 | final FlowRule sameAsFlowRule1 = new IntentTestsMocks.MockFlowRule(1); |
| ... | @@ -85,14 +92,14 @@ public class DefaultFlowRuleTest { | ... | @@ -85,14 +92,14 @@ public class DefaultFlowRuleTest { |
| 85 | public void testCreationWithFlowId() { | 92 | public void testCreationWithFlowId() { |
| 86 | final DefaultFlowRule rule = | 93 | final DefaultFlowRule rule = |
| 87 | new DefaultFlowRule(did("1"), SELECTOR, | 94 | new DefaultFlowRule(did("1"), SELECTOR, |
| 88 | - TREATMENT, 22, 33, | 95 | + TREATMENT1, 22, 33, |
| 89 | 44, false); | 96 | 44, false); |
| 90 | assertThat(rule.deviceId(), is(did("1"))); | 97 | assertThat(rule.deviceId(), is(did("1"))); |
| 91 | assertThat(rule.id().value(), is(33L)); | 98 | assertThat(rule.id().value(), is(33L)); |
| 92 | assertThat(rule.isPermanent(), is(false)); | 99 | assertThat(rule.isPermanent(), is(false)); |
| 93 | assertThat(rule.priority(), is(22)); | 100 | assertThat(rule.priority(), is(22)); |
| 94 | assertThat(rule.selector(), is(SELECTOR)); | 101 | assertThat(rule.selector(), is(SELECTOR)); |
| 95 | - assertThat(rule.treatment(), is(TREATMENT)); | 102 | + assertThat(rule.treatment(), is(TREATMENT1)); |
| 96 | assertThat(rule.timeout(), is(44)); | 103 | assertThat(rule.timeout(), is(44)); |
| 97 | } | 104 | } |
| 98 | 105 | ||
| ... | @@ -103,13 +110,25 @@ public class DefaultFlowRuleTest { | ... | @@ -103,13 +110,25 @@ public class DefaultFlowRuleTest { |
| 103 | public void testCreationWithAppId() { | 110 | public void testCreationWithAppId() { |
| 104 | final DefaultFlowRule rule = | 111 | final DefaultFlowRule rule = |
| 105 | new DefaultFlowRule(did("1"), SELECTOR, | 112 | new DefaultFlowRule(did("1"), SELECTOR, |
| 106 | - TREATMENT, 22, APP_ID, | 113 | + TREATMENT1, 22, APP_ID, |
| 107 | 44, false); | 114 | 44, false); |
| 108 | assertThat(rule.deviceId(), is(did("1"))); | 115 | assertThat(rule.deviceId(), is(did("1"))); |
| 109 | assertThat(rule.isPermanent(), is(false)); | 116 | assertThat(rule.isPermanent(), is(false)); |
| 110 | assertThat(rule.priority(), is(22)); | 117 | assertThat(rule.priority(), is(22)); |
| 111 | assertThat(rule.selector(), is(SELECTOR)); | 118 | assertThat(rule.selector(), is(SELECTOR)); |
| 112 | - assertThat(rule.treatment(), is(TREATMENT)); | 119 | + assertThat(rule.treatment(), is(TREATMENT1)); |
| 113 | assertThat(rule.timeout(), is(44)); | 120 | assertThat(rule.timeout(), is(44)); |
| 114 | } | 121 | } |
| 122 | + | ||
| 123 | + /** | ||
| 124 | + * Tests equality that factors in TrafficTreatment through the flowId. | ||
| 125 | + */ | ||
| 126 | + @Test | ||
| 127 | + public void testActionEquals() { | ||
| 128 | + final DefaultFlowRule rule1 = new DefaultFlowRule(did("1"), SELECTOR, | ||
| 129 | + TREATMENT1, 22, APP_ID, 44, false); | ||
| 130 | + final DefaultFlowRule rule2 = new DefaultFlowRule(did("1"), SELECTOR, | ||
| 131 | + TREATMENT2, 22, APP_ID, 44, false); | ||
| 132 | + assertThat(rule1, not(rule2)); | ||
| 133 | + } | ||
| 115 | } | 134 | } | ... | ... |
| ... | @@ -80,9 +80,19 @@ public class IntentTestsMocks { | ... | @@ -80,9 +80,19 @@ public class IntentTestsMocks { |
| 80 | * Mock traffic treatment class used for satisfying API requirements. | 80 | * Mock traffic treatment class used for satisfying API requirements. |
| 81 | */ | 81 | */ |
| 82 | public static class MockTreatment implements TrafficTreatment { | 82 | public static class MockTreatment implements TrafficTreatment { |
| 83 | + | ||
| 84 | + private List<Instruction> instructions = new ArrayList<>(); | ||
| 85 | + | ||
| 86 | + public MockTreatment() { | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public MockTreatment(Instruction... insts) { | ||
| 90 | + this.instructions.addAll(Arrays.asList(insts)); | ||
| 91 | + } | ||
| 92 | + | ||
| 83 | @Override | 93 | @Override |
| 84 | public List<Instruction> instructions() { | 94 | public List<Instruction> instructions() { |
| 85 | - return new ArrayList<>(); | 95 | + return this.instructions; |
| 86 | } | 96 | } |
| 87 | } | 97 | } |
| 88 | 98 | ... | ... |
-
Please register or login to post a comment