Fix/apps 2894 node size details automation sample test file (#3036)

* Adding the test case for calculating the NodeSize.

* Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationTest] Adding the test case for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

* [fix/APPS-2894_NodeSizeDetails_AutomationSampleTestFile] Updating sample testfile which being used for calculating the NodeSize.

---------

Co-authored-by: kshah <kavit.shah@hyland.com>
Co-authored-by: mohit-singh4 <mohit.singh@contractors.hyland.com>
This commit is contained in:
mohit-singh4
2024-11-14 18:53:27 +05:30
committed by GitHub
parent 3de74456ae
commit 867af27a96

View File

@@ -1,7 +1,11 @@
package org.alfresco.rest.nodes; package org.alfresco.rest.nodes;
import static java.util.Objects.requireNonNull;
import static org.alfresco.utility.report.log.Step.STEP; import static org.alfresco.utility.report.log.Step.STEP;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration; import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream; import java.util.stream.IntStream;
@@ -17,7 +21,6 @@ import org.testng.annotations.Test;
import org.alfresco.dataprep.CMISUtil.DocumentType; import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest; import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.model.RestSizeDetailsModel; import org.alfresco.rest.model.RestSizeDetailsModel;
import org.alfresco.utility.Utility; import org.alfresco.utility.Utility;
import org.alfresco.utility.model.*; import org.alfresco.utility.model.*;
@@ -30,13 +33,19 @@ public class NodeSizeDetailsTests extends RestTest
private SiteModel siteModel; private SiteModel siteModel;
private FolderModel folder; private FolderModel folder;
private String jobId; private String jobId;
private FileModel sampleFileToCreate;
private long sampleFileSize;
@BeforeClass(alwaysRun = true) @BeforeClass(alwaysRun = true)
public void dataPreparation() public void dataPreparation() throws IOException
{ {
user1 = dataUser.createRandomTestUser("User-1"); user1 = dataUser.createRandomTestUser("User-1");
siteModel = dataSite.usingUser(user1).createPublicRandomSite(); siteModel = dataSite.usingUser(user1).createPublicRandomSite();
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());
String fileName = "sampleLargeContent.txt";
final byte[] sampleFileContent = getSampleFileContent(fileName);
sampleFileSize = sampleFileContent.length;
sampleFileToCreate = new FileModel(fileName, FileType.TEXT_PLAIN, new String(sampleFileContent));
} }
/** /**
@@ -52,15 +61,10 @@ public class NodeSizeDetailsTests extends RestTest
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());
STEP("2. Upload a text document to the folder."); STEP("2. Upload a text document to the folder.");
long fileSize; dataContent.usingUser(user1)
.usingSite(siteModel)
restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); .usingResource(folder)
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); .createContent(sampleFileToCreate);
restClient.assertStatusCodeIs(HttpStatus.CREATED);
fileNode.assertThat().field("id").isNotNull()
.and().field("name").is("sampleLargeContent.txt")
.and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType);
fileSize = Utility.getResourceTestDataFile("sampleLargeContent.txt").length();
STEP("3. Wait for 30 seconds so that the content is indexed in Search Service."); STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30); Utility.waitToLoopTime(30);
@@ -71,10 +75,10 @@ public class NodeSizeDetailsTests extends RestTest
jobId = restSizeDetailsModel.getJobId(); jobId = restSizeDetailsModel.getJobId();
STEP("4. Wait for 10 seconds for the processing to complete."); STEP("4. Wait for 5 seconds for the processing to complete.");
Awaitility Awaitility
.await() .await()
.atMost(Duration.ofSeconds(10)) .atMost(Duration.ofSeconds(5))
.pollInterval(Durations.ONE_SECOND) .pollInterval(Durations.ONE_SECOND)
.ignoreExceptions() .ignoreExceptions()
.untilAsserted(() -> { .untilAsserted(() -> {
@@ -86,9 +90,9 @@ public class NodeSizeDetailsTests extends RestTest
sizeDetailsModel.assertThat() sizeDetailsModel.assertThat()
.field("sizeInBytes") .field("sizeInBytes")
.isNotEmpty(); .isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), fileSize, Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), sampleFileSize,
"Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes() "Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes()
+ " is not equal to " + fileSize); + " is not equal to " + sampleFileSize);
}); });
} }
@@ -120,13 +124,10 @@ public class NodeSizeDetailsTests extends RestTest
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel()); folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());
STEP("2. Upload a text document to the folder."); STEP("2. Upload a text document to the folder.");
dataContent.usingUser(user1)
restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); .usingSite(siteModel)
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); .usingResource(folder)
restClient.assertStatusCodeIs(HttpStatus.CREATED); .createContent(sampleFileToCreate);
fileNode.assertThat().field("id").isNotNull()
.and().field("name").is("sampleLargeContent.txt")
.and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType);
STEP("3. Wait for 30 seconds so that the content is indexed in Search Service."); STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30); Utility.waitToLoopTime(30);
@@ -170,12 +171,11 @@ public class NodeSizeDetailsTests extends RestTest
STEP("2. Upload a text document to the folder."); STEP("2. Upload a text document to the folder.");
String status = "NOT_INITIATED"; String status = "NOT_INITIATED";
restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); FileModel fileModel = dataContent.usingUser(user1)
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode(); .usingSite(siteModel)
restClient.assertStatusCodeIs(HttpStatus.CREATED); .usingResource(folder)
fileNode.assertThat().field("id").isNotNull() .createContent(sampleFileToCreate);
.and().field("name").is("sampleLargeContent.txt") Assert.assertNotNull(fileModel, "fileModel should not be null");
.and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType);
STEP("3. Wait for 30 seconds so that the content is indexed in Search Service."); STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Awaitility Awaitility
@@ -189,7 +189,6 @@ public class NodeSizeDetailsTests extends RestTest
.usingNode(folder) .usingNode(folder)
.getSizeDetails(jobId); .getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.OK); restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.assertStatusCodeIs(HttpStatus.OK);
sizeDetailsModel.assertThat().field("status").isNotEmpty(); sizeDetailsModel.assertThat().field("status").isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getStatus().toString(), status, "Value of status should be same, actual :" + sizeDetailsModel.getStatus().toString() + " expected: " + status); Assert.assertEquals(sizeDetailsModel.getStatus().toString(), status, "Value of status should be same, actual :" + sizeDetailsModel.getStatus().toString() + " expected: " + status);
}); });
@@ -260,26 +259,11 @@ public class NodeSizeDetailsTests extends RestTest
.createFolder(folderModel); .createFolder(folderModel);
STEP("3. Upload a text document to the childFolders."); STEP("3. Upload a text document to the childFolders.");
restClient.authenticateUser(user1) dataContent.usingUser(user1)
.configureRequestSpec() .usingSite(siteModel)
.addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); .usingResource(childFolder)
fileSize.addAndGet(Utility.getResourceTestDataFile("sampleLargeContent.txt").length()); .createContent(sampleFileToCreate);
RestNodeModel newNode = restClient.authenticateUser(user1) fileSize.addAndGet(sampleFileSize);
.withCoreAPI()
.usingNode(childFolder)
.createNode();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
newNode.assertThat()
.field("id")
.isNotNull()
.and()
.field("name")
.is("sampleLargeContent.txt")
.and()
.field("content.mimeType")
.is(FileType.TEXT_PLAIN.mimeType);
}); });
STEP("4. Wait for 30 seconds so that the content is indexed in Search Service."); STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
@@ -341,25 +325,10 @@ public class NodeSizeDetailsTests extends RestTest
.createFolder(folderModel); .createFolder(folderModel);
STEP("3. Upload a text document to the childFolders."); STEP("3. Upload a text document to the childFolders.");
restClient.authenticateUser(user1) dataContent.usingUser(user1)
.configureRequestSpec() .usingSite(siteModel)
.addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt")); .usingResource(childFolder)
RestNodeModel newNode = restClient.authenticateUser(user1) .createContent(sampleFileToCreate);
.withCoreAPI()
.usingNode(childFolder)
.createNode();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
newNode.assertThat()
.field("id")
.isNotNull()
.and()
.field("name")
.is("sampleLargeContent.txt")
.and()
.field("content.mimeType")
.is(FileType.TEXT_PLAIN.mimeType);
}); });
STEP("4. Wait for 30 seconds so that the content is indexed in Search Service."); STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
@@ -393,6 +362,16 @@ public class NodeSizeDetailsTests extends RestTest
}); });
} }
private byte[] getSampleFileContent(String fileName) throws IOException
{
final String fileClasspathLocation = "/shared-resources/testdata/" + fileName;
try (InputStream fileStream = getClass().getResourceAsStream(fileClasspathLocation))
{
requireNonNull(fileStream, "Couldn't locate `" + fileClasspathLocation + "`");
return fileStream.readAllBytes();
}
}
@AfterClass(alwaysRun = true) @AfterClass(alwaysRun = true)
public void cleanup() throws Exception public void cleanup() throws Exception
{ {