From 4631a91401167d25bcd878f77c51074082667f69 Mon Sep 17 00:00:00 2001 From: Benoit DUMONT Date: Wed, 3 Jan 2024 18:37:15 +0100 Subject: [PATCH] Code refactoring and maven dependency clean. --- source/pom.xml | 170 ++++++--------- .../execution/impl/RecorderService.java | 3 +- .../ReadTestCaseExecutionMedia.java | 10 +- .../servlet/zzpublic/GetTestCasesV001.java | 193 ------------------ .../java/org/cerberus/core/util/XmlUtil.java | 3 +- .../D2/include/en/changelog_4.18_en.adoc | 3 +- 6 files changed, 66 insertions(+), 316 deletions(-) delete mode 100644 source/src/main/java/org/cerberus/core/servlet/zzpublic/GetTestCasesV001.java diff --git a/source/pom.xml b/source/pom.xml index d994053dff..cd5294d11e 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -50,7 +50,7 @@ 2.7.0 3.0.11 - 3.0.11 + 1.19 7.2.0 @@ -62,36 +62,14 @@ 1.1.0 2.17.2 - 1.7.26 - - 8.0.1 - 4.0.1 - 1.1 - 32.1.3-jre - 1.5 - 20211018.1 - 1.0.16 - 1.5 - 2.7 - 3.9.0 - 3.12.0 - 4.4 - 0.8.5 - 1.5 - 1.3 - 4.1.2 - 2.1.0 - 1.28.3 - 4.5.14 - 4.5.14 - - + + 1.0.0 1.4.0 2.3.0 - 1.5.1 - 2.2.6 + + 2.6.3 6.2.1 @@ -104,11 +82,31 @@ 1.4.2.Final 2.9.2 + + 4.5.14 + + 8.0.1 + + + + 1.5 + 20211018.1 + 1.5 + 2.7 + 3.9.0 + 3.12.0 + 4.4 + 0.8.5 + 1.5 + 1.3 + + 1.28.3 + - 4.12 - 1.5.2 - 1.9.5 + + + 3.12.1 @@ -295,16 +293,6 @@ - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - - org.apache.logging.log4j - log4j-web - ${log4j.version} - org.apache.logging.log4j log4j-api @@ -346,18 +334,14 @@ compile - - - org.slf4j - slf4j-api - ${slf4j.version} - pom - + - org.slf4j - slf4j-log4j12 - ${slf4j.version} + io.github.amaris + sftm-tree-matching + ${sftm-tree-matching.version} + + javax.xml.soap javax.xml.soap-api @@ -368,7 +352,18 @@ jaxb-api ${jaxb.version} + + javax + javaee-web-api + ${javaee-web-api} + provided + + + + + xmlunit xmlunit @@ -425,11 +404,6 @@ owasp-java-html-sanitizer ${owasp-java-html-sanitizer.version} - - jfree - jcommon - ${jcommon.version} - commons-fileupload commons-fileupload @@ -470,7 +444,7 @@ commons-text ${commons-text.version} - + org.apache.tika tika-core ${apache.tika.version} - + org.apache.httpcomponents httpmime @@ -536,36 +505,11 @@ layout ${com.itextpdf.version} - - com.itextpdf - forms - ${com.itextpdf.version} - - - com.itextpdf - pdfa - ${com.itextpdf.version} - com.itextpdf sign ${com.itextpdf.version} - - com.itextpdf - barcodes - ${com.itextpdf.version} - - - com.itextpdf - font-asian - ${com.itextpdf.version} - - - com.itextpdf - hyph - ${com.itextpdf.version} - com.itextpdf html2pdf @@ -673,7 +617,7 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - + ${java.version} ${java.version} diff --git a/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java b/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java index 70d7c6fd24..d110cb48f9 100644 --- a/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java +++ b/source/src/main/java/org/cerberus/core/engine/execution/impl/RecorderService.java @@ -447,7 +447,8 @@ public TestCaseExecutionFile recordPicture(TestCaseStepActionExecution actionExe File newImage = new File(recorder.getFullFilename()); OutputStream outStream = new FileOutputStream(newImage); outStream.write(bytes); - IOUtils.close(outStream); + outStream.close(); +// IOUtils.close(outStream); // Index file created to database. object = testCaseExecutionFileFactory.create(0, runId, recorder.getLevel(), "Picture " + valueFieldName, recorder.getRelativeFilenameURL(), "PNG", "", null, "", null); diff --git a/source/src/main/java/org/cerberus/core/servlet/crud/testexecution/ReadTestCaseExecutionMedia.java b/source/src/main/java/org/cerberus/core/servlet/crud/testexecution/ReadTestCaseExecutionMedia.java index 50b8337f41..4fed269149 100644 --- a/source/src/main/java/org/cerberus/core/servlet/crud/testexecution/ReadTestCaseExecutionMedia.java +++ b/source/src/main/java/org/cerberus/core/servlet/crud/testexecution/ReadTestCaseExecutionMedia.java @@ -19,7 +19,6 @@ */ package org.cerberus.core.servlet.crud.testexecution; -import com.google.common.io.Files; import com.mortennobel.imagescaling.DimensionConstrain; import com.mortennobel.imagescaling.ResampleOp; import java.awt.image.BufferedImage; @@ -50,7 +49,6 @@ import org.cerberus.core.util.StringUtil; import org.cerberus.core.util.answer.AnswerList; import org.cerberus.core.util.servlet.ServletUtil; -import org.jfree.util.Log; import org.springframework.context.ApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -285,9 +283,9 @@ private void returnPDF(HttpServletRequest request, HttpServletResponse response, response.setContentType("application/pdf"); response.setContentLength((int) pdfFile.length()); try { - Files.copy(pdfFile, response.getOutputStream()); + FileUtils.copyFile(pdfFile, response.getOutputStream()); } catch (IOException e) { - Log.warn(e); + LOG.warn(e); } } @@ -301,9 +299,9 @@ private void returnMP4(HttpServletRequest request, HttpServletResponse response, response.setContentLength((int) mp4File.length()); response.setHeader("Content-Range", "bytes start-end/length"); try { - Files.copy(mp4File, response.getOutputStream()); + FileUtils.copyFile(mp4File, response.getOutputStream()); } catch (IOException e) { - Log.warn(e); + LOG.warn(e); } } diff --git a/source/src/main/java/org/cerberus/core/servlet/zzpublic/GetTestCasesV001.java b/source/src/main/java/org/cerberus/core/servlet/zzpublic/GetTestCasesV001.java deleted file mode 100644 index 31ce70fb74..0000000000 --- a/source/src/main/java/org/cerberus/core/servlet/zzpublic/GetTestCasesV001.java +++ /dev/null @@ -1,193 +0,0 @@ -/* Cerberus Copyright (C) 2013 - 2017 cerberustesting - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - - This file is part of Cerberus. - - Cerberus is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Cerberus is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Cerberus. If not, see .*/ -package org.cerberus.core.servlet.zzpublic; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.servlet.ServletContext; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.cerberus.core.crud.entity.TestCase; -import org.cerberus.core.crud.service.ITestCaseService; -import org.cerberus.core.service.authentification.IAPIKeyService; -import org.cerberus.core.util.StringUtil; -import org.springframework.context.ApplicationContext; -import org.springframework.web.context.support.WebApplicationContextUtils; - -/** - * This webservices is the rewriting of GetTestCasesV000 servlet adding Jax-RS - * Jax-RS is Java API for RESTful Web Services To learn more about it : - * http://spoonless.github.io/epsi-b3-javaee/javaee_web/jaxrs.html - * - * Webservice target it to return testcase by application - * - * @author Corentin Delage - */ -@Path("/GetTestCasesV001") -public class GetTestCasesV001 { - - private ITestCaseService testCaseService; - private static final String VERSION = "V1"; - private static final Logger LOG = LogManager.getLogger(GetTestCasesV001.class); - private IAPIKeyService apiKeyService; - - /* - * Response.Testcase object target is to construct testcase object formatted for webservice response - * expected attributes is : test, testCase, description, application, status. - */ - public static class ResponseTC { - - public static class TestCase implements Serializable { - - // TO DO : rework with auto generated serialization, this method should create bug when other object are import with same serialVersionUID - private static final long serialVersionUID = 1L; - - private final String test; - private final String testCase; - private final String description; - private final String application; - private final String status; - - public TestCase(final String test, final String testCase, final String description, final String application, final String status) { - this.test = test; - this.testCase = testCase; - this.description = description; - this.application = application; - this.status = status; - } - - public String getTest() { - return test; - } - - public String getTestCase() { - return testCase; - } - - public String getDescription() { - return description; - } - - public String getApplication() { - return application; - } - - public String getStatus() { - return status; - } - } - } - - protected String getVersion() { - return VERSION; - } - - /* - *method getTestCaseByApplication - *Called by user GET request - *target it build response send to user - *@Param application : get value of application in query url (to learn more about @QueryParam : https://www.mkyong.com/webservices/jax-rs/jax-rs-queryparam-example/) - *@Param servletContext : get servlet context to get bean of application in fine. - *@Return response : return the list of application in success case or error message in failed case - */ - @GET - @Produces(MediaType.APPLICATION_JSON) - public Response getTestCaseByApplication(@QueryParam("application") String application, @Context ServletContext servletContext) { - LOG.info("Webservice GetTestCasesV001 called by GET Request"); - Map mapResponse = new HashMap<>(); - try { - if (!StringUtil.isEmpty(application)) { - //Process to get testcase by application - List testCaseListResponse = new ArrayList<>(); - testCaseListResponse = findTestCasesByApplication(application, servletContext); - mapResponse.put("testCases", testCaseListResponse); - } else { - //TO DO : rework for get same exception than GetTestCasesV000 - mapResponse.put("Version", getVersion()); - mapResponse.put("Error", "no parameter application found"); - } - } catch (Exception exception) { - //TO DO : rework for get same exception than GetTestCasesV000 - mapResponse.put("Version", getVersion()); - mapResponse.put("Error", exception.getMessage()); - } - //Final response send to client - //Note : is also possible to return mapResponse only, Jax-RS will convert it to JSON (Response is Jax-RS Object) - return Response.ok(mapResponse).build(); - } - - /* - * Method findTestCasesByApplication - * target is return list of testcase associated to an application - * @Param application - * @Param ServletContext : using to call getTestCaseServiceFromSpring, to get testcase service spring bean - * @Return testCases : list of response - */ - private List findTestCasesByApplication(final String application, ServletContext servletContext) { - //Process to get testCase by application - getTestCaseServiceFromSpring(servletContext); - List response = new ArrayList<>(); - final List testCases = testCaseService.findTestCaseByApplication(application); - - if (testCases == null) { - LOG.error("TestCase list for application {} is null", application); - } else { - //Called conversion from testcase to Response.testcase - response = testCaseListConversionToResponse(testCases); - } - return response; - } - - /* - * Method getTestCaseServiceFromSpring - * target is to get bean of testcase service instance from the current application. - * @Param servletContext : context of servlet catched when GetTesCasesV001 is called - */ - public void getTestCaseServiceFromSpring(ServletContext servletContext) { - ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); - this.testCaseService = appContext.getBean(ITestCaseService.class); - } - - /* - * Method testCaseListConvertToResponse - * target is convert testcase from list to ResponseTC.testcase (to keep expected element of testcase for webservice response) - * expected element : test, testCase, description, application, status - * @Param testCaseList - * @Return testCaseList : reworked testcaseList - */ - public List testCaseListConversionToResponse(List testCaseList) { - //using stream method, to learn more about it : https://blog.ippon.fr/2014/03/17/api-stream-une-nouvelle-facon-de-gerer-les-collections-en-java-8/ - List responseList = testCaseList.stream() - .map(testCase -> new ResponseTC.TestCase(testCase.getTest(), - testCase.getTestcase(), testCase.getDescription(), - testCase.getApplication(), testCase.getStatus())) - .collect(Collectors.toList()); - return responseList; - } -} diff --git a/source/src/main/java/org/cerberus/core/util/XmlUtil.java b/source/src/main/java/org/cerberus/core/util/XmlUtil.java index dd98172996..2e0e57b283 100644 --- a/source/src/main/java/org/cerberus/core/util/XmlUtil.java +++ b/source/src/main/java/org/cerberus/core/util/XmlUtil.java @@ -21,7 +21,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.jfree.util.Log; import org.w3c.dom.Attr; import org.w3c.dom.DOMException; import org.w3c.dom.Document; @@ -477,7 +476,7 @@ public static Document fromNode(Node node) throws XmlUtilException { document.appendChild(document.adoptNode(node.cloneNode(true))); return document; } catch (DOMException e) { - Log.warn("Unable to create document from node " + node, e); + LOG.warn("Unable to create document from node " + node, e); return null; } } diff --git a/source/src/main/resources/documentation/D2/include/en/changelog_4.18_en.adoc b/source/src/main/resources/documentation/D2/include/en/changelog_4.18_en.adoc index c56cbe26cf..1123505830 100644 --- a/source/src/main/resources/documentation/D2/include/en/changelog_4.18_en.adoc +++ b/source/src/main/resources/documentation/D2/include/en/changelog_4.18_en.adoc @@ -5,7 +5,8 @@ *Improvements / New features* [square] * Added status code for Logs (Menu Administration / Log Viewer) +* Size of war binary reduced by cleaning a few unnecessary maven dependencies. *Warning to be considered before applying the version (deprecated features)* [square] -* none +* Service /GetTestCasesV001 is no longuer working. Please use /GetTestCasesV002 in stead or (even better) the /api/public/testcases/Examples/0001A endpoint.