Minor fixes and adding unit testing for validators
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / ccaps / AmIdValidatorTest.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.ccaps;
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.rev151101.ccap.attributes.AmId;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev151101.ccap.attributes.AmIdBuilder;
18
19 /**
20  * @author rvail
21  */
22 @Params.AlwaysUseParams
23 public class AmIdValidatorTest {
24
25     @Rule
26     public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
27
28     private final AmIdValidator validator = new AmIdValidator();
29
30     @Test
31     public void testValid() throws Exception {
32         AmId amId = new AmIdBuilder()
33                 .setAmTag(1)
34                 .setAmType(1)
35                 .build();
36
37         // this throw an exception if invalid
38         validator.validate(amId, extentParams.getCurrentParam());
39     }
40
41     @Test(expected = ValidationException.class)
42     public void testNoAmTag() throws Exception {
43         AmId amId = new AmIdBuilder()
44                 .setAmType(1)
45                 .build();
46
47         // this throw an exception if invalid
48         validator.validate(amId, extentParams.getCurrentParam());
49     }
50
51     @Test(expected = ValidationException.class)
52     public void testNoAmType() throws Exception {
53         AmId amId = new AmIdBuilder()
54                 .setAmTag(1)
55                 .build();
56
57         // this throw an exception if invalid
58         validator.validate(amId, extentParams.getCurrentParam());
59     }
60
61     @Test(expected = ValidationException.class)
62     public void testNullAmId() throws Exception {
63         // this throw an exception if invalid
64         validator.validate(null, extentParams.getCurrentParam());
65     }
66
67     public static AmId buildValidAmIdTree() {
68         return new AmIdBuilder()
69                 .setAmType(1)
70                 .setAmTag(2)
71                 .build();
72     }
73 }