Carmelo Cascone | 17fc9e4 | 2016-05-31 11:29:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.bmv2.ctl; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.bmv2.api.context.Bmv2Configuration; |
| 21 | import org.onosproject.bmv2.api.runtime.Bmv2ParsedTableEntry; |
| 22 | |
| 23 | import java.io.IOException; |
| 24 | import java.net.URISyntaxException; |
| 25 | import java.nio.charset.Charset; |
| 26 | import java.nio.file.Files; |
| 27 | import java.nio.file.Paths; |
| 28 | import java.util.List; |
| 29 | |
| 30 | import static org.hamcrest.MatcherAssert.assertThat; |
| 31 | import static org.hamcrest.Matchers.equalTo; |
| 32 | |
| 33 | public class Bmv2TableDumpParserTest { |
| 34 | |
| 35 | private Bmv2Configuration configuration = Bmv2DeviceContextServiceImpl.loadDefaultConfiguration(); |
| 36 | |
| 37 | @Test |
| 38 | public void testParse() throws Exception { |
| 39 | String text = readFile(); |
| 40 | List<Bmv2ParsedTableEntry> result = Bmv2TableDumpParser.parse(text, configuration); |
| 41 | assertThat(result.size(), equalTo(10)); |
| 42 | } |
| 43 | |
| 44 | private String readFile() |
| 45 | throws IOException, URISyntaxException { |
| 46 | byte[] encoded = Files.readAllBytes(Paths.get(this.getClass().getResource("/tabledump.txt").toURI())); |
| 47 | return new String(encoded, Charset.defaultCharset()); |
| 48 | } |
| 49 | } |