Skip to content

Commit

Permalink
Fix/apps 2894 node size details automation sample test file (#3036)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: mohit-singh4 <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2024
1 parent 3de7445 commit 867af27
Showing 1 changed file with 47 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.alfresco.rest.nodes;

import static java.util.Objects.requireNonNull;

import static org.alfresco.utility.report.log.Step.STEP;

import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream;
Expand All @@ -17,7 +21,6 @@

import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.model.RestSizeDetailsModel;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.*;
Expand All @@ -30,13 +33,19 @@ public class NodeSizeDetailsTests extends RestTest
private SiteModel siteModel;
private FolderModel folder;
private String jobId;
private FileModel sampleFileToCreate;
private long sampleFileSize;

@BeforeClass(alwaysRun = true)
public void dataPreparation()
public void dataPreparation() throws IOException
{
user1 = dataUser.createRandomTestUser("User-1");
siteModel = dataSite.usingUser(user1).createPublicRandomSite();
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));
}

/**
Expand All @@ -52,15 +61,10 @@ public void calculateNodeSizeForSingleFile() throws Exception
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());

STEP("2. Upload a text document to the folder.");
long fileSize;

restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt"));
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode();
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();
dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(folder)
.createContent(sampleFileToCreate);

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);
Expand All @@ -71,10 +75,10 @@ public void calculateNodeSizeForSingleFile() throws Exception

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
.await()
.atMost(Duration.ofSeconds(10))
.atMost(Duration.ofSeconds(5))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
Expand All @@ -86,9 +90,9 @@ public void calculateNodeSizeForSingleFile() throws Exception
sizeDetailsModel.assertThat()
.field("sizeInBytes")
.isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), fileSize,
Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), sampleFileSize,
"Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes()
+ " is not equal to " + fileSize);
+ " is not equal to " + sampleFileSize);
});
}

Expand Down Expand Up @@ -120,13 +124,10 @@ public void checkSizeDetailsWithInvalidJobId() throws Exception
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());

STEP("2. Upload a text document to the folder.");

restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt"));
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
fileNode.assertThat().field("id").isNotNull()
.and().field("name").is("sampleLargeContent.txt")
.and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType);
dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(folder)
.createContent(sampleFileToCreate);

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);
Expand Down Expand Up @@ -170,12 +171,11 @@ public void checkSizeDetailsWithoutExecuteSizeDetails() throws Exception
STEP("2. Upload a text document to the folder.");
String status = "NOT_INITIATED";

restClient.authenticateUser(user1).configureRequestSpec().addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt"));
RestNodeModel fileNode = restClient.withCoreAPI().usingNode(folder).createNode();
restClient.assertStatusCodeIs(HttpStatus.CREATED);
fileNode.assertThat().field("id").isNotNull()
.and().field("name").is("sampleLargeContent.txt")
.and().field("content.mimeType").is(FileType.TEXT_PLAIN.mimeType);
FileModel fileModel = dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(folder)
.createContent(sampleFileToCreate);
Assert.assertNotNull(fileModel, "fileModel should not be null");

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Awaitility
Expand All @@ -189,7 +189,6 @@ public void checkSizeDetailsWithoutExecuteSizeDetails() throws Exception
.usingNode(folder)
.getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.assertStatusCodeIs(HttpStatus.OK);
sizeDetailsModel.assertThat().field("status").isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getStatus().toString(), status, "Value of status should be same, actual :" + sizeDetailsModel.getStatus().toString() + " expected: " + status);
});
Expand Down Expand Up @@ -260,26 +259,11 @@ public void calculateNodeSizeForMultipleFiles() throws InterruptedException
.createFolder(folderModel);

STEP("3. Upload a text document to the childFolders.");
restClient.authenticateUser(user1)
.configureRequestSpec()
.addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt"));
fileSize.addAndGet(Utility.getResourceTestDataFile("sampleLargeContent.txt").length());
RestNodeModel newNode = restClient.authenticateUser(user1)
.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);
dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(childFolder)
.createContent(sampleFileToCreate);
fileSize.addAndGet(sampleFileSize);
});

STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
Expand Down Expand Up @@ -341,25 +325,10 @@ public void checkNumberOfFiles() throws InterruptedException
.createFolder(folderModel);

STEP("3. Upload a text document to the childFolders.");
restClient.authenticateUser(user1)
.configureRequestSpec()
.addMultiPart("filedata", Utility.getResourceTestDataFile("sampleLargeContent.txt"));
RestNodeModel newNode = restClient.authenticateUser(user1)
.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);
dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(childFolder)
.createContent(sampleFileToCreate);
});

STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
Expand Down Expand Up @@ -393,6 +362,16 @@ public void checkNumberOfFiles() throws InterruptedException
});
}

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)
public void cleanup() throws Exception
{
Expand Down

0 comments on commit 867af27

Please sign in to comment.