From bb1e01a6ccfedee90fb67aa5a4ffb6efa97db0b9 Mon Sep 17 00:00:00 2001 From: cagache Date: Mon, 13 May 2019 16:46:32 +0300 Subject: [PATCH] Fix sonar bugs for DockerHelper class --- .../rest/rm/community/util/DockerHelper.java | 16 ++++++++++------ .../DeclareAndFileDocumentAsRecordTests.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/DockerHelper.java b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/DockerHelper.java index adbb4ab30c..ce17d71717 100644 --- a/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/DockerHelper.java +++ b/rm-automation/rm-automation-community-rest-api/src/main/java/org/alfresco/rest/rm/community/util/DockerHelper.java @@ -39,6 +39,8 @@ import com.github.dockerjava.api.model.Frame; import com.github.dockerjava.core.DockerClientBuilder; import com.github.dockerjava.core.command.LogContainerResultCallback; +import lombok.Getter; +import lombok.Setter; import org.apache.commons.lang.SystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,8 +57,10 @@ import org.springframework.stereotype.Service; @Service public class DockerHelper { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); + private static final Logger LOGGER = LoggerFactory.getLogger(DockerHelper.class); private static final String REPO_IMAGE_NAME = "repository"; + @Getter + @Setter private DockerClient dockerClient; @Autowired @@ -82,9 +86,9 @@ public class DockerHelper { final List logs = new ArrayList<>(); // get the logs since current time - 10 seconds - int timeStamp = (int) (System.currentTimeMillis() / 1000) - 10; + final int timeStamp = (int) (System.currentTimeMillis() / 1000) - 10; - LogContainerCmd logContainerCmd = dockerClient.logContainerCmd(containerId); + final LogContainerCmd logContainerCmd = getDockerClient().logContainerCmd(containerId); logContainerCmd.withStdOut(true) .withStdErr(true) .withSince(timeStamp) // UNIX timestamp to filter logs. Output log-entries since that timestamp. @@ -104,7 +108,7 @@ public class DockerHelper catch (InterruptedException e) { Thread.currentThread().interrupt(); // set interrupt flag - logger.error("Failed to retrieve logs of container " + containerId, e); + LOGGER.error("Failed to retrieve logs of container " + containerId, e); } return logs; @@ -117,7 +121,7 @@ public class DockerHelper */ public List getAlfrescoLogs() { - Optional alfrescoContainer = findContainerByImageName(REPO_IMAGE_NAME); + final Optional alfrescoContainer = findContainerByImageName(REPO_IMAGE_NAME); return (alfrescoContainer.isPresent()) ? getDockerLogs(alfrescoContainer.get().getId()) : Collections.emptyList(); } @@ -129,7 +133,7 @@ public class DockerHelper */ private Optional findContainerByImageName(String imageName) { - List containers = dockerClient.listContainersCmd().withShowAll(true).exec(); + final List containers = getDockerClient().listContainersCmd().withShowAll(true).exec(); return containers.stream() .filter(container -> container.getImage().contains(imageName)) diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java index 379ceb45ed..327b70d7b4 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/DeclareAndFileDocumentAsRecordTests.java @@ -146,7 +146,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest STEP("Create test collaboration site to store documents in."); publicSite = dataSite.usingAdmin().createPublicRandomSite(); - STEP("Create a test foloder within the collaboration site"); + STEP("Create a test folder within the collaboration site"); testFolder = dataContent.usingAdmin().usingSite(publicSite).createFolder(); STEP("Create record categories and record folders");