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.bgp.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 BGPHexFileParserTest {
22 private static final String HEX_DUMP_FILE_NAME = "bgp_hex.txt";
23 private static final String BGP_MESSAGE_HEX_INVALID_LENGTH_BIN = "BgpMessage_Hex_InvalidLength.bin";
24 private static final int EXPECTED_SIZE = 25;
27 public void testCleanWhiteSpace() {
28 final String input = "abc def\r\nghi\nj";
29 assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
33 public void testParsing() throws Exception {
34 final List<byte[]> result = HexDumpBGPFileParser.parseMessages(getClass().getClassLoader()
35 .getResourceAsStream(BGPHexFileParserTest.HEX_DUMP_FILE_NAME));
36 assertEquals(EXPECTED_SIZE, result.size());
40 public void testParsingInvalidMessage() throws Exception {
42 HexDumpBGPFileParser.parseMessages(getClass().getClassLoader()
43 .getResourceAsStream(BGP_MESSAGE_HEX_INVALID_LENGTH_BIN));
44 fail("Exception should have occured.");
45 } catch (final IllegalArgumentException e) {
46 assertThat(e.getMessage(), containsString("Invalid message at index 0, "
47 + "length atribute is lower than 19"));
52 public void testParsingInvalidFile() throws Exception {
54 HexDumpBGPFileParser.parseMessages(new File("bad file name"));
55 fail("Exception should have occured.");
56 } catch (final FileNotFoundException e) {
57 assertThat(e.getMessage(), containsString("bad file name"));