@Test public void readPacket() throws IOException { listener = Mockito.mock(IPacketListener.class); reader.setAdapter(adapter); ReflectionTestUtils.setField(reader, "filemanager", mockFileManager); ReflectionTestUtils.setField(reader, "pcapngHelper", pcapNgHelper); ReflectionTestUtils.setField(reader, "extrunner", extrunner); Mockito.when(extrunner.executeCmd(Mockito.anyString())).thenReturn("mocked shell response"); Mockito.when(pcapNgHelper.isApplePcapng(Mockito.any(File.class))).thenReturn(false); Mockito.when(mockFileManager.createFile(Mockito.anyString(), Mockito.anyString())).thenReturn(backupCap); Mockito.when(mockFileManager.createFile("mypath:test")).thenReturn(tempFile); Mockito.when(mockFileManager.renameFile(Mockito.any(File.class), Mockito.anyString())).thenReturn(true); Mockito.when(file.getAbsolutePath()).thenReturn("mypath:test"); Mockito.when(tempFile.getAbsolutePath()).thenReturn("myPath/test"); Mockito.when(tempFile.getName()).thenReturn("test"); Mockito.when(tempFile.delete()).thenReturn(true); Mockito.when(tempFile.exists()).thenReturn(true); Mockito.when(backupCap.getAbsolutePath()).thenReturn("myPath/test2"); Mockito.when(backupCap.getName()).thenReturn("test2"); Mockito.when(backupCap.delete()).thenReturn(true); Mockito.when(backupCap.exists()).thenReturn(false); reader.readPacket(file.getAbsolutePath(), new IPacketListener() { @Override public void packetArrived(String appName, Packet packet) { tPacket = packet; } }); String nativeLibname = reader.getAroJpcapLibFileName(); byte[] data = new byte[20]; reader.receive(12, 1, 2, 3, data); assertNotEquals(tPacket, null); assertEquals(tPacket.getMicroSeconds(), 2L); assertNotEquals(nativeLibname, null); }
@Override public void readPacket(String packetfile, IPacketListener listener) throws IOException { if (aroJpcapLibName == null || aroWebPLibName==null) { setVOLibName(); } currentPacketfile = packetfile; provisionalPcapConversion(packetfile); if (listener == null) { LOGGER.error("PacketListener cannot be null"); throw new IllegalArgumentException("PacketListener cannot be null"); } this.packetlistener = listener; if (adapter == null) { adapter = new PCapAdapter(); adapter.loadAroLib(aroWebPLibFileName, aroWebPLibName); adapter.loadAroLib(aroJpcapLibFileName, aroJpcapLibName); } adapter.setSubscriber(this); String result = adapter.readData(packetfile); if (result != null) { LOGGER.debug("Result from executing all pcap packets: " + result); throw new IOException(result); } LOGGER.debug("Created PCapAdapter"); }
PacketReaderImpl implements IPacketReader, INativePacketSubscriber { @Override public void readPacket(String packetfile, IPacketListener listener) throws IOException { if (aroJpcapLibName == null || aroWebPLibName==null) { setVOLibName(); } currentPacketfile = packetfile; provisionalPcapConversion(packetfile); if (listener == null) { LOGGER.error("PacketListener cannot be null"); throw new IllegalArgumentException("PacketListener cannot be null"); } this.packetlistener = listener; if (adapter == null) { adapter = new PCapAdapter(); adapter.loadAroLib(aroWebPLibFileName, aroWebPLibName); adapter.loadAroLib(aroJpcapLibFileName, aroJpcapLibName); } adapter.setSubscriber(this); String result = adapter.readData(packetfile); if (result != null) { LOGGER.debug("Result from executing all pcap packets: " + result); throw new IOException(result); } LOGGER.debug("Created PCapAdapter"); } }
PacketReaderImpl implements IPacketReader, INativePacketSubscriber { @Override public void readPacket(String packetfile, IPacketListener listener) throws IOException { if (aroJpcapLibName == null || aroWebPLibName==null) { setVOLibName(); } currentPacketfile = packetfile; provisionalPcapConversion(packetfile); if (listener == null) { LOGGER.error("PacketListener cannot be null"); throw new IllegalArgumentException("PacketListener cannot be null"); } this.packetlistener = listener; if (adapter == null) { adapter = new PCapAdapter(); adapter.loadAroLib(aroWebPLibFileName, aroWebPLibName); adapter.loadAroLib(aroJpcapLibFileName, aroJpcapLibName); } adapter.setSubscriber(this); String result = adapter.readData(packetfile); if (result != null) { LOGGER.debug("Result from executing all pcap packets: " + result); throw new IOException(result); } LOGGER.debug("Created PCapAdapter"); } PacketReaderImpl(); }
PacketReaderImpl implements IPacketReader, INativePacketSubscriber { @Override public void readPacket(String packetfile, IPacketListener listener) throws IOException { if (aroJpcapLibName == null || aroWebPLibName==null) { setVOLibName(); } currentPacketfile = packetfile; provisionalPcapConversion(packetfile); if (listener == null) { LOGGER.error("PacketListener cannot be null"); throw new IllegalArgumentException("PacketListener cannot be null"); } this.packetlistener = listener; if (adapter == null) { adapter = new PCapAdapter(); adapter.loadAroLib(aroWebPLibFileName, aroWebPLibName); adapter.loadAroLib(aroJpcapLibFileName, aroJpcapLibName); } adapter.setSubscriber(this); String result = adapter.readData(packetfile); if (result != null) { LOGGER.debug("Result from executing all pcap packets: " + result); throw new IOException(result); } LOGGER.debug("Created PCapAdapter"); } PacketReaderImpl(); void setAdapter(PCapAdapter adapter); @Override void readPacket(String packetfile, IPacketListener listener); void setVOLibName(); void setAroJpcapLibName(String osname, String osarch); String getAroJpcapLibFileName(); String getAroWebPLibName(); void setAroWebPLib(String osname, String osarch); String getAroWebPLibFileName(); @Override void receive(int datalink, long seconds, long microSeconds, int len, byte[] data); }
PacketReaderImpl implements IPacketReader, INativePacketSubscriber { @Override public void readPacket(String packetfile, IPacketListener listener) throws IOException { if (aroJpcapLibName == null || aroWebPLibName==null) { setVOLibName(); } currentPacketfile = packetfile; provisionalPcapConversion(packetfile); if (listener == null) { LOGGER.error("PacketListener cannot be null"); throw new IllegalArgumentException("PacketListener cannot be null"); } this.packetlistener = listener; if (adapter == null) { adapter = new PCapAdapter(); adapter.loadAroLib(aroWebPLibFileName, aroWebPLibName); adapter.loadAroLib(aroJpcapLibFileName, aroJpcapLibName); } adapter.setSubscriber(this); String result = adapter.readData(packetfile); if (result != null) { LOGGER.debug("Result from executing all pcap packets: " + result); throw new IOException(result); } LOGGER.debug("Created PCapAdapter"); } PacketReaderImpl(); void setAdapter(PCapAdapter adapter); @Override void readPacket(String packetfile, IPacketListener listener); void setVOLibName(); void setAroJpcapLibName(String osname, String osarch); String getAroJpcapLibFileName(); String getAroWebPLibName(); void setAroWebPLib(String osname, String osarch); String getAroWebPLibFileName(); @Override void receive(int datalink, long seconds, long microSeconds, int len, byte[] data); public String windowsOS; public String windowsExtn; public String linuxOS; }