2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.util;
10 import static org.hamcrest.CoreMatchers.containsString;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.fail;
16 import java.io.FileNotFoundException;
17 import java.util.List;
18 import org.junit.Test;
20 public class PCEPHexDumpParserTest {
22 private static final String HEX_DUMP_FILE_NAME = "pcep-hex.txt";
23 private static final int EXPECTED_SIZE = 6;
26 public void testParsing() throws Exception {
27 final List<byte[]> result = PCEPHexDumpParser.parseMessages(getClass().getClassLoader().getResourceAsStream(
28 PCEPHexDumpParserTest.HEX_DUMP_FILE_NAME));
29 assertEquals(EXPECTED_SIZE, result.size());
30 final List<byte[]> result1 = PCEPHexDumpParser.parseMessages(new File(getClass().getClassLoader().getResource(
31 PCEPHexDumpParserTest.HEX_DUMP_FILE_NAME).toURI()));
32 assertEquals(EXPECTED_SIZE, result1.size());
36 public void testParsingInvalidFile() throws Exception {
38 PCEPHexDumpParser.parseMessages(new File("bad file name"));
39 fail("Exception should have occured.");
40 } catch (final FileNotFoundException e) {
41 assertThat(e.getMessage(), containsString("bad file name"));