@Test public void runTest_resTypeIsFail() { List<CacheEntry> diagnosisResults = new ArrayList<CacheEntry>(); Mockito.when(entryArray[0].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP); Mockito.when(entryArray[1].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT); Mockito.when(entryArray[2].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304); Mockito.when(entryArray[3].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT); Mockito.when(entryArray[4].getDiagnosis()).thenReturn(Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304); for (int i = 0; i < 5; i++) { diagnosisResults.add(entryArray[i]); } Mockito.when(cacheAnalysis.getDiagnosisResults()).thenReturn(diagnosisResults); Mockito.when(tracedata.getCacheAnalysis()).thenReturn(cacheAnalysis); cacheControlImpl = (CacheControlImpl) context.getBean("cacheControl"); AbstractBestPracticeResult testResult = cacheControlImpl.runTest(tracedata); assertEquals(BPResultType.WARNING, testResult.getResultType()); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CacheControlResult result = new CacheControlResult(); if(tracedata.getCacheAnalysis() == null){ return null; } int hitNotExpiredDup = 0; int hitExpired304 = 0; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT){ hitNotExpiredDup++; }else if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304){ hitExpired304++; } } boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true); if(cacheControl){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, hitNotExpiredDup,hitExpired304); result.setResultText(text); } result.setHitExpired304Count(hitExpired304); result.setHitNotExpiredDupCount(hitNotExpiredDup); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc); result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc); return result; }
CacheControlImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CacheControlResult result = new CacheControlResult(); if(tracedata.getCacheAnalysis() == null){ return null; } int hitNotExpiredDup = 0; int hitExpired304 = 0; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT){ hitNotExpiredDup++; }else if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304){ hitExpired304++; } } boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true); if(cacheControl){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, hitNotExpiredDup,hitExpired304); result.setResultText(text); } result.setHitExpired304Count(hitExpired304); result.setHitNotExpiredDupCount(hitNotExpiredDup); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc); result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc); return result; } }
CacheControlImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CacheControlResult result = new CacheControlResult(); if(tracedata.getCacheAnalysis() == null){ return null; } int hitNotExpiredDup = 0; int hitExpired304 = 0; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT){ hitNotExpiredDup++; }else if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304){ hitExpired304++; } } boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true); if(cacheControl){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, hitNotExpiredDup,hitExpired304); result.setResultText(text); } result.setHitExpired304Count(hitExpired304); result.setHitNotExpiredDupCount(hitNotExpiredDup); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc); result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc); return result; }  }
CacheControlImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CacheControlResult result = new CacheControlResult(); if(tracedata.getCacheAnalysis() == null){ return null; } int hitNotExpiredDup = 0; int hitExpired304 = 0; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT){ hitNotExpiredDup++; }else if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304){ hitExpired304++; } } boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true); if(cacheControl){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, hitNotExpiredDup,hitExpired304); result.setResultText(text); } result.setHitExpired304Count(hitExpired304); result.setHitNotExpiredDupCount(hitNotExpiredDup); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc); result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
CacheControlImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { CacheControlResult result = new CacheControlResult(); if(tracedata.getCacheAnalysis() == null){ return null; } int hitNotExpiredDup = 0; int hitExpired304 = 0; for(CacheEntry entry: tracedata.getCacheAnalysis().getDiagnosisResults()){ if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP || entry.getDiagnosis() == Diagnosis.CACHING_DIAG_NOT_EXPIRED_DUP_PARTIALHIT){ hitNotExpiredDup++; }else if(entry.getDiagnosis() == Diagnosis.CACHING_DIAG_OBJ_NOT_CHANGED_304){ hitExpired304++; } } boolean cacheControl = (hitNotExpiredDup > hitExpired304 ? false : true); if(cacheControl){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.WARNING); String text = MessageFormat.format(textResults, hitNotExpiredDup,hitExpired304); result.setResultText(text); } result.setHitExpired304Count(hitExpired304); result.setHitNotExpiredDupCount(hitNotExpiredDup); result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllCacheCon304Desc(exportAllCacheCon304Desc); result.setExportAllCacheConNExpDesc(exportAllCacheConNExpDesc); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }