Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.cpman.message; |
| 17 | |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 18 | import com.google.common.collect.Sets; |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 19 | import org.junit.Test; |
| 20 | import org.onosproject.cpman.ControlMessage; |
| 21 | import org.onosproject.cpman.DefaultControlMessage; |
| 22 | import org.onosproject.event.AbstractEventTest; |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 23 | import org.onosproject.net.DeviceId; |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 24 | |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 25 | import java.util.Set; |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 26 | |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 27 | import static org.onosproject.cpman.ControlMessage.Type.INBOUND_PACKET; |
| 28 | import static org.onosproject.cpman.ControlMessage.Type.OUTBOUND_PACKET; |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Tests of the control message event. |
| 32 | */ |
| 33 | public class ControlMessageEventTest extends AbstractEventTest { |
| 34 | |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 35 | private ControlMessage createControlMessage(ControlMessage.Type type, |
| 36 | DeviceId deviceId) { |
| 37 | return new DefaultControlMessage(type, deviceId, 0L, 0L, 0L, 0L); |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 38 | } |
| 39 | |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 40 | 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 Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 45 | return controlMessages; |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | @Test |
| 50 | public void withoutTime() { |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 51 | Set<ControlMessage> cms = createControlMessages(); |
Jian Li | 5c5ddcd | 2016-02-10 22:54:04 -0800 | [diff] [blame] | 52 | 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 | } |