9b21b5ccf394133e36743b63efd6feb739f85dc6
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / GateValidatorTest.java
1 /*
2  * Copyright (c) 2015 CableLabs and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos;
10
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.opendaylight.controller.packetcable.provider.test.rules.Params;
14 import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
15 import org.opendaylight.controller.packetcable.provider.validation.Validator;
16 import org.opendaylight.controller.packetcable.provider.validation.impl.validators.qos.classifier.ClassifiersValidatorTest;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.Gate;
18 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161219.pcmm.qos.gates.apps.app.subscribers.subscriber.gates.GateBuilder;
19
20 /**
21  * @author rvail
22  */
23 @Params.AlwaysUseParams
24 public class GateValidatorTest {
25
26     @Rule
27     public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
28
29     private final GateValidator validator = new GateValidator();
30
31     @Test(expected = ValidationException.class)
32     public void nullGate() throws ValidationException {
33         validator.validate(null, extentParams.getCurrentParam());
34     }
35
36     @Params.DoNotUseParams
37     @Test(expected = NullPointerException.class)
38     public void nullExtent() throws ValidationException {
39         validator.validate(buildValidGate(), null);
40     }
41
42     @Test(expected = ValidationException.class)
43     public void nullGateId() throws ValidationException {
44         Gate gate = new GateBuilder(buildValidGate()).setKey(null).setGateId(null).build();
45         validator.validate(gate, extentParams.getCurrentParam());
46     }
47
48     @Test
49     public void nullGateSpec() throws ValidationException {
50         // gate spec is all optional, no exception expected
51         Gate gate = new GateBuilder(buildValidGate()).setGateSpec(null).build();
52         validator.validate(gate, extentParams.getCurrentParam());
53     }
54
55     @Test(expected = ValidationException.class)
56     public void nullTrafficProfile() throws ValidationException {
57         Gate gate = new GateBuilder(buildValidGate()).setTrafficProfile(null).build();
58         validator.validate(gate, extentParams.getCurrentParam());
59     }
60
61     @Test(expected = ValidationException.class)
62     public void nullClassifiers() throws ValidationException {
63         Gate gate = new GateBuilder(buildValidGate()).setClassifiers(null).build();
64         validator.validate(gate, extentParams.getCurrentParam());
65     }
66
67     @Test
68     public void valid() throws ValidationException {
69         validator.validate(buildValidGate(), extentParams.getCurrentParam());
70     }
71
72
73     public static Gate buildValidGate() {
74         return new GateBuilder()
75                 .setGateId("unit-test-gate-id")
76                 .setGateSpec(GateSpecValidatorTest.buildValidGateSpec())
77                 .setTrafficProfile(TrafficProfileValidatorTest.buildValidTrafficProfile())
78                 .setClassifiers(ClassifiersValidatorTest.buildValidClassifiers())
79                 .build();
80     }
81 }