boyoung2 | a8549d2 | 2018-11-23 20:42:37 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.openstacktelemetry.util; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.packet.IPv4; |
| 20 | |
| 21 | import static org.junit.Assert.assertEquals; |
| 22 | import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getProtocolNameFromType; |
| 23 | import static org.onosproject.openstacktelemetry.util.OpenstackTelemetryUtil.getProtocolTypeFromString; |
| 24 | |
| 25 | public class OpenstackTelemetryUtilTest { |
| 26 | |
| 27 | private static final String PROTOCOL_TCP_L = "TCP"; |
| 28 | private static final String PROTOCOL_TCP_S = "tcp"; |
| 29 | private static final String PROTOCOL_UDP_L = "UDP"; |
| 30 | private static final String PROTOCOL_UDP_S = "udp"; |
| 31 | private static final String PROTOCOL_ANY_L = "ANY"; |
| 32 | private static final String PROTOCOL_ANY_S = "any"; |
| 33 | |
| 34 | /** |
| 35 | * Tests getting a protocol type from a protocol name. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testGetProtocolTypeFromString() { |
| 39 | assertEquals(IPv4.PROTOCOL_TCP, getProtocolTypeFromString(PROTOCOL_TCP_L)); |
| 40 | assertEquals(IPv4.PROTOCOL_TCP, getProtocolTypeFromString(PROTOCOL_TCP_S)); |
| 41 | |
| 42 | assertEquals(IPv4.PROTOCOL_UDP, getProtocolTypeFromString(PROTOCOL_UDP_L)); |
| 43 | assertEquals(IPv4.PROTOCOL_UDP, getProtocolTypeFromString(PROTOCOL_UDP_S)); |
| 44 | |
| 45 | assertEquals(0, getProtocolTypeFromString(PROTOCOL_ANY_L)); |
| 46 | assertEquals(0, getProtocolTypeFromString(PROTOCOL_ANY_S)); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Tests getting a protocol name from a protocol type. |
| 51 | */ |
| 52 | @Test |
| 53 | public void testGetProtocolNameFromType() { |
| 54 | assertEquals(PROTOCOL_TCP_S, getProtocolNameFromType(IPv4.PROTOCOL_TCP)); |
| 55 | assertEquals(PROTOCOL_UDP_S, getProtocolNameFromType(IPv4.PROTOCOL_UDP)); |
| 56 | assertEquals(PROTOCOL_ANY_S, getProtocolNameFromType((byte) 0)); |
| 57 | } |
| 58 | } |