Search in sources :

Example 1 with AppInfo

use of com.att.aro.core.peripheral.pojo.AppInfo in project VideoOptimzer by attdevsupport.

the class AppInfoReaderImpl method readData.

@Override
public AppInfo readData(String directory) {
    AppInfo app = new AppInfo();
    String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.APPNAME_FILE;
    if (!filereader.fileExist(filepath)) {
        LOGGER.warn("Application info file does not exists.");
        return app;
    }
    String[] lines = null;
    try {
        lines = filereader.readAllLine(filepath);
    } catch (IOException e) {
        LOGGER.error("failed to open appname file: " + filepath);
    }
    if (lines != null && lines.length > 0) {
        for (String line : lines) {
            String[] strFields;
            String appName;
            String appVer = "n/a";
            if (line.charAt(0) == '"') {
                // Application name is surrounded by double quotes
                strFields = line.split("\"");
                appName = strFields[1];
                if (strFields.length > 2) {
                    appVer = strFields[2];
                    app.getAppVersionMap().put(appName, appVer);
                }
            } else {
                // Application name is surrounded by spaces
                strFields = line.split(" ");
                appName = strFields[0];
                if (strFields.length > 1) {
                    appVer = strFields[1];
                    app.getAppVersionMap().put(appName, appVer);
                }
            }
            app.getAppInfos().add(appName);
        }
    }
    return app;
}
Also used : IOException(java.io.IOException) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo)

Example 2 with AppInfo

use of com.att.aro.core.peripheral.pojo.AppInfo in project VideoOptimzer by attdevsupport.

the class AppInfoReaderImplTest method readDataIoException.

@Test
public void readDataIoException() throws IOException {
    Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("test exception"));
    AppInfo info = null;
    info = reader.readData("/");
    assertTrue(info.getAppInfos().size() == 0);
}
Also used : IOException(java.io.IOException) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 3 with AppInfo

use of com.att.aro.core.peripheral.pojo.AppInfo in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImpl method readTraceDirectory.

/**
 * read all kind of trace file in a directory
 *
 * @param directoryPath
 *            full path to physical directory
 * @throws FileNotFoundException
 */
public TraceDirectoryResult readTraceDirectory(String directoryPath) throws FileNotFoundException {
    if (!filereader.directoryExist(directoryPath)) {
        throw new FileNotFoundException("Not found directory: " + directoryPath);
    }
    TraceDirectoryResult result = new TraceDirectoryResult();
    result.setTraceDirectory(directoryPath);
    // readAppInfo(result);
    AppInfo app = appinforeader.readData(result.getTraceDirectory());
    result.setAppVersionMap(app.getAppVersionMap());
    result.setAppInfos(app.getAppInfos());
    // Read the time file and PCAP trace
    try {
        result = readTimeAndPcap(result);
    } catch (IOException e1) {
        LOGGER.error("Failed to read file", e1);
        // no need to continue, everything else is useless without packet data
        return null;
    }
    if (result == null) {
        return null;
    }
    readDeviceDetails(result);
    // merge several methods to one method
    readFileUtil(result);
    readAlarmDumpsysTimestamp(result);
    try {
        readAlarmAnalysisInfo(result);
    } catch (IOException e) {
        LOGGER.info("*** Warning: no alarm dumpsys information found ***");
    }
    readWakelockInfo(result);
    readVideoTime(result);
    readSSLKeys(result);
    readPrivateData(result);
    readAttenuationEvent(result);
    readThrottleEvent(result);
    return result;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) IOException(java.io.IOException) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo)

Example 4 with AppInfo

use of com.att.aro.core.peripheral.pojo.AppInfo in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImplTest method readTraceDir_.

@Test
public void readTraceDir_() throws IOException {
    String[] time = { "1410212153 1410213352", "272927100", "1410213352.550" };
    String[] appId = { "5", "5", "13", "-127" };
    traceDataReaderImpl.setFileReader(filereader);
    when(filereader.directoryExist(any(String.class))).thenReturn(true);
    when(filereader.fileExist(any(String.class))).thenReturn(true);
    when(filereader.readAllLine(any(String.class))).thenReturn(time);
    when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "appid")).thenReturn(appId);
    when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
    Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
    List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
    AlarmAnalysisResult alarmResult = mock(AlarmAnalysisResult.class);
    when(alarmResult.getScheduledAlarms()).thenReturn(scheduledAlarms);
    when(alarmResult.getStatistics()).thenReturn(statistics);
    when(alarmanalysisinfoparser.parse(any(String.class), any(String.class), any(String.class), any(double.class), any(double.class), any(Date.class))).thenReturn(alarmResult);
    // Crypto
    traceDataReaderImpl.setCrypto(crypto);
    when(crypto.readSSLKeys(any(String.class))).thenReturn(1);
    Mockito.doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            byte b = 3;
            short s = 1;
            InetAddress address1 = null;
            InetAddress address2 = null;
            try {
                address2 = InetAddress.getByName("78.46.84.177");
                address1 = InetAddress.getByName("78.46.84.171");
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            Date date1 = new Date();
            IPPacket ippack01 = mock(IPPacket.class);
            when(ippack01.getIPVersion()).thenReturn(b);
            when(ippack01.getFragmentOffset()).thenReturn(s);
            when(ippack01.getSourceIPAddress()).thenReturn(address1);
            when(ippack01.getDestinationIPAddress()).thenReturn(address2);
            when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
            // pretend jpcap lib
            traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
            return null;
        }
    }).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
    AppInfo app = new AppInfo();
    Map<String, String> appMap = new HashMap<String, String>();
    appMap.put("flipboard.app", "2.3.8");
    appMap.put("com.att.android.arodatacollector", "3.1.1.6");
    appMap.put("com.google.android.youtube", "4.0.23");
    app.setAppVersionMap(appMap);
    List<String> appInfos = new ArrayList<String>();
    appInfos.add("flipboard.app");
    appInfos.add("com.att.android.arodatacollector");
    appInfos.add("com.google.android.youtube");
    app.setAppInfos(appInfos);
    when(appinforeader.readData(any(String.class))).thenReturn(app);
    DeviceDetail device = new DeviceDetail();
    device.setTotalLines(8);
    device.setScreenSize("720*1280");
    when(devicedetailreader.readData(any(String.class))).thenReturn(device);
    CollectOptions cOptions = new CollectOptions();
    when(collectOptionsReader.readData(any(String.class))).thenReturn(cOptions);
    NetworkTypeObject obj = new NetworkTypeObject();
    when(networktypereader.readData(any(String.class), any(double.class), any(double.class))).thenReturn(obj);
    TraceDirectoryResult result = traceDataReaderImpl.readTraceDirectory(Util.getCurrentRunningDir());
    assertSame(3, result.getAppIds().size());
}
Also used : NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) ArrayList(java.util.ArrayList) List(java.util.List) UnknownHostException(java.net.UnknownHostException) IPacketListener(com.att.aro.core.packetreader.IPacketListener) DeviceDetail(com.att.aro.core.peripheral.pojo.DeviceDetail) ScheduledAlarmInfo(com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo) Date(java.util.Date) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo) CollectOptions(com.att.aro.core.peripheral.pojo.CollectOptions) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) InetAddress(java.net.InetAddress) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Example 5 with AppInfo

use of com.att.aro.core.peripheral.pojo.AppInfo in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImplTest method readTraceDir_checkExternalVideoAndTime.

@Test
public void readTraceDir_checkExternalVideoAndTime() throws IOException {
    String[] time = { "1410212153.578 1410213352.550", "272927100", "1410213352.550" };
    String[] appId = {};
    traceDataReaderImpl.setFileReader(filereader);
    when(filereader.directoryExist(any(String.class))).thenReturn(true);
    when(filereader.readAllLine(any(String.class))).thenReturn(time);
    when(filereader.readAllLine(any(String.class))).thenReturn(appId);
    when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "exVideo_time")).thenReturn(time);
    when(filereader.fileExist(any(String.class))).thenReturn(true);
    when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
    when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "time")).thenReturn(false);
    Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
    List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
    AlarmAnalysisResult alarmResult = mock(AlarmAnalysisResult.class);
    when(alarmResult.getScheduledAlarms()).thenReturn(scheduledAlarms);
    when(alarmResult.getStatistics()).thenReturn(statistics);
    when(alarmanalysisinfoparser.parse(any(String.class), any(String.class), any(String.class), any(double.class), any(double.class), any(Date.class))).thenReturn(alarmResult);
    Mockito.doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            byte b = 3;
            short s = 1;
            InetAddress address1 = null;
            InetAddress address2 = null;
            try {
                address2 = InetAddress.getByName("78.46.84.177");
                address1 = InetAddress.getByName("78.46.84.171");
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            Date date1 = new Date();
            IPPacket ippack01 = mock(IPPacket.class);
            when(ippack01.getIPVersion()).thenReturn(b);
            when(ippack01.getFragmentOffset()).thenReturn(s);
            when(ippack01.getSourceIPAddress()).thenReturn(address1);
            when(ippack01.getDestinationIPAddress()).thenReturn(address2);
            when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
            // pretend jpcap lib
            traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
            return null;
        }
    }).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
    AppInfo app = new AppInfo();
    Map<String, String> appMap = new HashMap<String, String>();
    appMap.put("flipboard.app", "2.3.8");
    appMap.put("com.att.android.arodatacollector", "3.1.1.6");
    appMap.put("com.google.android.youtube", "4.0.23");
    app.setAppVersionMap(appMap);
    List<String> appInfos = new ArrayList<String>();
    appInfos.add("flipboard.app");
    appInfos.add("com.att.android.arodatacollector");
    appInfos.add("com.google.android.youtube");
    app.setAppInfos(appInfos);
    when(appinforeader.readData(any(String.class))).thenReturn(app);
    DeviceDetail device = new DeviceDetail();
    when(devicedetailreader.readData(any(String.class))).thenReturn(device);
    NetworkTypeObject obj = new NetworkTypeObject();
    when(networktypereader.readData(any(String.class), any(double.class), any(double.class))).thenReturn(obj);
    TraceDirectoryResult result = traceDataReaderImpl.readTraceDirectory(Util.getCurrentRunningDir());
    assertSame(0, result.getAppIds().size());
}
Also used : NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) IPacketListener(com.att.aro.core.packetreader.IPacketListener) ArrayList(java.util.ArrayList) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) DeviceDetail(com.att.aro.core.peripheral.pojo.DeviceDetail) ScheduledAlarmInfo(com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo) Date(java.util.Date) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo) AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) ArrayList(java.util.ArrayList) List(java.util.List) NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) InetAddress(java.net.InetAddress) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Aggregations

AppInfo (com.att.aro.core.peripheral.pojo.AppInfo)7 BaseTest (com.att.aro.core.BaseTest)5 Test (org.junit.Test)5 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)3 IOException (java.io.IOException)3 ScheduledAlarmInfo (com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo)2 IPacketListener (com.att.aro.core.packetreader.IPacketListener)2 IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)2 AlarmAnalysisInfo (com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo)2 AlarmAnalysisResult (com.att.aro.core.peripheral.pojo.AlarmAnalysisResult)2 DeviceDetail (com.att.aro.core.peripheral.pojo.DeviceDetail)2 NetworkTypeObject (com.att.aro.core.peripheral.pojo.NetworkTypeObject)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 CollectOptions (com.att.aro.core.peripheral.pojo.CollectOptions)1