package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Before;
+import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.opendaylight.groupbasedpolicy.api.sf.EtherTypeClassifierDefinition;
+import org.opendaylight.groupbasedpolicy.api.sf.IpProtoClassifierDefinition;
import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValue;
import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.subject.feature.instance.ParameterValueBuilder;
-import com.google.common.collect.ImmutableMap;
-
public class EtherTypeClassifierTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- List<MatchBuilder> matches;
- Map<String, ParameterValue> params;
+ @Test
+ public void testUpdate() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
+ matches.add(
+ new MatchBuilder().setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv4));
- @Before
- public void setUp() {
- matches = new ArrayList<>();
- params = new HashMap<>();
- }
+ List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
- @Test
- public void setValueTest() {
- matches.add(new MatchBuilder()
- .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.TCP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv4));
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
- assertEquals(true, ClassifierTestUtils.IPV4_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.TCP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV4_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.TCP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByTheSameValueTest() {
+ public void testUpdate_overrideBySameValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
matches.add(new MatchBuilder()
- .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
- .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv6));
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
- assertEquals(true, ClassifierTestUtils.IPV6_ETH_TYPE.equals(matches.get(0).getEthernetMatch().getEthernetType()));
- assertEquals(true, ClassifierTestUtils.UDP.equals(matches.get(0).getIpMatch().getIpProtocol().longValue()));
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV6_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.UDP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
+
+ List<MatchBuilder> updated = Classifier.ETHER_TYPE_CL.update(matches, params);
+
+ assertEquals(1, updated.size());
+ MatchBuilder first = updated.get(0);
+ assertEquals(ClassifierTestUtils.IPV6_ETH_TYPE, first.getEthernetMatch().getEthernetType());
+ assertSame(ClassifierTestUtils.UDP, first.getIpMatch().getIpProtocol().longValue());
}
@Test
- public void overrideByDifferentValueTest() {
+ public void testUpdate_overrideByDifferentValue() {
+ List<MatchBuilder> matches = new ArrayList<>();
+ Map<String, ParameterValue> params = new HashMap<>();
matches.add(new MatchBuilder()
- .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
- .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
- params.putAll(ClassifierTestUtils.createIntValueParam(EtherTypeClassifier.ETHER_TYPE, FlowUtils.IPv6));
+ .setEthernetMatch(ClassifierTestUtils.createEthernetMatch(ClassifierTestUtils.IPV4_ETH_TYPE))
+ .setIpMatch(ClassifierTestUtils.createIpMatch(ClassifierTestUtils.SCTP.shortValue())));
+ params.putAll(
+ ClassifierTestUtils.createIntValueParam(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, FlowUtils.IPv6));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Trying to override ether-type value:");
- matches = Classifier.ETHER_TYPE_CL.update(matches, params);
+ thrown.expectMessage(Classifier.MSG_CLASSIFICATION_CONFLICT_DETECTED);
+ Classifier.ETHER_TYPE_CL.update(matches, params);
}
@Test
- public void checkPresenceOfRequiredParameters1Test() {
- params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifier.PROTO, ClassifierTestUtils.TCP));
+ public void testCheckPresenceOfRequiredParameters_EtherTypeMissing() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(ClassifierTestUtils.createIntValueParam(IpProtoClassifierDefinition.PROTO_PARAM,
+ ClassifierTestUtils.TCP));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Parameter ethertype not present");
+ thrown.expectMessage(Classifier.MSG_NOT_SPECIFIED);
Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
}
@Test
- public void checkPresenceOfRequiredParameters2Test() {
- params.putAll(ImmutableMap.<String, ParameterValue> of(EtherTypeClassifier.ETHER_TYPE,
- new ParameterValueBuilder().build()));
+ public void testCheckPresenceOfRequiredParameters_EtherTypeNull() {
+ Map<String, ParameterValue> params = new HashMap<>();
+ params.putAll(
+ ImmutableMap.of(EtherTypeClassifierDefinition.ETHERTYPE_PARAM, new ParameterValueBuilder().build()));
+
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Value of ethertype parameter is not present");
+ thrown.expectMessage(Classifier.MSG_PARAMETER_IS_NOT_PRESENT);
Classifier.ETHER_TYPE_CL.checkPresenceOfRequiredParams(params);
}
}