From 32d72a2bf8e8aa5cd461059c8435b33e42ce320b Mon Sep 17 00:00:00 2001 From: Claudia Agache Date: Wed, 15 Jul 2020 11:54:01 +0300 Subject: [PATCH] create helper method to check if an exception is thrown in alfresco logs --- .../rest/rm/community/util/DockerHelper.java | 19 +++++++++++++++++++ .../DeclareAndFileDocumentAsRecordTests.java | 9 +-------- .../files/FileVersionAsRecordTests.java | 11 ++--------- 3 files changed, 22 insertions(+), 17 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 a46cd44e5c..dd71e65075 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 @@ -27,6 +27,8 @@ package org.alfresco.rest.rm.community.util; +import static org.testng.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -42,6 +44,7 @@ import com.github.dockerjava.netty.NettyDockerCmdExecFactory; import lombok.Getter; import lombok.Setter; +import org.alfresco.utility.Utility; import org.apache.commons.lang.SystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -142,6 +145,22 @@ public class DockerHelper } } + /** + * Helper method to check if the specified exception is thrown in alfresco logs + * + * @param expectedException the expected exception to be thrown + * @throws Exception + */ + public void checkExceptionIsInAlfrescoLogs(String expectedException) throws Exception + { + //Retry the operation because sometimes it takes few seconds to throw the exception + Utility.sleep(6000, 30000, () -> + { + List alfrescoLogs = getAlfrescoLogs(); + assertTrue(alfrescoLogs.stream().anyMatch(logLine -> logLine.contains(expectedException))); + }); + } + /** * Method for finding docker containers after the image name * 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 a040a4d3d1..61e91f4517 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 @@ -50,8 +50,6 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; -import java.util.List; - import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.rm.community.base.BaseRMRestTest; import org.alfresco.rest.rm.community.model.record.Record; @@ -266,12 +264,7 @@ public class DeclareAndFileDocumentAsRecordTests extends BaseRMRestTest assertStatusCode(ACCEPTED); STEP("Check the exception thrown in alfresco logs"); - //Retry the operation because sometimes it takes few seconds to throw the exception - Utility.sleep(6000, 30000, () -> - { - List alfrescoLogs = dockerHelper.getAlfrescoLogs(); - assertTrue(alfrescoLogs.stream().anyMatch(logLine -> logLine.contains(expectedException))); - }); + dockerHelper.checkExceptionIsInAlfrescoLogs(expectedException); STEP("Check that the file is not a record"); assertFalse(hasRecordAspect(testFile), "File should not have record aspect"); diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/FileVersionAsRecordTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/FileVersionAsRecordTests.java index 4e32cf4790..dd6d0e453c 100644 --- a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/FileVersionAsRecordTests.java +++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/files/FileVersionAsRecordTests.java @@ -41,7 +41,6 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import java.io.File; -import java.util.List; import org.alfresco.dataprep.CMISUtil; import org.alfresco.rest.rm.community.base.BaseRMRestTest; @@ -127,7 +126,7 @@ public class FileVersionAsRecordTests extends BaseRMRestTest } @BeforeMethod (alwaysRun = true) - public void createDocument() + public void createDocument() throws Exception { STEP("Create a document in the collaboration site"); testFile = dataContent.usingSite(publicSite) @@ -215,13 +214,7 @@ public class FileVersionAsRecordTests extends BaseRMRestTest assertStatusCode(ACCEPTED); STEP("Check the exception thrown in alfresco logs"); - //Retry the operation because sometimes it takes few seconds to throw the exception - Utility.sleep(6000, 30000, () -> - { - List alfrescoLogs = dockerHelper.getAlfrescoLogs(); - assertTrue(alfrescoLogs.stream().anyMatch(logLine -> logLine.contains(expectedException))); - }); - + dockerHelper.checkExceptionIsInAlfrescoLogs(expectedException); } /**