@Test public void runTest_resIsNoErrResultTypeIsPass(){ Mockito.when(pktInfo01.getTimeStamp()).thenReturn(1.0); Mockito.when(pktInfo02.getTimeStamp()).thenReturn(2.0); httpRequestInfo01 = Mockito.mock(HttpRequestResponseInfo.class); Mockito.when(httpRequestInfo01.getDirection()).thenReturn(HttpDirection.REQUEST); Mockito.when(httpRequestInfo01.getFirstDataPacket()).thenReturn(pktInfo01); List<HttpRequestResponseInfo> value = new ArrayList<HttpRequestResponseInfo>(); value.add(httpRequestInfo01); Mockito.when(session01.getRequestResponseInfo()).thenReturn(value); Mockito.when(session02.getRequestResponseInfo()).thenReturn(value); List<Session> sessionList = new ArrayList<Session>(); sessionList.add(session01); sessionList.add(session02); Mockito.when(tracedata.getSessionlist()).thenReturn(sessionList); csjsImpl = (CombineCsJssImpl) context.getBean("combineCsJss"); AbstractBestPracticeResult result = csjsImpl.runTest(tracedata); assertEquals(BPResultType.PASS,result.getResultType() ); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CombineCsJssResult result = new CombineCsJssResult(); List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>(); int inefficientCssRequests = 0; PacketInfo consecutiveCssJsFirstPacket = null; int inefficientJsRequests = 0; double cssLastTimeStamp = 0.0; double jsLastTimeStamp = 0.0; String contentType = ""; for(Session session: tracedata.getSessionlist()){ HttpRequestResponseInfo lastRequestObj = null; for(HttpRequestResponseInfo httpreq: session.getRequestResponseInfo()){ if(httpreq.getDirection() == HttpDirection.REQUEST){ lastRequestObj = httpreq; } if(httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null){ PacketInfo pktInfo = httpreq.getFirstDataPacket(); if(pktInfo != null){ contentType = httpreq.getContentType().toLowerCase().trim(); if(contentType.equalsIgnoreCase("text/css")){ if (cssLastTimeStamp == 0.0) { cssLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) { inefficientCssRequests++; CsJssFilesDetails cssFileDetails = new CsJssFilesDetails(); cssFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ cssFileDetails.setFileName(httpreq.getObjName()); } else { if(lastRequestObj != null){ cssFileDetails.setFileName(lastRequestObj.getObjName()); } } cssFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(cssFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } cssLastTimeStamp = pktInfo.getTimeStamp(); } }else if(contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")){ if (jsLastTimeStamp == 0.0) { jsLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) { inefficientJsRequests++; CsJssFilesDetails jsFileDetails = new CsJssFilesDetails(); jsFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ jsFileDetails.setFileName(httpreq.getObjName()); } else{ if(lastRequestObj != null){ jsFileDetails.setFileName(lastRequestObj.getObjName()); } } jsFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(jsFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } jsLastTimeStamp = pktInfo.getTimeStamp(); } } } } } } result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket); result.setInefficientCssRequests(inefficientCssRequests); result.setInefficientJsRequests(inefficientJsRequests); if(inefficientCssRequests < 1 && inefficientJsRequests < 1){ result.setResultType(BPResultType.PASS); result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName())); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(textResults); result.setFilesDetails(fileDetails); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest); result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest); return result; }
CombineCsJssImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CombineCsJssResult result = new CombineCsJssResult(); List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>(); int inefficientCssRequests = 0; PacketInfo consecutiveCssJsFirstPacket = null; int inefficientJsRequests = 0; double cssLastTimeStamp = 0.0; double jsLastTimeStamp = 0.0; String contentType = ""; for(Session session: tracedata.getSessionlist()){ HttpRequestResponseInfo lastRequestObj = null; for(HttpRequestResponseInfo httpreq: session.getRequestResponseInfo()){ if(httpreq.getDirection() == HttpDirection.REQUEST){ lastRequestObj = httpreq; } if(httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null){ PacketInfo pktInfo = httpreq.getFirstDataPacket(); if(pktInfo != null){ contentType = httpreq.getContentType().toLowerCase().trim(); if(contentType.equalsIgnoreCase("text/css")){ if (cssLastTimeStamp == 0.0) { cssLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) { inefficientCssRequests++; CsJssFilesDetails cssFileDetails = new CsJssFilesDetails(); cssFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ cssFileDetails.setFileName(httpreq.getObjName()); } else { if(lastRequestObj != null){ cssFileDetails.setFileName(lastRequestObj.getObjName()); } } cssFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(cssFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } cssLastTimeStamp = pktInfo.getTimeStamp(); } }else if(contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")){ if (jsLastTimeStamp == 0.0) { jsLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) { inefficientJsRequests++; CsJssFilesDetails jsFileDetails = new CsJssFilesDetails(); jsFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ jsFileDetails.setFileName(httpreq.getObjName()); } else{ if(lastRequestObj != null){ jsFileDetails.setFileName(lastRequestObj.getObjName()); } } jsFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(jsFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } jsLastTimeStamp = pktInfo.getTimeStamp(); } } } } } } result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket); result.setInefficientCssRequests(inefficientCssRequests); result.setInefficientJsRequests(inefficientJsRequests); if(inefficientCssRequests < 1 && inefficientJsRequests < 1){ result.setResultType(BPResultType.PASS); result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName())); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(textResults); result.setFilesDetails(fileDetails); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest); result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest); return result; } }
CombineCsJssImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CombineCsJssResult result = new CombineCsJssResult(); List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>(); int inefficientCssRequests = 0; PacketInfo consecutiveCssJsFirstPacket = null; int inefficientJsRequests = 0; double cssLastTimeStamp = 0.0; double jsLastTimeStamp = 0.0; String contentType = ""; for(Session session: tracedata.getSessionlist()){ HttpRequestResponseInfo lastRequestObj = null; for(HttpRequestResponseInfo httpreq: session.getRequestResponseInfo()){ if(httpreq.getDirection() == HttpDirection.REQUEST){ lastRequestObj = httpreq; } if(httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null){ PacketInfo pktInfo = httpreq.getFirstDataPacket(); if(pktInfo != null){ contentType = httpreq.getContentType().toLowerCase().trim(); if(contentType.equalsIgnoreCase("text/css")){ if (cssLastTimeStamp == 0.0) { cssLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) { inefficientCssRequests++; CsJssFilesDetails cssFileDetails = new CsJssFilesDetails(); cssFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ cssFileDetails.setFileName(httpreq.getObjName()); } else { if(lastRequestObj != null){ cssFileDetails.setFileName(lastRequestObj.getObjName()); } } cssFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(cssFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } cssLastTimeStamp = pktInfo.getTimeStamp(); } }else if(contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")){ if (jsLastTimeStamp == 0.0) { jsLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) { inefficientJsRequests++; CsJssFilesDetails jsFileDetails = new CsJssFilesDetails(); jsFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ jsFileDetails.setFileName(httpreq.getObjName()); } else{ if(lastRequestObj != null){ jsFileDetails.setFileName(lastRequestObj.getObjName()); } } jsFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(jsFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } jsLastTimeStamp = pktInfo.getTimeStamp(); } } } } } } result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket); result.setInefficientCssRequests(inefficientCssRequests); result.setInefficientJsRequests(inefficientJsRequests); if(inefficientCssRequests < 1 && inefficientJsRequests < 1){ result.setResultType(BPResultType.PASS); result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName())); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(textResults); result.setFilesDetails(fileDetails); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest); result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest); return result; }  }
CombineCsJssImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CombineCsJssResult result = new CombineCsJssResult(); List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>(); int inefficientCssRequests = 0; PacketInfo consecutiveCssJsFirstPacket = null; int inefficientJsRequests = 0; double cssLastTimeStamp = 0.0; double jsLastTimeStamp = 0.0; String contentType = ""; for(Session session: tracedata.getSessionlist()){ HttpRequestResponseInfo lastRequestObj = null; for(HttpRequestResponseInfo httpreq: session.getRequestResponseInfo()){ if(httpreq.getDirection() == HttpDirection.REQUEST){ lastRequestObj = httpreq; } if(httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null){ PacketInfo pktInfo = httpreq.getFirstDataPacket(); if(pktInfo != null){ contentType = httpreq.getContentType().toLowerCase().trim(); if(contentType.equalsIgnoreCase("text/css")){ if (cssLastTimeStamp == 0.0) { cssLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) { inefficientCssRequests++; CsJssFilesDetails cssFileDetails = new CsJssFilesDetails(); cssFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ cssFileDetails.setFileName(httpreq.getObjName()); } else { if(lastRequestObj != null){ cssFileDetails.setFileName(lastRequestObj.getObjName()); } } cssFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(cssFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } cssLastTimeStamp = pktInfo.getTimeStamp(); } }else if(contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")){ if (jsLastTimeStamp == 0.0) { jsLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) { inefficientJsRequests++; CsJssFilesDetails jsFileDetails = new CsJssFilesDetails(); jsFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ jsFileDetails.setFileName(httpreq.getObjName()); } else{ if(lastRequestObj != null){ jsFileDetails.setFileName(lastRequestObj.getObjName()); } } jsFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(jsFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } jsLastTimeStamp = pktInfo.getTimeStamp(); } } } } } } result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket); result.setInefficientCssRequests(inefficientCssRequests); result.setInefficientJsRequests(inefficientJsRequests); if(inefficientCssRequests < 1 && inefficientJsRequests < 1){ result.setResultType(BPResultType.PASS); result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName())); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(textResults); result.setFilesDetails(fileDetails); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest); result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
CombineCsJssImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CombineCsJssResult result = new CombineCsJssResult(); List<CsJssFilesDetails> fileDetails = new ArrayList<CsJssFilesDetails>(); int inefficientCssRequests = 0; PacketInfo consecutiveCssJsFirstPacket = null; int inefficientJsRequests = 0; double cssLastTimeStamp = 0.0; double jsLastTimeStamp = 0.0; String contentType = ""; for(Session session: tracedata.getSessionlist()){ HttpRequestResponseInfo lastRequestObj = null; for(HttpRequestResponseInfo httpreq: session.getRequestResponseInfo()){ if(httpreq.getDirection() == HttpDirection.REQUEST){ lastRequestObj = httpreq; } if(httpreq.getDirection() == HttpDirection.RESPONSE && httpreq.getContentType() != null){ PacketInfo pktInfo = httpreq.getFirstDataPacket(); if(pktInfo != null){ contentType = httpreq.getContentType().toLowerCase().trim(); if(contentType.equalsIgnoreCase("text/css")){ if (cssLastTimeStamp == 0.0) { cssLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - cssLastTimeStamp) <= 2.0) { inefficientCssRequests++; CsJssFilesDetails cssFileDetails = new CsJssFilesDetails(); cssFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ cssFileDetails.setFileName(httpreq.getObjName()); } else { if(lastRequestObj != null){ cssFileDetails.setFileName(lastRequestObj.getObjName()); } } cssFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(cssFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } cssLastTimeStamp = pktInfo.getTimeStamp(); } }else if(contentType.equalsIgnoreCase("text/javascript") || contentType.equalsIgnoreCase("application/x-javascript") || contentType.equalsIgnoreCase("application/javascript")){ if (jsLastTimeStamp == 0.0) { jsLastTimeStamp = pktInfo.getTimeStamp(); continue; } else { if ((pktInfo.getTimeStamp() - jsLastTimeStamp) < 2.0) { inefficientJsRequests++; CsJssFilesDetails jsFileDetails = new CsJssFilesDetails(); jsFileDetails.setTimeStamp(pktInfo.getTimeStamp()); if(httpreq.getObjName() != null){ jsFileDetails.setFileName(httpreq.getObjName()); } else{ if(lastRequestObj != null){ jsFileDetails.setFileName(lastRequestObj.getObjName()); } } jsFileDetails.setSize(httpreq.getContentLength()); fileDetails.add(jsFileDetails); if (consecutiveCssJsFirstPacket == null) { consecutiveCssJsFirstPacket = pktInfo; } } jsLastTimeStamp = pktInfo.getTimeStamp(); } } } } } } result.setConsecutiveCssJsFirstPacket(consecutiveCssJsFirstPacket); result.setInefficientCssRequests(inefficientCssRequests); result.setInefficientJsRequests(inefficientJsRequests); if(inefficientCssRequests < 1 && inefficientJsRequests < 1){ result.setResultType(BPResultType.PASS); result.setResultText(MessageFormat.format(textResultPass, ApplicationConfig.getInstance().getAppShortName())); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(textResults); result.setFilesDetails(fileDetails); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllInefficientCssRequest(exportAllInefficientCssRequest); result.setExportAllInefficientJsRequest(exportAllInefficientJsRequest); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }