Skip to content

Commit

Permalink
Fix/apps 2894 node size details automation test (#3032)
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.

---------

Co-authored-by: kshah <[email protected]>
Co-authored-by: mohit-singh4 <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2024
1 parent 4250167 commit e6ac287
Showing 1 changed file with 336 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package org.alfresco.rest.nodes;

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

import java.time.Duration;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.IntStream;

import org.apache.commons.lang3.RandomStringUtils;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
import org.springframework.http.HttpStatus;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import org.alfresco.dataprep.CMISUtil.DocumentType;
import org.alfresco.rest.RestTest;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.alfresco.rest.model.RestNodeModel;
import org.alfresco.rest.model.RestSizeDetailsModel;
import org.alfresco.utility.Utility;
import org.alfresco.utility.model.*;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;

Expand All @@ -20,6 +29,7 @@ public class NodeSizeDetailsTests extends RestTest
private UserModel user1;
private SiteModel siteModel;
private FolderModel folder;
private String jobId;

@BeforeClass(alwaysRun = true)
public void dataPreparation()
Expand All @@ -30,7 +40,163 @@ public void dataPreparation()
}

/**
*
* calculateNodeSizeForSingleFile testcase
*/

@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void calculateNodeSizeForSingleFile() throws Exception
{

STEP("1. Create a folder in the test site.");
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();

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);

RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails();
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
restSizeDetailsModel.assertThat().field("jobId").isNotEmpty();

jobId = restSizeDetailsModel.getJobId();

STEP("4. Wait for 10 seconds for the processing to complete.");
Awaitility
.await()
.atMost(Duration.ofSeconds(10))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.OK);
sizeDetailsModel.assertThat()
.field("sizeInBytes")
.isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), fileSize,
"Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes()
+ " is not equal to " + fileSize);
});
}

/**
* checkJobIdPresentInCache testcase
*/

@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void checkJobIdPresentInCache() throws Exception
{
STEP("1. Verifying that same JobId is coming or not");
RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails();
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
restSizeDetailsModel.assertThat().field("jobId").isNotEmpty();
Assert.assertEquals(restSizeDetailsModel.getJobId(), jobId, "jobId should be present in cache, actual :" + restSizeDetailsModel.getJobId() + " expected: " + jobId);
}

/**
* checkSizeDetailsWithInvalidJobId testcase
*/

@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void checkSizeDetailsWithInvalidJobId() throws Exception
{

STEP("1. Create a folder in the test site.");
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);

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);

RestSizeDetailsModel restSizeDetailsModel = restClient.authenticateUser(user1).withCoreAPI().usingNode(folder).executeSizeDetails();
restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
restSizeDetailsModel.assertThat().field("jobId").isNotEmpty();
jobId = restSizeDetailsModel.getJobId();

STEP("4. Adding random content to jobId ");
jobId += RandomStringUtils.randomAlphanumeric(2);

STEP("5. Wait for 10 seconds for the processing to complete.");
Awaitility
.await()
.atMost(Duration.ofSeconds(10))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
restClient.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.NOT_FOUND);
});

}

/**
* checkSizeDetailsWithoutExecuteSizeDetails testcase
*/

@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void checkSizeDetailsWithoutExecuteSizeDetails() throws Exception
{

STEP("1. Create a folder in the test site.");
folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());

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);

STEP("3. Wait for 30 seconds so that the content is indexed in Search Service.");
Awaitility
.await()
.atMost(Duration.ofSeconds(30))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1)
.withCoreAPI()
.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);
});

}

/**
* Unauthenticated user not able to execute POST /nodes/{nodeId}/size-details: 401 STATUS CODE
*/

Expand All @@ -57,7 +223,6 @@ public void nodeIdNotExist()
}

/**
*
* Value of nodeId is invalid: 422 STATUS CODE
*/

Expand All @@ -69,4 +234,168 @@ public void nodeIdNotValid()
restClient.authenticateUser(user1).withCoreAPI().usingNode(document).executeSizeDetails();
restClient.assertStatusCodeIs(HttpStatus.UNPROCESSABLE_ENTITY);
}

/**
*
* calculateNodeSizeForMultipleFiles testCase
*/
@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void calculateNodeSizeForMultipleFiles() throws InterruptedException
{
STEP("1. Create a parent folder in the test site.");
FolderModel folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());

STEP("2. Creating a 5 nested folders in the folder-1");
AtomicLong fileSize = new AtomicLong(0);

IntStream.rangeClosed(1, 5).forEach(i -> {
String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2);
FolderModel folderModel = new FolderModel();
folderModel.setName(folder0Name);

FolderModel childFolder = dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(folder)
.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);
});

STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);

RestSizeDetailsModel restSizeDetailsModel = restClient
.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.executeSizeDetails();

restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
restSizeDetailsModel.assertThat().field("jobId").isNotEmpty();

String jobId = restSizeDetailsModel.getJobId();

STEP("5. Wait for 5 seconds for the processing to complete.");
Awaitility
.await()
.atMost(Duration.ofSeconds(5))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.OK);
sizeDetailsModel.assertThat()
.field("sizeInBytes")
.isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getSizeInBytes(), fileSize.get(),
"Value of sizeInBytes " + sizeDetailsModel.getSizeInBytes()
+ " is not equal to " + fileSize.get());
});
}

/**
*
* checkNumberOfFiles testCase
*/
@TestRail(section = {TestGroup.REST_API, TestGroup.NODES}, executionType = ExecutionType.SANITY)
@Test(groups = {TestGroup.REST_API, TestGroup.NODES, TestGroup.SANITY})
public void checkNumberOfFiles() throws InterruptedException
{
STEP("1. Create a parent folder in the test site.");
FolderModel folder = dataContent.usingUser(user1).usingSite(siteModel).createFolder(FolderModel.getRandomFolderModel());

STEP("2. Creating a 10 nested folders in the folder-1");

IntStream.rangeClosed(1, 10).forEach(i -> {
String folder0Name = "childFolder" + i + RandomStringUtils.randomAlphanumeric(2);
FolderModel folderModel = new FolderModel();
folderModel.setName(folder0Name);

FolderModel childFolder = dataContent.usingUser(user1)
.usingSite(siteModel)
.usingResource(folder)
.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);
});

STEP("4. Wait for 30 seconds so that the content is indexed in Search Service.");
Utility.waitToLoopTime(30);

RestSizeDetailsModel restSizeDetailsModel = restClient
.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.executeSizeDetails();

restClient.assertStatusCodeIs(HttpStatus.ACCEPTED);
restSizeDetailsModel.assertThat().field("jobId").isNotEmpty();

String jobId = restSizeDetailsModel.getJobId();

STEP("5. Wait for 10 seconds for the processing to complete.");
Awaitility
.await()
.atMost(Duration.ofSeconds(10))
.pollInterval(Durations.ONE_SECOND)
.ignoreExceptions()
.untilAsserted(() -> {
RestSizeDetailsModel sizeDetailsModel = restClient.authenticateUser(user1)
.withCoreAPI()
.usingNode(folder)
.getSizeDetails(jobId);
restClient.assertStatusCodeIs(HttpStatus.OK);
sizeDetailsModel.assertThat().field("numberOfFiles").isNotEmpty();
Assert.assertEquals(sizeDetailsModel.getNumberOfFiles(), 10, "Value of NumberOfFiles " + sizeDetailsModel.getNumberOfFiles() + " is not equal to " + 10);
});
}

@AfterClass(alwaysRun = true)
public void cleanup() throws Exception
{
dataSite.usingUser(user1).deleteSite(siteModel);
}
}

0 comments on commit e6ac287

Please sign in to comment.