import org.opendaylight.controller.packetcable.provider.validation.ValidatorProviderFactory;
import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.AppValidator;
import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.AppsValidator;
-import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.GateSpecValidatator;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.GateSpecValidator;
import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.GateValidator;
import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.GatesValidator;
import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.SubscriberValidator;
provider.put(Gates.class, new GatesValidator());
provider.put(Gate.class, new GateValidator());
- provider.put(GateSpec.class, new GateSpecValidatator());
+ provider.put(GateSpec.class, new GateSpecValidator());
provider.put(TrafficProfile.class, new TrafficProfileValidator());
/**
* @author rvail
*/
-public class GateSpecValidatator extends AbstractValidator<GateSpec> {
+public class GateSpecValidator extends AbstractValidator<GateSpec> {
private static final String DIRECTION = "gate-spec.direction";
private static final String TRAFFIC_PROFILE = "gate.traffic-profile";
private static final String CLASSIFIERS = "gate.classifiers";
-// private final GateSpecValidatator gateSpecValidatator = new GateSpecValidatator();
+// private final GateSpecValidator gateSpecValidatator = new GateSpecValidator();
private final TrafficProfileValidator trafficProfileValidator = new TrafficProfileValidator();
private final ClassifiersValidator classifiersValidator = new ClassifiersValidator();
}
if (extent == Extent.NODE_AND_SUBTREE) {
- for (Gate gate : gates.getGate()) {
- validateChild(gateValidator, gate);
+ if (gates.getGate() != null) {
+ for (Gate gate : gates.getGate()) {
+ validateChild(gateValidator, gate);
+ }
}
}
}
}
if (extent == Extent.NODE_AND_SUBTREE) {
- for (Subscriber subscriber : subscribers.getSubscriber()) {
- validateChild(subscriberValidator , subscriber);
+ if (subscribers.getSubscriber() != null) {
+ for (Subscriber subscriber : subscribers.getSubscriber()) {
+ validateChild(subscriberValidator, subscriber);
+ }
}
}
}
@Override
protected void doValidate(final TrafficProfile trafficProfile, final Extent extent) {
- if (trafficProfile == null) {
+ if (trafficProfile == null) {
getErrorMessages().add("traffic-profile must exist");
return;
}
private static final String CLASSIFER_CONTAINER = "classifers.classifer-container";
- private ClassifierContainerValidator classifierContainerValidator = new ClassifierContainerValidator();
+ private final ClassifierContainerValidator classifierContainerValidator = new ClassifierContainerValidator();
@Override
protected void doValidate(final Classifiers classifiers, final Extent extent) {
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.test.rules;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+import org.junit.rules.ErrorCollector;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Rule that allows a test to be run with multiple parameters.<br><br>
+ * Two ways to use
+ * <ol>
+ * <li>Individual Method Annotation - {@link Params.UseParams} <br>Used if only a few methods need to use the rule</li>
+ * <li>Class Annotation - {@link Params.AlwaysUseParams} <br> Used if most/all methods will use the rule. Exceptions should be marked with {@link Params.DoNotUseParams}</li>
+ * </ol>
+ *
+ * @author rvail
+ */
+public class Params<T> implements TestRule {
+
+ private final List<T> allParams;
+ private final VerifiableErrorCollector errorCollector = new VerifiableErrorCollector();
+ private Optional<T> currentParam = null;
+
+
+
+ public static <E> Params<E> of(E... allParams) {
+ return new Params<>(allParams);
+ }
+
+ public static <E extends Enum<E>> Params<E> of(Class<E> enumClass) {
+ return new Params<>(enumClass.getEnumConstants());
+ }
+
+ private Params(List<T> allParams) {
+ this.allParams = allParams;
+ }
+
+ private Params(T[] allParams) {
+ this(Arrays.asList(allParams));
+ }
+
+ public T getCurrentParam() {
+ if (currentParam == null) {
+ throw new IllegalStateException("Params.getCurrentParam called from unannotated method/class");
+ }
+ return currentParam.get();
+ }
+
+ @Override
+ public Statement apply(final Statement base, final Description description) {
+ if (!shouldUseParams(description)) {
+ return base;
+ }
+ return new Statement() {
+
+ @Override
+ public void evaluate() throws Throwable {
+
+ for (final T param : allParams) {
+ currentParam = Optional.of(param);
+ try {
+ base.evaluate();
+ } catch (Throwable t) {
+ errorCollector.addError(new ParamsAssertionError(currentParam, t));
+ }
+ }
+ currentParam = null;
+ errorCollector.verify();
+ }
+ };
+ }
+
+ private boolean shouldUseParams(final Description description) {
+ final UseParams useParamsAnnotation = description.getAnnotation(UseParams.class);
+ boolean testUsesParams = (useParamsAnnotation != null);
+ if (!testUsesParams) {
+ final AlwaysUseParams alwaysUseParams = description.getTestClass().getAnnotation(AlwaysUseParams.class);
+ testUsesParams = (alwaysUseParams != null);
+ if (testUsesParams) {
+ testUsesParams = (description.getAnnotation(DoNotUseParams.class) == null);
+ }
+ }
+
+ return testUsesParams;
+ }
+
+ /**
+ * Method will use Params
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD})
+ public @interface UseParams {
+ }
+
+
+ /**
+ * Method will not use Params
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD})
+ public @interface DoNotUseParams {
+ }
+
+
+ /**
+ * All Methods in Class will use Params unless they are annotated with
+ * {@link Params.DoNotUseParams}
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.TYPE})
+ public @interface AlwaysUseParams {
+ }
+
+
+ public static class ParamsAssertionError extends AssertionError {
+ ParamsAssertionError(Object param, Throwable t) {
+ super(String.format("\nParam: %s\n%s", Objects.toString(param), t));
+ // We don't care where this is thrown from we care about the passed in cause
+ // use its stack trace
+ this.setStackTrace(t.getStackTrace());
+ }
+ }
+
+
+ /**
+ * ErrorCollector.verify() is protected so extend ErrorCollector so we can call it.
+ */
+ private class VerifiableErrorCollector extends ErrorCollector {
+ public void verify() throws Throwable {
+ super.verify();
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.collect.Maps;
+import java.util.Map;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps.CcapValidatorTest;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * @author rvail
+ */
+public class DataValidatorTest {
+
+ @Test
+ public void badData() throws ValidationException {
+ final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
+
+ doThrow(new ValidationException("unit-test-exception"))
+ .when(validatorProvider)
+ .validate(any(Class.class), any(Ccap.class), any(Validator.Extent.class));
+
+
+ final Ccap ccap = mock(Ccap.class);
+ doReturn(Ccap.class)
+ .when(ccap)
+ .getImplementedInterface();
+
+
+ DataValidator dataValidator = new DataValidator(validatorProvider);
+
+
+ Map<InstanceIdentifier<?>, DataObject> dataMap = Maps.newHashMap();
+ InstanceIdentifier iid = mock(InstanceIdentifier.class);
+ dataMap.put(iid, ccap);
+
+ Map<InstanceIdentifier<?>, ValidationException> validationMap = dataValidator.validate(dataMap, Validator.Extent.NODE_ONLY);
+
+ assertThat(validationMap, is(not(nullValue())));
+ assertThat(validationMap.size(), is(1));
+ assertThat(validationMap.containsKey(iid), is(true));
+ ValidationException ex = validationMap.get(iid);
+ assertThat(ex, is(not(nullValue())));
+
+ }
+
+ @Test
+ public void validCcap() {
+ final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
+
+ Map<InstanceIdentifier<?>, DataObject> dataMap = Maps.newHashMap();
+ InstanceIdentifier iid = mock(InstanceIdentifier.class);
+ dataMap.put(iid, CcapValidatorTest.buildValidCcapTree());
+
+ final DataValidator dataValidator = new DataValidator(validatorProvider);
+ Map<InstanceIdentifier<?>, ValidationException> validationMap = dataValidator.validate(dataMap, Validator.Extent.NODE_ONLY);
+
+ assertThat(validationMap.isEmpty(), is(true));
+
+ }
+
+ @Test
+ public void validCcapExplictTyping() {
+ final ValidatorProvider validatorProvider = mock(ValidatorProvider.class);
+
+ Map<InstanceIdentifier<Ccap>, Ccap> dataMap = Maps.newHashMap();
+ InstanceIdentifier<Ccap> iid = mock(InstanceIdentifier.class);
+ dataMap.put(iid, CcapValidatorTest.buildValidCcapTree());
+
+ final DataValidator dataValidator = new DataValidator(validatorProvider);
+ Map<InstanceIdentifier<Ccap>, ValidationException> validationMap = dataValidator.validateOneType(dataMap,
+ Validator.Extent.NODE_ONLY);
+
+ assertThat(validationMap.isEmpty(), is(true));
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.validation.ValidatorProvider;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.Ccaps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmId;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.Connection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
+
+/**
+ * @author rvail
+ */
+public class CcapsValidatorProviderFactoryTest {
+
+ private final CcapsValidatorProviderFactory factory = new CcapsValidatorProviderFactory();
+
+ @Test
+ public void validBuild() {
+ assertNotNull(factory.build());
+ assertThat(factory.build(), instanceOf(ValidatorProvider.class));
+
+ assertNotNull(factory.build().validatorFor(Ccaps.class));
+ assertNotNull(factory.build().validatorFor(Ccap.class));
+ assertNotNull(factory.build().validatorFor(AmId.class));
+ assertNotNull(factory.build().validatorFor(Connection.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.validation.ValidatorProvider;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.Classifiers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.classifier.Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ext.classifier.ExtClassifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gate.spec.GateSpec;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.Apps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.App;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.Subscribers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.Subscriber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.Gates;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ipv6.classifier.Ipv6Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.traffic.profile.TrafficProfile;
+
+/**
+ * @author rvail
+ */
+public class QosValidatorProviderFactoryTest {
+
+ private final QosValidatorProviderFactory factory = new QosValidatorProviderFactory();
+
+ @Test
+ public void validBuild() {
+ assertNotNull(factory.build());
+ assertThat(factory.build(), instanceOf(ValidatorProvider.class));
+
+ assertNotNull(factory.build().validatorFor(Apps.class));
+ assertNotNull(factory.build().validatorFor(App.class));
+ assertNotNull(factory.build().validatorFor(Subscribers.class));
+ assertNotNull(factory.build().validatorFor(Subscriber.class));
+ assertNotNull(factory.build().validatorFor(Gates.class));
+ assertNotNull(factory.build().validatorFor(Gate.class));
+ assertNotNull(factory.build().validatorFor(GateSpec.class));
+ assertNotNull(factory.build().validatorFor(TrafficProfile.class));
+ assertNotNull(factory.build().validatorFor(Classifiers.class));
+ assertNotNull(factory.build().validatorFor(Classifier.class));
+ assertNotNull(factory.build().validatorFor(ClassifierContainer.class));
+ assertNotNull(factory.build().validatorFor(ExtClassifier.class));
+ assertNotNull(factory.build().validatorFor(Ipv6Classifier.class));
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.validation.ValidatorProvider;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.Ccaps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmId;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.Connection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.Classifiers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.classifier.Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ext.classifier.ExtClassifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gate.spec.GateSpec;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.Apps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.App;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.Subscribers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.Subscriber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.Gates;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ipv6.classifier.Ipv6Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.traffic.profile.TrafficProfile;
+
+/**
+ * @author rvail
+ */
+public class ValidatorProviderFactoryImplTest {
+
+ private final ValidatorProviderFactoryImpl factory = new ValidatorProviderFactoryImpl();
+
+ @Test
+ public void validBuild() {
+ assertNotNull(factory.build());
+ assertThat(factory.build(), instanceOf(ValidatorProvider.class));
+
+ assertNotNull(factory.build().validatorFor(Ccaps.class));
+ assertNotNull(factory.build().validatorFor(Ccap.class));
+ assertNotNull(factory.build().validatorFor(AmId.class));
+ assertNotNull(factory.build().validatorFor(Connection.class));
+
+ assertNotNull(factory.build().validatorFor(Apps.class));
+ assertNotNull(factory.build().validatorFor(App.class));
+ assertNotNull(factory.build().validatorFor(Subscribers.class));
+ assertNotNull(factory.build().validatorFor(Subscriber.class));
+ assertNotNull(factory.build().validatorFor(Gates.class));
+ assertNotNull(factory.build().validatorFor(Gate.class));
+ assertNotNull(factory.build().validatorFor(GateSpec.class));
+ assertNotNull(factory.build().validatorFor(TrafficProfile.class));
+ assertNotNull(factory.build().validatorFor(Classifiers.class));
+ assertNotNull(factory.build().validatorFor(Classifier.class));
+ assertNotNull(factory.build().validatorFor(ClassifierContainer.class));
+ assertNotNull(factory.build().validatorFor(ExtClassifier.class));
+ assertNotNull(factory.build().validatorFor(Ipv6Classifier.class));
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps.ConnectionValidator;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps.ConnectionValidatorTest;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.Connection;
+
+/**
+ * @author rvail
+ */
+public class ValidatorProviderImplTest {
+
+ private final ValidatorProviderImpl validatorProvider = new ValidatorProviderImpl();
+
+ @Test
+ public void testPutAndGetValidator() {
+ final ConnectionValidator validator = new ConnectionValidator();
+ validatorProvider.put(Connection.class, validator);
+ assertNotNull(validatorProvider.validatorFor(Connection.class));
+ assertSame(validator, validatorProvider.validatorFor(Connection.class));
+ }
+
+ @Test
+ public void testValidate() throws ValidationException {
+ final ConnectionValidator validator = new ConnectionValidator();
+ validatorProvider.put(Connection.class, validator);
+ validatorProvider.validate(Connection.class, ConnectionValidatorTest.buildValidConnectionTree(),
+ Validator.Extent.NODE_ONLY);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmId;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmIdBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class AmIdValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final AmIdValidator validator = new AmIdValidator();
+
+ @Test
+ public void testValid() throws Exception {
+ AmId amId = new AmIdBuilder()
+ .setAmTag(1)
+ .setAmType(1)
+ .build();
+
+ // this throw an exception if invalid
+ validator.validate(amId, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNoAmTag() throws Exception {
+ AmId amId = new AmIdBuilder()
+ .setAmType(1)
+ .build();
+
+ // this throw an exception if invalid
+ validator.validate(amId, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNoAmType() throws Exception {
+ AmId amId = new AmIdBuilder()
+ .setAmTag(1)
+ .build();
+
+ // this throw an exception if invalid
+ validator.validate(amId, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullAmId() throws Exception {
+ // this throw an exception if invalid
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ public static AmId buildValidAmIdTree() {
+ return new AmIdBuilder()
+ .setAmType(1)
+ .setAmTag(2)
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps;
+
+import java.util.Collections;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ServiceClassName;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.CcapBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class CcapValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final CcapValidator validator = new CcapValidator();
+
+ @Test(expected = ValidationException.class)
+ public void testNullCcap() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void testNullExtent() throws ValidationException {
+ validator.validate(buildValidCcapTree(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullCcapId() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ // key is based off of CcapId so clear that too
+ .setKey(null)
+ .setCcapId(null)
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullDownstreamScns() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setDownstreamScns(null)
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testEmptyDownstreamScns() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setDownstreamScns(Collections.<ServiceClassName>emptyList())
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullUpstreamScns() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setUpstreamScns(null)
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testEmptyUpstreamScns() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setUpstreamScns(Collections.<ServiceClassName>emptyList())
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullAmId() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setAmId(null)
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullConnection() throws ValidationException {
+ final Ccap ccap = new CcapBuilder(buildValidCcapTree())
+ .setConnection(null)
+ .build();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValid() throws ValidationException {
+ final Ccap ccap = buildValidCcapTree();
+
+ validator.validate(ccap, extentParams.getCurrentParam());
+ }
+
+ public static Ccap buildValidCcapTree() {
+ return new CcapBuilder()
+ .setCcapId("aCcapId")
+ .setDownstreamScns(Collections.singletonList(new ServiceClassName("down_scn")))
+ .setUpstreamScns(Collections.singletonList(new ServiceClassName("up_scn")))
+ .setAmId(AmIdValidatorTest.buildValidAmIdTree())
+ .setConnection(ConnectionValidatorTest.buildValidConnectionTree())
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps;
+
+import java.util.Collections;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.Ccaps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.CcapsBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.Ccap;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccaps.CcapBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class CcapsValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final CcapsValidator validator = new CcapsValidator();
+
+ @Test(expected = ValidationException.class)
+ public void testNullCcaps() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void testNullExtent() throws ValidationException {
+ validator.validate(buildValidCcapsTree(), null);
+ }
+
+ @Test
+ public void testNullListValid() throws ValidationException {
+ final Ccaps ccaps = new CcapsBuilder()
+ .setCcap(null)
+ .build();
+
+ validator.validate(ccaps, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testEmptyListValid() throws ValidationException {
+ final Ccaps ccaps = new CcapsBuilder()
+ .setCcap(Collections.<Ccap>emptyList())
+ .build();
+
+ validator.validate(ccaps, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValid() throws ValidationException {
+ final Ccap ccap = new CcapBuilder().setCcapId("aCcapId").build();
+
+ final Ccaps ccaps = new CcapsBuilder()
+ .setCcap(Collections.singletonList(ccap))
+ .build();
+
+ validator.validate(ccaps, extentParams.getCurrentParam());
+ }
+
+ public static Ccaps buildValidCcapsTree() {
+ final Ccap ccap = CcapValidatorTest.buildValidCcapTree();
+ return new CcapsBuilder()
+ .setCcap(Collections.singletonList(ccap))
+ .build();
+ }
+
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.ccaps;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.Connection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.ConnectionBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ConnectionValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private ConnectionValidator validator = new ConnectionValidator();
+
+ @Test(expected = ValidationException.class)
+ public void testNullConnection() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void testNullExtent() throws ValidationException {
+ validator.validate(null, null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullIpAddress() throws ValidationException {
+ final Connection connection = new ConnectionBuilder(buildValidConnectionTree())
+ .setIpAddress(null)
+ .build();
+
+ validator.validate(connection, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testNullPortNumber() throws ValidationException {
+ final Connection connection = new ConnectionBuilder(buildValidConnectionTree())
+ .setPort(null)
+ .build();
+
+ validator.validate(connection, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValid() throws ValidationException {
+ Connection connection = buildValidConnectionTree();
+ validator.validate(connection, extentParams.getCurrentParam());
+ }
+
+ public static Connection buildValidConnectionTree() {
+ return new ConnectionBuilder()
+ .setIpAddress(new IpAddress(new Ipv4Address("192.168.1.100")))
+ .setPort(new PortNumber(6500))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.App;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.AppBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class AppValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final AppValidator validator = new AppValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullSubscribers() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidApp(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullAppId() throws ValidationException {
+ final App app = new AppBuilder(buildValidApp())
+ .setAppId(null).setKey(null)
+ .build();
+
+ validator.validate(app, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidApp(), extentParams.getCurrentParam());
+ }
+
+ public static App buildValidApp() {
+ return new AppBuilder()
+ .setAppId("unit-test-app")
+ .setSubscribers(SubscribersValidatorTest.buildValidSubscriber())
+ .build();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import java.util.Collections;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.Apps;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.AppsBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class AppsValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final AppsValidator validator = new AppsValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullApps() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidApps(), null);
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidApps(), extentParams.getCurrentParam());
+ }
+
+ public static Apps buildValidApps() {
+ return new AppsBuilder()
+ .setApp(Collections.singletonList(AppValidatorTest.buildValidApp()))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ServiceFlowDirection;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TosByte;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gate.spec.GateSpec;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gate.spec.GateSpecBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class GateSpecValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final GateSpecValidator validator = new GateSpecValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullGateSpec() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidGateSpec(), null);
+ }
+
+ @Test
+ public void nullDirection() throws ValidationException {
+ // optional expect no exception
+ GateSpec gateSpec = new GateSpecBuilder(buildValidGateSpec())
+ .setDirection(null)
+ .build();
+ validator.validate(gateSpec, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void nullDscpTosMask() throws ValidationException {
+ // optional expect no exception
+ GateSpec gateSpec = new GateSpecBuilder(buildValidGateSpec())
+ .setDscpTosMask(null)
+ .build();
+ validator.validate(gateSpec, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void nullDscpTosOverwrite() throws ValidationException {
+ // optional expect no exception
+ GateSpec gateSpec = new GateSpecBuilder(buildValidGateSpec())
+ .setDscpTosOverwrite(null)
+ .build();
+ validator.validate(gateSpec, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidGateSpec(), extentParams.getCurrentParam());
+ }
+
+ public static GateSpec buildValidGateSpec() {
+ return new GateSpecBuilder()
+ .setDirection(ServiceFlowDirection.Us)
+ .setDscpTosMask(new TosByte((short) 0xff))
+ .setDscpTosOverwrite(new TosByte((short) 0xa0))
+ .build();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifiersValidatorTest;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.GateBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class GateValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final GateValidator validator = new GateValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullGate() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidGate(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullGateId() throws ValidationException {
+ Gate gate = new GateBuilder(buildValidGate()).setKey(null).setGateId(null).build();
+ validator.validate(gate, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void nullGateSpec() throws ValidationException {
+ // gate spec is all optional, no exception expected
+ Gate gate = new GateBuilder(buildValidGate()).setGateSpec(null).build();
+ validator.validate(gate, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTrafficProfile() throws ValidationException {
+ Gate gate = new GateBuilder(buildValidGate()).setTrafficProfile(null).build();
+ validator.validate(gate, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullClassifiers() throws ValidationException {
+ Gate gate = new GateBuilder(buildValidGate()).setClassifiers(null).build();
+ validator.validate(gate, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidGate(), extentParams.getCurrentParam());
+ }
+
+
+ public static Gate buildValidGate() {
+ return new GateBuilder()
+ .setGateId("unit-test-gate-id")
+ .setGateSpec(GateSpecValidatorTest.buildValidGateSpec())
+ .setTrafficProfile(TrafficProfileValidatorTest.buildValidTrafficProfile())
+ .setClassifiers(ClassifiersValidatorTest.buildValidClassifiers())
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import java.util.Collections;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.Gates;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.GatesBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class GatesValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final GatesValidator validator = new GatesValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullGates() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidGates(), null);
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidGates(), extentParams.getCurrentParam());
+ }
+
+ public static Gates buildValidGates() {
+ return new GatesBuilder()
+ .setGate(Collections.singletonList(GateValidatorTest.buildValidGate()))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.Subscriber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.SubscriberBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class SubscriberValidatorTest {
+
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final SubscriberValidator validator = new SubscriberValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullSubscriber() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidSubscriber(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSubscriberId() throws ValidationException {
+ final Subscriber subscriber = new SubscriberBuilder(buildValidSubscriber())
+ .setSubscriberId(null).setKey(null)
+ .build();
+ validator.validate(subscriber, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullGates() throws ValidationException {
+ final Subscriber subscriber = new SubscriberBuilder(buildValidSubscriber())
+ .setGates(null)
+ .build();
+ validator.validate(subscriber, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidSubscriber(), extentParams.getCurrentParam());
+ }
+
+ public static Subscriber buildValidSubscriber() {
+ return new SubscriberBuilder()
+ .setSubscriberId("76.76.76.76")
+ .setGates(GatesValidatorTest.buildValidGates())
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import java.util.Collections;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.Subscribers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.SubscribersBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class SubscribersValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final SubscribersValidator validator = new SubscribersValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullSubscribers() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidSubscriber(), null);
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidSubscriber(), extentParams.getCurrentParam());
+ }
+
+ public static Subscribers buildValidSubscriber() {
+ return new SubscribersBuilder()
+ .setSubscriber(Collections.singletonList(SubscriberValidatorTest.buildValidSubscriber()))
+ .build();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ServiceClassName;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.traffic.profile.TrafficProfile;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.traffic.profile.TrafficProfileBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class TrafficProfileValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final TrafficProfileValidator validator = new TrafficProfileValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullTrafficProfile() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidTrafficProfile(), null);
+ }
+
+ @Test
+ public void nullServiceClassName() throws ValidationException {
+ final TrafficProfile trafficProfile = new TrafficProfileBuilder(buildValidTrafficProfile())
+ .setServiceClassName(null)
+ .build();
+ validator.validate(buildValidTrafficProfile(), extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ validator.validate(buildValidTrafficProfile(), extentParams.getCurrentParam());
+ }
+
+
+ public static TrafficProfile buildValidTrafficProfile() {
+ return new TrafficProfileBuilder()
+ .setServiceClassName(new ServiceClassName("unit-test-scn"))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.ClassifierChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.ExtClassifierChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.ExtClassifierChoiceBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.Ipv6ClassifierChoice;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.Ipv6ClassifierChoiceBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.classifier.container.classifier.choice.QosClassifierChoiceBuilder;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ClassifierChoiceValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final ClassifierChoiceValidator validator = new ClassifierChoiceValidator();
+
+ @Test(expected = ValidationException.class)
+ public void testNullClassifierChoice() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void testNullExtent() throws ValidationException {
+ validator.validate(buildValidQosClassifierChoice(), null);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testUnknownClassifierChoiceClass() throws ValidationException {
+ ClassifierChoice unknownChoice = new ClassifierChoice() {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ };
+ validator.validate(unknownChoice, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValid() throws ValidationException {
+ validator.validate(buildValidQosClassifierChoice(),extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValidExt() throws ValidationException {
+ validator.validate(buildValidExtClassifierChoice(), extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void testValidIpv6() throws ValidationException {
+ validator.validate(buildValidIpv6ClassifierChoice(), extentParams.getCurrentParam());
+ }
+
+ public static ClassifierChoice buildValidQosClassifierChoice() {
+ return new QosClassifierChoiceBuilder()
+ .setClassifier(ClassifierValidatorTest.buildValidClassifierTree())
+ .build();
+ }
+
+ public static ExtClassifierChoice buildValidExtClassifierChoice() {
+ return new ExtClassifierChoiceBuilder()
+ .setExtClassifier(ExtClassifierValidatorTest.buildValidExtClassifier())
+ .build();
+ }
+
+ public static Ipv6ClassifierChoice buildValidIpv6ClassifierChoice() {
+ return new Ipv6ClassifierChoiceBuilder()
+ .setIpv6Classifier(Ipv6ClassifierValidatorTest.buildValidIpv6Classifier())
+ .build();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainerBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ClassifierContainerValidatorTest {
+
+ private static final short DEFAULT_ID = (short)1;
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final ClassifierContainerValidator validator = new ClassifierContainerValidator();
+
+ @Test(expected = ValidationException.class)
+ public void testNullClassifierContainer() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNullExtent() throws ValidationException {
+ validator.validate(buildValidClassifierContainer(DEFAULT_ID), null);
+ }
+
+ @Test
+ public void validQos() throws ValidationException {
+ ClassifierContainer classifierContainer = buildValidClassifierContainer(DEFAULT_ID);
+
+ validator.validate(classifierContainer, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void validExt() throws ValidationException {
+ ClassifierContainer classifierContainer = buildValidExtClassifierContainer(DEFAULT_ID);
+
+ validator.validate(classifierContainer, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void validIpv6() throws ValidationException {
+ ClassifierContainer classifierContainer = buildValidIpv6ClassifierContainer(DEFAULT_ID);
+
+ validator.validate(classifierContainer, extentParams.getCurrentParam());
+ }
+
+
+ public static ClassifierContainer buildValidClassifierContainer(short id) {
+ return new ClassifierContainerBuilder()
+ .setClassifierId(id)
+ .setClassifierChoice(ClassifierChoiceValidatorTest.buildValidQosClassifierChoice())
+ .build();
+ }
+
+ public static ClassifierContainer buildValidExtClassifierContainer(short id) {
+ return new ClassifierContainerBuilder()
+ .setClassifierId(id)
+ .setClassifierChoice(ClassifierChoiceValidatorTest.buildValidExtClassifierChoice())
+ .build();
+ }
+
+ public static ClassifierContainer buildValidIpv6ClassifierContainer(short id) {
+ return new ClassifierContainerBuilder()
+ .setClassifierId(id)
+ .setClassifierChoice(ClassifierChoiceValidatorTest.buildValidIpv6ClassifierChoice())
+ .build();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TosByte;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TpProtocol;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.classifier.Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.classifier.ClassifierBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ClassifierValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final ClassifierValidator validator= new ClassifierValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullClassifier() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Params.DoNotUseParams
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidClassifierTree(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcIp() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setSrcIp(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcPort() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setSrcPort(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstIp() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setDstIp(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstPort() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setDstPort(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullProtocol() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setProtocol(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTosByte() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setTosByte(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTosMask() throws ValidationException {
+ Classifier classifier = new ClassifierBuilder(buildValidClassifierTree())
+ .setTosMask(null)
+ .build();
+
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ Classifier classifier = buildValidClassifierTree();
+ validator.validate(classifier, extentParams.getCurrentParam());
+ }
+
+ public static Classifier buildValidClassifierTree() {
+ return new ClassifierBuilder()
+ .setSrcIp(new Ipv4Address("10.0.0.100"))
+ .setSrcPort(new PortNumber(7000))
+ .setDstIp(new Ipv4Address("10.0.0.200"))
+ .setDstPort(new PortNumber(8000))
+ .setProtocol(new TpProtocol(127))
+ .setTosByte(new TosByte((short)0x10))
+ .setTosMask(new TosByte((short)0xf0))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.Classifiers;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.ClassifiersBuilder;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.classifier.attributes.classifiers.ClassifierContainer;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ClassifiersValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final ClassifiersValidator validator = new ClassifiersValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullClassifiers() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void badClassifiersList() throws ValidationException {
+ List<ClassifierContainer> classifierChoices = Lists.newArrayList(
+ ClassifierContainerValidatorTest.buildValidClassifierContainer((short) 1),
+ ClassifierContainerValidatorTest.buildValidIpv6ClassifierContainer((short)2)
+ );
+ Classifiers classifiers = new ClassifiersBuilder()
+ .setClassifierContainer(classifierChoices)
+ .build();
+
+ validator.validate(classifiers, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws Exception {
+ Classifiers classifiers = buildValidClassifiers();
+
+ validator.validate(classifiers, extentParams.getCurrentParam());
+ }
+
+ public static Classifiers buildValidClassifiers() {
+ List<ClassifierContainer> classifierChoices = Lists.newArrayList(
+ ClassifierContainerValidatorTest.buildValidExtClassifierContainer((short)1),
+ ClassifierContainerValidatorTest.buildValidIpv6ClassifierContainer((short) 2)
+ );
+ return new ClassifiersBuilder()
+ .setClassifierContainer(classifierChoices)
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TosByte;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TpProtocol;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ext.classifier.ExtClassifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ext.classifier.ExtClassifierBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class ExtClassifierValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final ExtClassifierValidator validator = new ExtClassifierValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullExtClassifier() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidExtClassifier(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcIp() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setSrcIp(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcPortStart() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setSrcPortStart(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcPortEnd() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setSrcPortEnd(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstIp() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setDstIp(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstPortStart() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setDstPortStart(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstPortEnd() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setDstPortEnd(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullProtocol() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setProtocol(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTosByte() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setTosByte(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTosMask() throws ValidationException {
+ ExtClassifier extClassifier = new ExtClassifierBuilder(buildValidExtClassifier())
+ .setTosMask(null)
+ .build();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ ExtClassifier extClassifier = buildValidExtClassifier();
+
+ validator.validate(extClassifier, extentParams.getCurrentParam());
+ }
+
+ public static ExtClassifier buildValidExtClassifier() {
+ return new ExtClassifierBuilder()
+ .setSrcIp(new Ipv4Address("10.0.0.100"))
+ .setSrcIpMask(new Ipv4Address("255.255.255.0"))
+ .setSrcPortStart(new PortNumber(7000))
+ .setSrcPortEnd(new PortNumber((7005)))
+ .setDstIp(new Ipv4Address("10.0.0.200"))
+ .setDstIpMask(new Ipv4Address("255.255.255.0"))
+ .setDstPortStart(new PortNumber(7000))
+ .setDstPortEnd(new PortNumber(7005))
+ .setProtocol(new TpProtocol(127))
+ .setTosByte(new TosByte((short)0x10))
+ .setTosMask(new TosByte((short)0xf0))
+ .build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 CableLabs and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.controller.packetcable.provider.test.rules.Params;
+import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
+import org.opendaylight.controller.packetcable.provider.validation.Validator;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Prefix;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TosByte;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.TpProtocol;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ipv6.classifier.Ipv6Classifier;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.ipv6.classifier.Ipv6ClassifierBuilder;
+
+/**
+ * @author rvail
+ */
+@Params.AlwaysUseParams
+public class Ipv6ClassifierValidatorTest {
+
+ @Rule
+ public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
+
+ private final Ipv6ClassifierValidator validator = new Ipv6ClassifierValidator();
+
+ @Test(expected = ValidationException.class)
+ public void nullIpv6Classifier() throws ValidationException {
+ validator.validate(null, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void nullExtent() throws ValidationException {
+ validator.validate(buildValidIpv6Classifier(), null);
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcIp6() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setSrcIp6(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcPortStart() throws ValidationException {
+ Ipv6Classifier ipv6Classifier =
+ new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setSrcPortStart(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullSrcPortEnd() throws ValidationException {
+ Ipv6Classifier ipv6Classifier =
+ new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setSrcPortEnd(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstIp6() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setDstIp6(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstPortStart() throws ValidationException {
+ Ipv6Classifier ipv6Classifier =
+ new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setDstPortStart(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullDstPortEnd() throws ValidationException {
+ Ipv6Classifier ipv6Classifier =
+ new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setDstPortEnd(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullFlowLabel() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setFlowLabel(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullNextHdr() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setNextHdr(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTcHigh() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setTcHigh(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTcLow() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setTcLow(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test(expected = ValidationException.class)
+ public void nullTcMask() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = new Ipv6ClassifierBuilder(buildValidIpv6Classifier()).setTcMask(null).build();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ @Test
+ public void valid() throws ValidationException {
+ Ipv6Classifier ipv6Classifier = buildValidIpv6Classifier();
+
+ validator.validate(ipv6Classifier, extentParams.getCurrentParam());
+ }
+
+ public static Ipv6Classifier buildValidIpv6Classifier() {
+ return new Ipv6ClassifierBuilder().setSrcIp6(new Ipv6Prefix("2001:4978:030d:1000:0:0:0:0/64"))
+ .setSrcPortStart(new PortNumber(7000))
+ .setSrcPortEnd(new PortNumber((7005)))
+ .setDstIp6(new Ipv6Prefix("2001:4978:030d:1100:0:0:0:0/64"))
+ .setDstPortStart(new PortNumber(7000))
+ .setDstPortEnd(new PortNumber(7005))
+ .setFlowLabel(101L)
+ .setNextHdr(new TpProtocol(256))
+ .setTcHigh(new TosByte((short) 0xc0))
+ .setTcLow(new TosByte((short) 0x01))
+ .setTcMask(new TosByte((short) 0xe0))
+ .build();
+ }
+}