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