Migrate deprecated assertThat()
[bgpcep.git] / bgp / util / src / test / java / org / opendaylight / protocol / bgp / util / BGPHexFileParserTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.util;
9
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;
14
15 import java.io.File;
16 import java.io.FileNotFoundException;
17 import java.util.List;
18 import org.junit.Test;
19
20 public class BGPHexFileParserTest {
21
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;
25
26     @Test
27     public void testCleanWhiteSpace() {
28         final String input = "abc def\r\nghi\nj";
29         assertEquals("ABCDEFGHIJ", HexDumpBGPFileParser.clearWhiteSpaceToUpper(input));
30     }
31
32     @Test
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());
37     }
38
39     @Test
40     public void testParsingInvalidMessage() throws Exception {
41         try {
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"));
48         }
49     }
50
51     @Test
52     public void testParsingInvalidFile() throws Exception {
53         try {
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"));
58         }
59     }
60 }