Merge "Minor fixes and adding unit testing for validators"
[packetcable.git] / packetcable-policy-server / src / main / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / GateValidator.java
index e97974cc501c51a187caad107e46ad1e28cc7830..58a9efd02283686156e7494d6b7f9aec97baf089 100644 (file)
@@ -8,12 +8,9 @@
 
 package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
 
-import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.AbstractValidator;
-import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifierValidator;
-import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ExtClassifierValidator;
-import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.Ipv6ClassifierValidator;
-import org.opendaylight.yang.gen.v1.urn.packetcable.rev151026.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
+import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifiersValidator;
+import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
 
 /**
  * @author rvail
@@ -23,17 +20,17 @@ public class GateValidator extends AbstractValidator<Gate> {
     private static final String GATE_ID = "gate.gateId";
     private static final String GATE_SPEC = "gate.gate-spec";
     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 ClassifierValidator classifierValidator = new ClassifierValidator();
-    private final ExtClassifierValidator extClassifierValidator = new ExtClassifierValidator();
-    private final Ipv6ClassifierValidator ipv6ClassifierValidator = new Ipv6ClassifierValidator();
+    private final ClassifiersValidator classifiersValidator = new ClassifiersValidator();
 
     @Override
-    public void validate(final Gate gate, final Extent extent) throws ValidationException {
+    protected void doValidate(final Gate gate, final Extent extent) {
         if (gate == null) {
-            throw new ValidationException("gate must exist");
+            getErrorMessages().add("gate must exist");
+            return;
         }
 
         mustExist(gate.getGateId(), GATE_ID);
@@ -41,50 +38,13 @@ public class GateValidator extends AbstractValidator<Gate> {
         // all leafs in GateSpec are optional
         // mustExist(gate.getGateSpec(), GATE_SPEC);
 
+        // Classifiers
+        mustExist(gate.getClassifiers(), CLASSIFIERS);
+
         mustExist(gate.getTrafficProfile(), TRAFFIC_PROFILE);
         if (extent == Extent.NODE_AND_SUBTREE) {
-//            validateChild(gateSpecValidatator, gate.getGateSpec());
             validateChild(trafficProfileValidator, gate.getTrafficProfile());
+            validateChild(classifiersValidator, gate.getClassifiers());
         }
-
-        // Classifiers
-
-        if (gate.getClassifier() != null) {
-
-            // classifer is not null, ext and ipv6 must be null
-
-            if (gate.getExtClassifier() != null || gate.getIpv6Classifier() != null) {
-                getErrorMessages().add("Only one type of classifier is allowed");
-            }
-            else if (extent == Extent.NODE_AND_SUBTREE) {
-                validateChild(classifierValidator, gate.getClassifier());
-            }
-
-        }
-        else if (gate.getExtClassifier() != null) {
-
-            // classifer is null; ext is not null and ipv6 must be null
-
-            if (gate.getIpv6Classifier() != null) {
-                getErrorMessages().add("Only one type of classifier is allowed");
-            }
-            else if (extent == Extent.NODE_AND_SUBTREE) {
-                validateChild(extClassifierValidator, gate.getExtClassifier());
-            }
-
-        }
-        else if (gate.getIpv6Classifier() != null) {
-
-            // classifer and ext are null; ipv6 is not
-            if (extent == Extent.NODE_AND_SUBTREE) {
-                validateChild(ipv6ClassifierValidator, gate.getIpv6Classifier());
-            }
-
-        }
-        else {
-            getErrorMessages().add("a classifer is required");
-        }
-
-        throwErrorsIfNeeded();
     }
 }