2 * Copyright (c) 2015 Cable Television Laboratories, Inc and others. All rights reserved.
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
8 package org.pcmm.objects;
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;
17 * Tests the data holder class SyncOptions to ensure both construction and byte parsing result in correct object
20 public class SyncOptionsTest {
22 @Test(expected = IllegalArgumentException.class)
23 public void nullReportType() {
24 new SyncOptions(null, SyncType.FULL_SYNCHRONIZATION);
27 @Test(expected = IllegalArgumentException.class)
28 public void nullSyncType() {
29 new SyncOptions(ReportType.STANDARD_REPORT_DATA, null);
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])));
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);