Add missing license headers
[packetcable.git] / packetcable-driver / src / test / java / org / pcmm / objects / SyncOptionsTest.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.objects;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.pcmm.objects.SyncOptions.ReportType;
13 import org.pcmm.objects.SyncOptions.SyncType;
14 import org.umu.cops.stack.COPSMsgParser;
15
16 /**
17  * Tests the data holder class SyncOptions to ensure both construction and byte parsing result in correct object
18  * creation.
19  */
20 public class SyncOptionsTest {
21
22     @Test(expected = IllegalArgumentException.class)
23     public void nullReportType() {
24         new SyncOptions(null, SyncType.FULL_SYNCHRONIZATION);
25     }
26
27     @Test(expected = IllegalArgumentException.class)
28     public void nullSyncType() {
29         new SyncOptions(ReportType.STANDARD_REPORT_DATA, null);
30     }
31
32     @Test
33     public void construction() {
34         final SyncOptions syncOpts = new SyncOptions(ReportType.STANDARD_REPORT_DATA, SyncType.FULL_SYNCHRONIZATION);
35         final byte[] dataBytes = syncOpts.getBytes();
36         Assert.assertEquals(4, dataBytes.length);
37         Assert.assertEquals(ReportType.STANDARD_REPORT_DATA,
38                 ReportType.valueOf(COPSMsgParser.bytesToShort(dataBytes[0], dataBytes[1])));
39         Assert.assertEquals(SyncType.FULL_SYNCHRONIZATION,
40                 SyncType.valueOf(COPSMsgParser.bytesToShort(dataBytes[2], dataBytes[3])));
41     }
42
43     @Test
44     public void byteParsing() {
45         final SyncOptions syncOpts = new SyncOptions(ReportType.COMPLETE_GATE_DATA, SyncType.INCREMENTAL_SYNCHRONIZATION);
46         final SyncOptions parsed = SyncOptions.parse(syncOpts.getBytes());
47         Assert.assertEquals(syncOpts, parsed);
48     }
49
50 }