@Test public void runTest_Fail(){ List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>(); Mockito.when(entryArray[0].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_CACHABLE); Mockito.when(entryArray[0].hasCacheHeaders()).thenReturn(true); Mockito.when(entryArray[1].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_CACHE_MISSED); Mockito.when(entryArray[1].hasCacheHeaders()).thenReturn(false); Mockito.when(entryArray[1].getSessionFirstPacket()).thenReturn(pktInfo01); Mockito.when(entryArray[2].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT); Mockito.when(entryArray[2].hasCacheHeaders()).thenReturn(true); Mockito.when(entryArray[3].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP); Mockito.when(entryArray[3].hasCacheHeaders()).thenReturn(true); Mockito.when(entryArray[4].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304); Mockito.when(entryArray[4].hasCacheHeaders()).thenReturn(false); for(int i = 0; i < 5; i++){ diagnosisResults.add(entryArray[i]); } Mockito.when(cacheAnalysis.getDiagnosisResults()).thenReturn(diagnosisResults); Mockito.when(tracedata.getCacheAnalysis()).thenReturn(cacheAnalysis); AbstractBestPracticeResult testResult = usingCacheImpl.runTest(tracedata); assertEquals(BPResultType.WARNING, testResult.getResultType()); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { UsingCacheResult result = new UsingCacheResult(); if(tracedata.getCacheAnalysis() == null){ return null; } double cacheHeaderRatio = 0.0; boolean usingCache = false; int validCount = 0; int noCacheHeadersCount = 0; PacketInfo noCacheHeaderFirstPacket = null; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() != Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_REQUEST && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_RESPONSE ){ ++validCount; if (!entry.hasCacheHeaders()) { if (noCacheHeadersCount == 0) { noCacheHeaderFirstPacket = entry.getSessionFirstPacket(); } ++noCacheHeadersCount; } } } cacheHeaderRatio = validCount > 0 ? (100.0 * noCacheHeadersCount) / validCount : 0.0; usingCache = cacheHeaderRatio <= 10.0; if(usingCache){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), NumberFormat.getIntegerInstance().format(cacheHeaderRatio)); result.setResultText(text); } result.setCacheHeaderRatio(cacheHeaderRatio); result.setNoCacheHeaderFirstPacket(noCacheHeaderFirstPacket); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheConPct(exportAllCacheConPct); return result; }
UsingCacheImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { UsingCacheResult result = new UsingCacheResult(); if(tracedata.getCacheAnalysis() == null){ return null; } double cacheHeaderRatio = 0.0; boolean usingCache = false; int validCount = 0; int noCacheHeadersCount = 0; PacketInfo noCacheHeaderFirstPacket = null; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() != Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_REQUEST && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_RESPONSE ){ ++validCount; if (!entry.hasCacheHeaders()) { if (noCacheHeadersCount == 0) { noCacheHeaderFirstPacket = entry.getSessionFirstPacket(); } ++noCacheHeadersCount; } } } cacheHeaderRatio = validCount > 0 ? (100.0 * noCacheHeadersCount) / validCount : 0.0; usingCache = cacheHeaderRatio <= 10.0; if(usingCache){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), NumberFormat.getIntegerInstance().format(cacheHeaderRatio)); result.setResultText(text); } result.setCacheHeaderRatio(cacheHeaderRatio); result.setNoCacheHeaderFirstPacket(noCacheHeaderFirstPacket); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheConPct(exportAllCacheConPct); return result; } }
UsingCacheImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { UsingCacheResult result = new UsingCacheResult(); if(tracedata.getCacheAnalysis() == null){ return null; } double cacheHeaderRatio = 0.0; boolean usingCache = false; int validCount = 0; int noCacheHeadersCount = 0; PacketInfo noCacheHeaderFirstPacket = null; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() != Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_REQUEST && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_RESPONSE ){ ++validCount; if (!entry.hasCacheHeaders()) { if (noCacheHeadersCount == 0) { noCacheHeaderFirstPacket = entry.getSessionFirstPacket(); } ++noCacheHeadersCount; } } } cacheHeaderRatio = validCount > 0 ? (100.0 * noCacheHeadersCount) / validCount : 0.0; usingCache = cacheHeaderRatio <= 10.0; if(usingCache){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), NumberFormat.getIntegerInstance().format(cacheHeaderRatio)); result.setResultText(text); } result.setCacheHeaderRatio(cacheHeaderRatio); result.setNoCacheHeaderFirstPacket(noCacheHeaderFirstPacket); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheConPct(exportAllCacheConPct); return result; }  }
UsingCacheImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { UsingCacheResult result = new UsingCacheResult(); if(tracedata.getCacheAnalysis() == null){ return null; } double cacheHeaderRatio = 0.0; boolean usingCache = false; int validCount = 0; int noCacheHeadersCount = 0; PacketInfo noCacheHeaderFirstPacket = null; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() != Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_REQUEST && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_RESPONSE ){ ++validCount; if (!entry.hasCacheHeaders()) { if (noCacheHeadersCount == 0) { noCacheHeaderFirstPacket = entry.getSessionFirstPacket(); } ++noCacheHeadersCount; } } } cacheHeaderRatio = validCount > 0 ? (100.0 * noCacheHeadersCount) / validCount : 0.0; usingCache = cacheHeaderRatio <= 10.0; if(usingCache){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), NumberFormat.getIntegerInstance().format(cacheHeaderRatio)); result.setResultText(text); } result.setCacheHeaderRatio(cacheHeaderRatio); result.setNoCacheHeaderFirstPacket(noCacheHeaderFirstPacket); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheConPct(exportAllCacheConPct); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
UsingCacheImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { UsingCacheResult result = new UsingCacheResult(); if(tracedata.getCacheAnalysis() == null){ return null; } double cacheHeaderRatio = 0.0; boolean usingCache = false; int validCount = 0; int noCacheHeadersCount = 0; PacketInfo noCacheHeaderFirstPacket = null; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() != Diagnosis.CACHING_DIAG_REQUEST_NOT_FOUND && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_OBJ_NAME && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_REQUEST && entry.getDiagnosis() != Diagnosis.CACHING_DIAG_INVALID_RESPONSE ){ ++validCount; if (!entry.hasCacheHeaders()) { if (noCacheHeadersCount == 0) { noCacheHeaderFirstPacket = entry.getSessionFirstPacket(); } ++noCacheHeadersCount; } } } cacheHeaderRatio = validCount > 0 ? (100.0 * noCacheHeadersCount) / validCount : 0.0; usingCache = cacheHeaderRatio <= 10.0; if(usingCache){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), NumberFormat.getIntegerInstance().format(cacheHeaderRatio)); result.setResultText(text); } result.setCacheHeaderRatio(cacheHeaderRatio); result.setNoCacheHeaderFirstPacket(noCacheHeaderFirstPacket); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheConPct(exportAllCacheConPct); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }