blob: 22e276244475b750cbaac54209cfc0c8ec9b9d9c [file] [log] [blame]
Jian Li5c5ddcd2016-02-10 22:54:04 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Jian Li5c5ddcd2016-02-10 22:54:04 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cpman.message;
17
18import org.junit.Test;
19import org.onosproject.cpman.DefaultControlMessage;
Jian Li72b9b122016-02-11 15:58:51 -080020import org.onosproject.net.DeviceId;
Jian Li5c5ddcd2016-02-10 22:54:04 -080021
22import static org.hamcrest.Matchers.is;
23import static org.junit.Assert.assertThat;
24import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
25import static org.onosproject.cpman.ControlMessage.Type.INBOUND_PACKET;
26
27/**
28 * Unit tests for the default control message class.
29 */
30public class DefaultControlMessageTest {
31
32 /**
33 * Checks that the DefaultControlMessage class is immutable but can be
34 * inherited from.
35 */
36 @Test
37 public void testImmutability() {
38 assertThatClassIsImmutableBaseClass(DefaultControlMessage.class);
39 }
40
41 /**
42 * Tests creation of a DefaultControlMessage using a regular constructor.
43 */
44 @Test
45 public void testBasic() {
Jian Li72b9b122016-02-11 15:58:51 -080046 final DeviceId deviceId = DeviceId.deviceId("of:0000000000000001");
Jian Li5c5ddcd2016-02-10 22:54:04 -080047 final DefaultControlMessage cm =
Jian Li72b9b122016-02-11 15:58:51 -080048 new DefaultControlMessage(INBOUND_PACKET, deviceId, 0L, 1L, 2L, 3L);
Jian Li5c5ddcd2016-02-10 22:54:04 -080049 assertThat(cm.type(), is(INBOUND_PACKET));
50 assertThat(cm.load(), is(0L));
51 assertThat(cm.rate(), is(1L));
52 assertThat(cm.count(), is(2L));
Jian Li72b9b122016-02-11 15:58:51 -080053 assertThat(cm.timestamp(), is(3L));
Jian Li5c5ddcd2016-02-10 22:54:04 -080054 }
55}