Added support for RTP and UGS gate traffic profiles
[packetcable.git] / packetcable-policy-server / src / test / java / org / opendaylight / controller / packetcable / provider / validation / impl / validators / ccaps / CcapValidatorTest.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 java.util.Collections;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.opendaylight.controller.packetcable.provider.test.rules.Params;
15 import org.opendaylight.controller.packetcable.provider.validation.ValidationException;
16 import org.opendaylight.controller.packetcable.provider.validation.Validator;
17 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.ServiceClassName;
18 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.ccaps.Ccap;
19 import org.opendaylight.yang.gen.v1.urn.packetcable.rev170125.ccaps.CcapBuilder;
20
21 /**
22  * @author rvail
23  */
24 @Params.AlwaysUseParams
25 public class CcapValidatorTest {
26
27     @Rule
28     public Params<Validator.Extent> extentParams = Params.of(Validator.Extent.class);
29
30     private final CcapValidator validator = new CcapValidator();
31
32     @Test(expected = ValidationException.class)
33     public void testNullCcap() throws ValidationException {
34         validator.validate(null, extentParams.getCurrentParam());
35     }
36
37     @Params.DoNotUseParams
38     @Test(expected = NullPointerException.class)
39     public void testNullExtent() throws ValidationException {
40         validator.validate(buildValidCcapTree(), null);
41     }
42
43     @Test(expected = ValidationException.class)
44     public void testNullCcapId() throws ValidationException {
45         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
46                 // key is based off of CcapId so clear that too
47                 .setKey(null)
48                 .setCcapId(null)
49                 .build();
50
51         validator.validate(ccap, extentParams.getCurrentParam());
52     }
53
54     @Test(expected = ValidationException.class)
55     public void testNullDownstreamScns() throws ValidationException {
56         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
57                 .setDownstreamScns(null)
58                 .build();
59
60         validator.validate(ccap, extentParams.getCurrentParam());
61     }
62
63     @Test(expected = ValidationException.class)
64     public void testEmptyDownstreamScns() throws ValidationException {
65         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
66                 .setDownstreamScns(Collections.<ServiceClassName>emptyList())
67                 .build();
68
69         validator.validate(ccap, extentParams.getCurrentParam());
70     }
71
72     @Test(expected = ValidationException.class)
73     public void testNullUpstreamScns() throws ValidationException {
74         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
75                 .setUpstreamScns(null)
76                 .build();
77
78         validator.validate(ccap, extentParams.getCurrentParam());
79     }
80
81     @Test(expected = ValidationException.class)
82     public void testEmptyUpstreamScns() throws ValidationException {
83         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
84                 .setUpstreamScns(Collections.<ServiceClassName>emptyList())
85                 .build();
86
87         validator.validate(ccap, extentParams.getCurrentParam());
88     }
89
90     @Test(expected = ValidationException.class)
91     public void testNullAmId() throws ValidationException {
92         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
93                 .setAmId(null)
94                 .build();
95
96         validator.validate(ccap, extentParams.getCurrentParam());
97     }
98
99     @Test(expected = ValidationException.class)
100     public void testNullConnection() throws ValidationException {
101         final Ccap ccap = new CcapBuilder(buildValidCcapTree())
102                 .setConnection(null)
103                 .build();
104
105         validator.validate(ccap, extentParams.getCurrentParam());
106     }
107
108     @Test
109     public void testValid() throws ValidationException {
110         final Ccap ccap = buildValidCcapTree();
111
112         validator.validate(ccap, extentParams.getCurrentParam());
113     }
114
115     public static Ccap buildValidCcapTree() {
116         return new CcapBuilder()
117                 .setCcapId("aCcapId")
118                 .setDownstreamScns(Collections.singletonList(new ServiceClassName("down_scn")))
119                 .setUpstreamScns(Collections.singletonList(new ServiceClassName("up_scn")))
120                 .setAmId(AmIdValidatorTest.buildValidAmIdTree())
121                 .setConnection(ConnectionValidatorTest.buildValidConnectionTree())
122                 .build();
123     }
124 }