Add missing license headers
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / gates / impl / BestEffortServiceTest.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 BestEffortService to ensure both construction and byte parsing result in correct object
15  * creation.
16  */
17 public class BestEffortServiceTest {
18
19     @Test(expected = IllegalArgumentException.class)
20     public void nullAllEnvelopes() {
21         new BestEffortService(null, null, null);
22     }
23
24     @Test
25     public void requiredEnvelopeOnly() {
26         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
27         final BestEffortService service = new BestEffortService(auth, null, null);
28         Assert.assertNotNull(service.getAuthorizedEnvelop());
29         Assert.assertNull(service.getReservedEnvelop());
30         Assert.assertNull(service.getCommittedEnvelop());
31         // TODO - add more validation here
32     }
33
34     @Test
35     public void authAndReservedEnvelopes() {
36         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
37         final BEEnvelop resv = new BEEnvelop((byte)10, 11, 12, 13, 14, (short)15, (short)16, 17, 18, 19, 10, 11, 12, 13);
38         final BestEffortService service = new BestEffortService(auth, resv, null);
39         Assert.assertNotNull(service.getAuthorizedEnvelop());
40         Assert.assertNotNull(service.getReservedEnvelop());
41         Assert.assertNull(service.getCommittedEnvelop());
42         // TODO - add more validation here
43     }
44
45     @Test
46     public void allEnvelopes() {
47         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
48         final BEEnvelop resv = new BEEnvelop((byte)10, 11, 12, 13, 14, (short)15, (short)16, 17, 18, 19, 10, 11, 12, 13);
49         final BEEnvelop cmmt = new BEEnvelop((byte)20, 21, 22, 23, 24, (short)25, (short)26, 27, 28, 29, 20, 21, 22, 23);
50         final BestEffortService service = new BestEffortService(auth, resv, cmmt);
51         Assert.assertNotNull(service.getAuthorizedEnvelop());
52         Assert.assertNotNull(service.getReservedEnvelop());
53         Assert.assertNotNull(service.getCommittedEnvelop());
54         // TODO - add more validation here
55     }
56
57     @Test
58     public void byteParsingAuth() {
59         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
60         final BestEffortService service = new BestEffortService(auth, null, null);
61         final BestEffortService parsed = BestEffortService.parse(service.getBytes());
62         Assert.assertEquals(service, parsed);
63     }
64
65     @Test
66     public void byteParsingAuthReserved() {
67         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
68         final BEEnvelop resv = new BEEnvelop((byte)10, 11, 12, 13, 14, (short)15, (short)16, 17, 18, 19, 10, 11, 12, 13);
69         final BestEffortService service = new BestEffortService(auth, resv, null);
70         final BestEffortService parsed = BestEffortService.parse(service.getBytes());
71         Assert.assertEquals(service, parsed);
72     }
73
74     @Test
75     public void byteParsingAll() {
76         final BEEnvelop auth = new BEEnvelop((byte)0, 1, 2, 3, 4, (short)5, (short)6, 7, 8, 9, 0, 1, 2, 3);
77         final BEEnvelop resv = new BEEnvelop((byte)10, 11, 12, 13, 14, (short)15, (short)16, 17, 18, 19, 10, 11, 12, 13);
78         final BEEnvelop cmmt = new BEEnvelop((byte)20, 21, 22, 23, 24, (short)25, (short)26, 27, 28, 29, 20, 21, 22, 23);
79         final BestEffortService service = new BestEffortService(auth, resv, cmmt);
80         final BestEffortService parsed = BestEffortService.parse(service.getBytes());
81         Assert.assertEquals(service, parsed);
82     }
83
84 }