blob: 9d3fdff6938fef50eb9d222f754fb713949e2aed [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
Jian Li72b9b122016-02-11 15:58:51 -080018import com.google.common.collect.Sets;
Jian Li5c5ddcd2016-02-10 22:54:04 -080019import org.junit.Test;
20import org.onosproject.cpman.ControlMessage;
21import org.onosproject.cpman.DefaultControlMessage;
22import org.onosproject.event.AbstractEventTest;
Jian Li72b9b122016-02-11 15:58:51 -080023import org.onosproject.net.DeviceId;
Jian Li5c5ddcd2016-02-10 22:54:04 -080024
Jian Li72b9b122016-02-11 15:58:51 -080025import java.util.Set;
Jian Li5c5ddcd2016-02-10 22:54:04 -080026
Jian Li72b9b122016-02-11 15:58:51 -080027import static org.onosproject.cpman.ControlMessage.Type.INBOUND_PACKET;
28import static org.onosproject.cpman.ControlMessage.Type.OUTBOUND_PACKET;
Jian Li5c5ddcd2016-02-10 22:54:04 -080029
30/**
31 * Tests of the control message event.
32 */
33public class ControlMessageEventTest extends AbstractEventTest {
34
Jian Li72b9b122016-02-11 15:58:51 -080035 private ControlMessage createControlMessage(ControlMessage.Type type,
36 DeviceId deviceId) {
37 return new DefaultControlMessage(type, deviceId, 0L, 0L, 0L, 0L);
Jian Li5c5ddcd2016-02-10 22:54:04 -080038 }
39
Jian Li72b9b122016-02-11 15:58:51 -080040 private Set<ControlMessage> createControlMessages() {
41 final DeviceId deviceId = DeviceId.deviceId("of:0000000000000001");
42 Set<ControlMessage> controlMessages = Sets.newConcurrentHashSet();
43 controlMessages.add(createControlMessage(INBOUND_PACKET, deviceId));
44 controlMessages.add(createControlMessage(OUTBOUND_PACKET, deviceId));
Jian Li5c5ddcd2016-02-10 22:54:04 -080045 return controlMessages;
46 }
47
48 @Override
49 @Test
50 public void withoutTime() {
Jian Li72b9b122016-02-11 15:58:51 -080051 Set<ControlMessage> cms = createControlMessages();
Jian Li5c5ddcd2016-02-10 22:54:04 -080052 long before = System.currentTimeMillis();
53 ControlMessageEvent event =
54 new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, cms);
55 long after = System.currentTimeMillis();
56 validateEvent(event, ControlMessageEvent.Type.STATS_UPDATE, cms, before, after);
57 }
58}