@Test public void runTest_1() { List<Session> sessionlist; Session session_1; session_1 = mock(Session.class); sessionlist = new ArrayList<Session>(); sessionlist.add(session_1); MinificationImpl = (MinificationImpl) context.getBean("minify"); result = MinificationImpl.runTest(tracedata); assertEquals( "Many text files contain excess whitespace to allow for better human coding. Run these files through a minifier to remove the whitespace in order to reduce file size.", result.getAboutText()); assertEquals("Minify CSS, JS and HTML", result.getDetailTitle()); assertEquals("File Download: Minify CSS, JS and HTML", result.getOverviewTitle()); assertEquals("Your trace passes.", result.getResultText()); assertEquals("MINIFICATION", result.getBestPracticeType().toString()); assertEquals("PASS", result.getResultType().toString()); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { htmlCompressor = null; MinificationResult result = new MinificationResult(); initHtmlCompressor(); List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>(); String contentType = null; int totalSavingInBytes = 0; int totalBytes= 0; final ExecutorService executorService = Executors.newFixedThreadPool(50); Collection<Worker> workers = new ArrayList<Worker>(); for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastRequestObj = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastRequestObj = req; } contentType = req.getContentType(); if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) { workers.add(new Worker(contentType, req, lastRequestObj, session)); } } } try { List<Future<MinificationEntry>> list = executorService.invokeAll(workers); for (Future<MinificationEntry> future: list){ if (future != null && future.get()!=null) { totalSavingInBytes += future.get().getSavingsSizeInByte(); totalBytes += future.get().getOriginalSizeInByte(); minificationEntryList.add(future.get()); } } } catch(InterruptedException | ExecutionException ee){ LOGGER.error(ee.getMessage(), ee); } executorService.shutdown(); int savingInKb = totalSavingInBytes / 1024; result.setTotalSavingsInKb(savingInKb); result.setTotalSavingsInByte(totalSavingInBytes); result.setMinificationEntryList(minificationEntryList); int numberOfFiles = minificationEntryList.size(); String text = ""; if (minificationEntryList.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb); result.setResultText(text); } else if (savingInKb < 1) { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100)); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles); return result; }
MinificationImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { htmlCompressor = null; MinificationResult result = new MinificationResult(); initHtmlCompressor(); List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>(); String contentType = null; int totalSavingInBytes = 0; int totalBytes= 0; final ExecutorService executorService = Executors.newFixedThreadPool(50); Collection<Worker> workers = new ArrayList<Worker>(); for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastRequestObj = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastRequestObj = req; } contentType = req.getContentType(); if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) { workers.add(new Worker(contentType, req, lastRequestObj, session)); } } } try { List<Future<MinificationEntry>> list = executorService.invokeAll(workers); for (Future<MinificationEntry> future: list){ if (future != null && future.get()!=null) { totalSavingInBytes += future.get().getSavingsSizeInByte(); totalBytes += future.get().getOriginalSizeInByte(); minificationEntryList.add(future.get()); } } } catch(InterruptedException | ExecutionException ee){ LOGGER.error(ee.getMessage(), ee); } executorService.shutdown(); int savingInKb = totalSavingInBytes / 1024; result.setTotalSavingsInKb(savingInKb); result.setTotalSavingsInByte(totalSavingInBytes); result.setMinificationEntryList(minificationEntryList); int numberOfFiles = minificationEntryList.size(); String text = ""; if (minificationEntryList.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb); result.setResultText(text); } else if (savingInKb < 1) { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100)); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles); return result; } }
MinificationImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { htmlCompressor = null; MinificationResult result = new MinificationResult(); initHtmlCompressor(); List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>(); String contentType = null; int totalSavingInBytes = 0; int totalBytes= 0; final ExecutorService executorService = Executors.newFixedThreadPool(50); Collection<Worker> workers = new ArrayList<Worker>(); for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastRequestObj = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastRequestObj = req; } contentType = req.getContentType(); if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) { workers.add(new Worker(contentType, req, lastRequestObj, session)); } } } try { List<Future<MinificationEntry>> list = executorService.invokeAll(workers); for (Future<MinificationEntry> future: list){ if (future != null && future.get()!=null) { totalSavingInBytes += future.get().getSavingsSizeInByte(); totalBytes += future.get().getOriginalSizeInByte(); minificationEntryList.add(future.get()); } } } catch(InterruptedException | ExecutionException ee){ LOGGER.error(ee.getMessage(), ee); } executorService.shutdown(); int savingInKb = totalSavingInBytes / 1024; result.setTotalSavingsInKb(savingInKb); result.setTotalSavingsInByte(totalSavingInBytes); result.setMinificationEntryList(minificationEntryList); int numberOfFiles = minificationEntryList.size(); String text = ""; if (minificationEntryList.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb); result.setResultText(text); } else if (savingInKb < 1) { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100)); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles); return result; }  }
MinificationImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { htmlCompressor = null; MinificationResult result = new MinificationResult(); initHtmlCompressor(); List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>(); String contentType = null; int totalSavingInBytes = 0; int totalBytes= 0; final ExecutorService executorService = Executors.newFixedThreadPool(50); Collection<Worker> workers = new ArrayList<Worker>(); for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastRequestObj = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastRequestObj = req; } contentType = req.getContentType(); if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) { workers.add(new Worker(contentType, req, lastRequestObj, session)); } } } try { List<Future<MinificationEntry>> list = executorService.invokeAll(workers); for (Future<MinificationEntry> future: list){ if (future != null && future.get()!=null) { totalSavingInBytes += future.get().getSavingsSizeInByte(); totalBytes += future.get().getOriginalSizeInByte(); minificationEntryList.add(future.get()); } } } catch(InterruptedException | ExecutionException ee){ LOGGER.error(ee.getMessage(), ee); } executorService.shutdown(); int savingInKb = totalSavingInBytes / 1024; result.setTotalSavingsInKb(savingInKb); result.setTotalSavingsInByte(totalSavingInBytes); result.setMinificationEntryList(minificationEntryList); int numberOfFiles = minificationEntryList.size(); String text = ""; if (minificationEntryList.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb); result.setResultText(text); } else if (savingInKb < 1) { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100)); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles); return result; }  @Autowired void setHttpRequestResponseHelper(IHttpRequestResponseHelper reqhelper); @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); MinificationEntry calculateSavingMinifiedHtml(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); MinificationEntry calculateSavingMinifiedCss(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyCss(String content); MinificationEntry calculateSavingMinifiedJavascript(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyJavascript(String content); MinificationEntry calculateSavingMinifiedJson(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyJson(String jsonString); }
MinificationImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { htmlCompressor = null; MinificationResult result = new MinificationResult(); initHtmlCompressor(); List<MinificationEntry> minificationEntryList = new ArrayList<MinificationEntry>(); String contentType = null; int totalSavingInBytes = 0; int totalBytes= 0; final ExecutorService executorService = Executors.newFixedThreadPool(50); Collection<Worker> workers = new ArrayList<Worker>(); for (Session session : tracedata.getSessionlist()) { HttpRequestResponseInfo lastRequestObj = null; for (HttpRequestResponseInfo req : session.getRequestResponseInfo()) { if (req.getDirection() == HttpDirection.REQUEST) { lastRequestObj = req; } contentType = req.getContentType(); if (req.getDirection() == HttpDirection.RESPONSE && req.getContentLength() > 0 && contentType != null) { workers.add(new Worker(contentType, req, lastRequestObj, session)); } } } try { List<Future<MinificationEntry>> list = executorService.invokeAll(workers); for (Future<MinificationEntry> future: list){ if (future != null && future.get()!=null) { totalSavingInBytes += future.get().getSavingsSizeInByte(); totalBytes += future.get().getOriginalSizeInByte(); minificationEntryList.add(future.get()); } } } catch(InterruptedException | ExecutionException ee){ LOGGER.error(ee.getMessage(), ee); } executorService.shutdown(); int savingInKb = totalSavingInBytes / 1024; result.setTotalSavingsInKb(savingInKb); result.setTotalSavingsInByte(totalSavingInBytes); result.setMinificationEntryList(minificationEntryList); int numberOfFiles = minificationEntryList.size(); String text = ""; if (minificationEntryList.isEmpty()) { result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, numberOfFiles, savingInKb); result.setResultText(text); } else if (savingInKb < 1) { result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResultFail, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles); result.setResultText(text); } else { result.setResultType(BPResultType.FAIL); String percentageSaving = String.valueOf(Math.round(((double) totalSavingInBytes / totalBytes) * 100)); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), numberOfFiles, savingInKb, percentageSaving); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfMinifyFiles(exportAllNumberOfMinifyFiles); return result; }  @Autowired void setHttpRequestResponseHelper(IHttpRequestResponseHelper reqhelper); @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); MinificationEntry calculateSavingMinifiedHtml(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); MinificationEntry calculateSavingMinifiedCss(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyCss(String content); MinificationEntry calculateSavingMinifiedJavascript(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyJavascript(String content); MinificationEntry calculateSavingMinifiedJson(HttpRequestResponseInfo req, HttpRequestResponseInfo lastRequestObj, Session session); String minifyJson(String jsonString);  }