9ca67ac347fc15f8a7a079ef03c4848ce91a4d3c
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / qos / SubscriberValidatorTest.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.yang.gen.v1.urn.packetcable.rev161017.pcmm.qos.gates.apps.app.subscribers.Subscriber;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev161017.pcmm.qos.gates.apps.app.subscribers.SubscriberBuilder;
18
19 /**
20  * @author rvail
21  */
22 @Params.AlwaysUseParams
23 public class SubscriberValidatorTest {
24
25
26     @Rule
27     public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
28
29     private final SubscriberValidator validator = new SubscriberValidator();
30
31     @Test(expected = ValidationException.class)
32     public void nullSubscriber() 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(buildValidSubscriber(), null);
40     }
41
42     @Test(expected = ValidationException.class)
43     public void nullSubscriberId() throws ValidationException {
44         final Subscriber subscriber = new SubscriberBuilder(buildValidSubscriber())
45                 .setSubscriberId(null).setKey(null)
46                 .build();
47         validator.validate(subscriber, extentParams.getCurrentParam());
48     }
49
50     @Test(expected = ValidationException.class)
51     public void nullGates() throws ValidationException {
52         final Subscriber subscriber = new SubscriberBuilder(buildValidSubscriber())
53                 .setGates(null)
54                 .build();
55         validator.validate(subscriber, extentParams.getCurrentParam());
56     }
57
58     @Test
59     public void valid() throws ValidationException {
60         validator.validate(buildValidSubscriber(), extentParams.getCurrentParam());
61     }
62
63     public static Subscriber buildValidSubscriber() {
64         return new SubscriberBuilder()
65                 .setSubscriberId("76.76.76.76")
66                 .setGates(GatesValidatorTest.buildValidGates())
67                 .build();
68     }
69 }