Add missing license headers
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / gates / impl / DOCSISServiceClassNameTrafficProfileTest.java
1 /*
2  * Copyright (c) 2015 Cable Television Laboratories, Inc 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 package org.pcmm.gates.impl;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12
13 /**
14  * Tests the data holder class DOCSISServiceClassNameTrafficProfile to ensure both construction and byte parsing result
15  * in correct object creation.
16  */
17 public class DOCSISServiceClassNameTrafficProfileTest {
18
19     @Test(expected = IllegalArgumentException.class)
20     public void constructor1NullSCN() {
21         new DOCSISServiceClassNameTrafficProfile(null);
22     }
23
24     @Test(expected = IllegalArgumentException.class)
25     public void constructor1ShortSCN() {
26         new DOCSISServiceClassNameTrafficProfile("1");
27     }
28
29     @Test(expected = IllegalArgumentException.class)
30     public void constructor1LongSCN() {
31         new DOCSISServiceClassNameTrafficProfile("01234567891234567");
32     }
33
34     @Test(expected = IllegalArgumentException.class)
35     public void constructor2NullSCN() {
36         new DOCSISServiceClassNameTrafficProfile((byte)1, null);
37     }
38
39     @Test(expected = IllegalArgumentException.class)
40     public void constructor2ShortSCN() {
41         new DOCSISServiceClassNameTrafficProfile((byte)1, "1");
42     }
43
44     @Test(expected = IllegalArgumentException.class)
45     public void constructor2LongSCN() {
46         new DOCSISServiceClassNameTrafficProfile((byte)1, "01234567891234567");
47     }
48
49     @Test
50     public void construction() {
51         final DOCSISServiceClassNameTrafficProfile profile =
52                 new DOCSISServiceClassNameTrafficProfile((byte)5, "0123456789123456");
53         Assert.assertEquals((byte)5, profile.getEnvelop());
54         Assert.assertEquals("0123456789123456", profile.getScnName());
55     }
56
57     @Test
58     public void byteParsingWithoutPadding() {
59         // Name length % 4 == 0
60         final DOCSISServiceClassNameTrafficProfile profile =
61                 new DOCSISServiceClassNameTrafficProfile((byte)25, "1234");
62         final DOCSISServiceClassNameTrafficProfile parsed =
63                 DOCSISServiceClassNameTrafficProfile.parse(profile.getBytes());
64         Assert.assertEquals(profile, parsed);
65     }
66
67     @Test
68     public void byteParsingWithOnePaddedChar() {
69         // Name length % 4 == 1
70         final DOCSISServiceClassNameTrafficProfile profile =
71                 new DOCSISServiceClassNameTrafficProfile((byte)25, "123");
72         final DOCSISServiceClassNameTrafficProfile parsed =
73                 DOCSISServiceClassNameTrafficProfile.parse(profile.getBytes());
74         Assert.assertEquals(profile, parsed);
75     }
76
77     @Test
78     public void byteParsingWithThreePaddedChar() {
79         // Name length % 4 == 3
80         final DOCSISServiceClassNameTrafficProfile profile =
81                 new DOCSISServiceClassNameTrafficProfile((byte)25, "12345");
82         final DOCSISServiceClassNameTrafficProfile parsed =
83                 DOCSISServiceClassNameTrafficProfile.parse(profile.getBytes());
84         Assert.assertEquals(profile, parsed);
85     }
86
87 }