package org.graylog.plugins.netflow.flows.cflow;

import com.google.common.io.Resources;
import io.netty.buffer.Unpooled;
import org.joda.time.DateTime;
import org.junit.Test;

import java.net.URL;

import static org.junit.Assert.assertEquals;

public class NetFlowV5PacketTest {
    @Test
    public void test() throws Exception {
        final URL resource = Resources.getResource("netflow-data/netflow-v5-1.dat");
        final byte[] bytes = Resources.toByteArray(resource);

        final NetFlowV5Packet packet = NetFlowV5Packet.parse(null, Unpooled.wrappedBuffer(bytes));

        final NetFlowV5 flow1 = packet.flows.get(0);
        final NetFlowV5 flow2 = packet.flows.get(1);

        assertEquals(2, packet.flows.size());
        assertEquals(0, packet.engineId);
        assertEquals(0, packet.engineType);

        assertEquals(0, flow1.tos);
        assertEquals("/10.0.2.2", flow1.srcAddress.toString());
        assertEquals("/10.0.2.15", flow1.dstAddress.toString());
        assertEquals("/0.0.0.0", flow1.nextHop.get().toString());
        assertEquals(54435, flow1.srcPort);
        assertEquals(22, flow1.dstPort);
        assertEquals(6, flow1.proto);
        assertEquals(16, flow1.tcpflags);
        assertEquals(new DateTime("2015-06-21T13:40:51.914+02:00"), flow1.start.get());
        assertEquals(new DateTime("2015-05-02T18:38:07.196Z"), flow1.stop.get());
        assertEquals(230, flow1.bytes);
        assertEquals(5, flow1.pkts);
    }
}
@@ -1455,16 +1455,660 @@
 1.pkts);
+%0A%0A        assertEquals(0, flow2.tos);%0A        assertEquals(%22/10.0.2.15%22, flow2.srcAddress.toString());%0A        assertEquals(%22/10.0.2.2%22, flow2.dstAddress.toString());%0A        assertEquals(%22/0.0.0.0%22, flow2.nextHop.get().toString());%0A        assertEquals(22, flow2.srcPort);%0A        assertEquals(54435, flow2.dstPort);%0A        assertEquals(6, flow2.proto);%0A        assertEquals(24, flow2.tcpflags);%0A        assertEquals(new DateTime(%222015-06-21T13:40:51.914+02:00%22), flow2.start.get());%0A        assertEquals(new DateTime(%222015-05-02T18:38:07.196Z%22), flow2.stop.get());%0A        assertEquals(304, flow2.bytes);%0A        assertEquals(4, flow2.pkts);
 %0A    %7D%0A%7D

Add test for second package.