@Test public void runTest_resTypeIsFail(){ Mockito.when(httpRequestInfo01.getDirection()).thenReturn(HttpDirection.RESPONSE); Mockito.when(httpRequestInfo01.getScheme()).thenReturn(HttpRequestResponseInfo.HTTP_SCHEME); Mockito.when(httpRequestInfo01.getStatusCode()).thenReturn(404); Mockito.when(httpRequestInfo01.getObjName()).thenReturn(""); Mockito.when(httpRequestInfo02.getDirection()).thenReturn(HttpDirection.REQUEST); Mockito.when(httpRequestInfo02.getObjName()).thenReturn(""); Mockito.when(httpRequestInfo03.getDirection()).thenReturn(HttpDirection.RESPONSE); Mockito.when(httpRequestInfo03.getScheme()).thenReturn(HttpRequestResponseInfo.HTTP_SCHEME); Mockito.when(httpRequestInfo03.getStatusCode()).thenReturn(505); Mockito.when(httpRequestInfo03.getObjName()).thenReturn(""); Mockito.when(httpRequestInfo04.getDirection()).thenReturn(HttpDirection.REQUEST); Mockito.when(httpRequestInfo04.getObjName()).thenReturn(""); List<HttpRequestResponseInfo> value = new ArrayList<HttpRequestResponseInfo>(); value.add(httpRequestInfo01); value.add(httpRequestInfo02); value.add(httpRequestInfo03); value.add(httpRequestInfo04); value.add(httpRequestInfo03); Mockito.when(session01.getRequestResponseInfo()).thenReturn(value); Mockito.when(session01.getDomainName()).thenReturn("www.google.com"); List<Session> sessionList = new ArrayList<Session>(); sessionList.add(session01); Mockito.when(tracedata.getSessionlist()).thenReturn(sessionList); http4xx5xxImpl = (Http4xx5xxImpl) context.getBean("http4xx5xx"); AbstractBestPracticeResult result = http4xx5xxImpl.runTest(tracedata); assertEquals(BPResultType.FAIL,result.getResultType() ); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { Http4xx5xxResult result = new Http4xx5xxResult(); Map<Integer, HttpRequestResponseInfo> firstErrorRespMap4XX = new HashMap<Integer, HttpRequestResponseInfo>(); SortedMap<Integer, Integer> httpErrorCounts4XX = new TreeMap<Integer, Integer>(); List<Http4xx5xxStatusResponseCodesEntry> httpResCodelist = new ArrayList<Http4xx5xxStatusResponseCodesEntry>(); HttpRequestResponseInfo lastRequestObj = null; for(Session session: tracedata.getSessionlist()){ lastRequestObj = null; for(HttpRequestResponseInfo req: session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.REQUEST){ lastRequestObj = req; } if(req.getDirection() == HttpDirection.RESPONSE && HttpRequestResponseInfo.HTTP_SCHEME.equals(req.getScheme()) && req.getStatusCode() >= 400 && req.getStatusCode() < 600){ Integer code = req.getStatusCode(); Integer count = httpErrorCounts4XX.get(code); if(count != null){ httpErrorCounts4XX.put(code, count + 1); }else{ httpErrorCounts4XX.put(code, 1); firstErrorRespMap4XX.put(code, req); } httpResCodelist.add(new Http4xx5xxStatusResponseCodesEntry(req, lastRequestObj, session.getDomainName())); } } } if(httpErrorCounts4XX.isEmpty()){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(Http3xx4xxHelper.createFailResult(httpErrorCounts4XX, textResults, errorPlural, errorSingular)); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllHttpError(exportAllHttpError); result.setFirstErrorRespMap4XX(firstErrorRespMap4XX); result.setHttpErrorCounts4XX(httpErrorCounts4XX); result.setHttpResCodelist(httpResCodelist); return result; }
Http4xx5xxImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { Http4xx5xxResult result = new Http4xx5xxResult(); Map<Integer, HttpRequestResponseInfo> firstErrorRespMap4XX = new HashMap<Integer, HttpRequestResponseInfo>(); SortedMap<Integer, Integer> httpErrorCounts4XX = new TreeMap<Integer, Integer>(); List<Http4xx5xxStatusResponseCodesEntry> httpResCodelist = new ArrayList<Http4xx5xxStatusResponseCodesEntry>(); HttpRequestResponseInfo lastRequestObj = null; for(Session session: tracedata.getSessionlist()){ lastRequestObj = null; for(HttpRequestResponseInfo req: session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.REQUEST){ lastRequestObj = req; } if(req.getDirection() == HttpDirection.RESPONSE && HttpRequestResponseInfo.HTTP_SCHEME.equals(req.getScheme()) && req.getStatusCode() >= 400 && req.getStatusCode() < 600){ Integer code = req.getStatusCode(); Integer count = httpErrorCounts4XX.get(code); if(count != null){ httpErrorCounts4XX.put(code, count + 1); }else{ httpErrorCounts4XX.put(code, 1); firstErrorRespMap4XX.put(code, req); } httpResCodelist.add(new Http4xx5xxStatusResponseCodesEntry(req, lastRequestObj, session.getDomainName())); } } } if(httpErrorCounts4XX.isEmpty()){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(Http3xx4xxHelper.createFailResult(httpErrorCounts4XX, textResults, errorPlural, errorSingular)); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllHttpError(exportAllHttpError); result.setFirstErrorRespMap4XX(firstErrorRespMap4XX); result.setHttpErrorCounts4XX(httpErrorCounts4XX); result.setHttpResCodelist(httpResCodelist); return result; } }
Http4xx5xxImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { Http4xx5xxResult result = new Http4xx5xxResult(); Map<Integer, HttpRequestResponseInfo> firstErrorRespMap4XX = new HashMap<Integer, HttpRequestResponseInfo>(); SortedMap<Integer, Integer> httpErrorCounts4XX = new TreeMap<Integer, Integer>(); List<Http4xx5xxStatusResponseCodesEntry> httpResCodelist = new ArrayList<Http4xx5xxStatusResponseCodesEntry>(); HttpRequestResponseInfo lastRequestObj = null; for(Session session: tracedata.getSessionlist()){ lastRequestObj = null; for(HttpRequestResponseInfo req: session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.REQUEST){ lastRequestObj = req; } if(req.getDirection() == HttpDirection.RESPONSE && HttpRequestResponseInfo.HTTP_SCHEME.equals(req.getScheme()) && req.getStatusCode() >= 400 && req.getStatusCode() < 600){ Integer code = req.getStatusCode(); Integer count = httpErrorCounts4XX.get(code); if(count != null){ httpErrorCounts4XX.put(code, count + 1); }else{ httpErrorCounts4XX.put(code, 1); firstErrorRespMap4XX.put(code, req); } httpResCodelist.add(new Http4xx5xxStatusResponseCodesEntry(req, lastRequestObj, session.getDomainName())); } } } if(httpErrorCounts4XX.isEmpty()){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(Http3xx4xxHelper.createFailResult(httpErrorCounts4XX, textResults, errorPlural, errorSingular)); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllHttpError(exportAllHttpError); result.setFirstErrorRespMap4XX(firstErrorRespMap4XX); result.setHttpErrorCounts4XX(httpErrorCounts4XX); result.setHttpResCodelist(httpResCodelist); return result; }  }
Http4xx5xxImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { Http4xx5xxResult result = new Http4xx5xxResult(); Map<Integer, HttpRequestResponseInfo> firstErrorRespMap4XX = new HashMap<Integer, HttpRequestResponseInfo>(); SortedMap<Integer, Integer> httpErrorCounts4XX = new TreeMap<Integer, Integer>(); List<Http4xx5xxStatusResponseCodesEntry> httpResCodelist = new ArrayList<Http4xx5xxStatusResponseCodesEntry>(); HttpRequestResponseInfo lastRequestObj = null; for(Session session: tracedata.getSessionlist()){ lastRequestObj = null; for(HttpRequestResponseInfo req: session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.REQUEST){ lastRequestObj = req; } if(req.getDirection() == HttpDirection.RESPONSE && HttpRequestResponseInfo.HTTP_SCHEME.equals(req.getScheme()) && req.getStatusCode() >= 400 && req.getStatusCode() < 600){ Integer code = req.getStatusCode(); Integer count = httpErrorCounts4XX.get(code); if(count != null){ httpErrorCounts4XX.put(code, count + 1); }else{ httpErrorCounts4XX.put(code, 1); firstErrorRespMap4XX.put(code, req); } httpResCodelist.add(new Http4xx5xxStatusResponseCodesEntry(req, lastRequestObj, session.getDomainName())); } } } if(httpErrorCounts4XX.isEmpty()){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(Http3xx4xxHelper.createFailResult(httpErrorCounts4XX, textResults, errorPlural, errorSingular)); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllHttpError(exportAllHttpError); result.setFirstErrorRespMap4XX(firstErrorRespMap4XX); result.setHttpErrorCounts4XX(httpErrorCounts4XX); result.setHttpResCodelist(httpResCodelist); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
Http4xx5xxImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { Http4xx5xxResult result = new Http4xx5xxResult(); Map<Integer, HttpRequestResponseInfo> firstErrorRespMap4XX = new HashMap<Integer, HttpRequestResponseInfo>(); SortedMap<Integer, Integer> httpErrorCounts4XX = new TreeMap<Integer, Integer>(); List<Http4xx5xxStatusResponseCodesEntry> httpResCodelist = new ArrayList<Http4xx5xxStatusResponseCodesEntry>(); HttpRequestResponseInfo lastRequestObj = null; for(Session session: tracedata.getSessionlist()){ lastRequestObj = null; for(HttpRequestResponseInfo req: session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.REQUEST){ lastRequestObj = req; } if(req.getDirection() == HttpDirection.RESPONSE && HttpRequestResponseInfo.HTTP_SCHEME.equals(req.getScheme()) && req.getStatusCode() >= 400 && req.getStatusCode() < 600){ Integer code = req.getStatusCode(); Integer count = httpErrorCounts4XX.get(code); if(count != null){ httpErrorCounts4XX.put(code, count + 1); }else{ httpErrorCounts4XX.put(code, 1); firstErrorRespMap4XX.put(code, req); } httpResCodelist.add(new Http4xx5xxStatusResponseCodesEntry(req, lastRequestObj, session.getDomainName())); } } } if(httpErrorCounts4XX.isEmpty()){ result.setResultType(BPResultType.PASS); result.setResultText(textResultPass); }else{ result.setResultType(BPResultType.FAIL); result.setResultText(Http3xx4xxHelper.createFailResult(httpErrorCounts4XX, textResults, errorPlural, errorSingular)); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllHttpError(exportAllHttpError); result.setFirstErrorRespMap4XX(firstErrorRespMap4XX); result.setHttpErrorCounts4XX(httpErrorCounts4XX); result.setHttpResCodelist(httpResCodelist); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }