[feature/MNT-24127-EndpointToCalculateFolderSize] Updated endpoints flow to calculate and retrieve folder size details

This commit is contained in:
mohit-singh4
2024-09-04 10:32:17 +05:30
parent a620e9114f
commit 0959f820e4
12 changed files with 153 additions and 100 deletions

View File

@@ -25,15 +25,15 @@
*/
package org.alfresco.rest.api;
import org.alfresco.rest.api.model.NodeSizeDetail;
import org.alfresco.rest.api.model.NodeSizeDetails;
public interface SizeDetail
public interface SizeDetails
{
enum PROCESSINGSTATE
{
NOT_INITIATED, IN_PROGRESS, COMPLETED;
}
NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId);
NodeSizeDetail getNodeSizeDetails(String nodeId, String jobId);
NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId);
NodeSizeDetails getNodeSizeDetails(String nodeId, String jobId);
}

View File

@@ -29,10 +29,10 @@ import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.SizeDetail;
import org.alfresco.rest.api.SizeDetails;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.NodePermissions;
import org.alfresco.rest.api.model.NodeSizeDetail;
import org.alfresco.rest.api.model.NodeSizeDetails;
import org.alfresco.rest.framework.core.exceptions.InvalidNodeTypeException;
import org.alfresco.rest.framework.core.exceptions.UnprocessableContentException;
import org.alfresco.service.cmr.action.Action;
@@ -48,13 +48,13 @@ import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.COMPLETED;
import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.NOT_INITIATED;
import static org.alfresco.rest.api.SizeDetail.PROCESSINGSTATE.IN_PROGRESS;
import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.COMPLETED;
import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.NOT_INITIATED;
import static org.alfresco.rest.api.SizeDetails.PROCESSINGSTATE.IN_PROGRESS;
public class SizeDetailImpl implements SizeDetail
public class SizeDetailsImpl implements SizeDetails
{
private static final Logger LOG = LoggerFactory.getLogger(SizeDetailImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(SizeDetailsImpl.class);
private static final String STATUS = "status";
private static final String ACTIONID = "actionId";
private static final String INVALID_NODEID = "Invalid parameter: value of nodeId is invalid";
@@ -97,37 +97,41 @@ public class SizeDetailImpl implements SizeDetail
this.defaultItems = defaultItems;
}
/**
* generateNodeSizeDetailsRequest : providing HTTP STATUS 202 with jobId.
*/
@Override
public NodeSizeDetail generateNodeSizeDetailsRequest(String nodeId) {
public NodeSizeDetails generateNodeSizeDetailsRequest(String nodeId)
{
NodeRef nodeRef = nodes.validateNode(nodeId);
validateType(nodeRef);
String actionId;
if(simpleCache.get(nodeId) == null)
{
actionId = executeAction(nodeRef, defaultItems, simpleCache);
} else {
} else
{
Map<String, Object> result = simpleCache.get(nodeRef.getId());
actionId = (String)result.get(ACTIONID);
}
return new NodeSizeDetail(actionId);
return new NodeSizeDetails(actionId);
}
/**
* calculateNodeSize : providing HTTP STATUS 202 which signifies REQUEST ACCEPTED.
* HTTP STATUS 200 will provide the size details response from cache.
* getNodeSizeDetails : providing HTTP STATUS 200 with NodeSizeDetails data from cache.
*/
@Override
public NodeSizeDetail getNodeSizeDetails(final String nodeId, final String jobId)
public NodeSizeDetails getNodeSizeDetails(final String nodeId, final String jobId)
{
NodeRef nodeRef = nodes.validateNode(nodeId);
validateType(nodeRef);
if(simpleCache.get(nodeId) == null)
{
return new NodeSizeDetail(nodeId, NOT_INITIATED.name());
return new NodeSizeDetails(nodeId, NOT_INITIATED.name());
}
LOG.debug("Executing NodeSizeDetailActionExecuter from calculateNodeSize method");
LOG.debug("Executing executorResultToSizeDetail method");
return executorResultToSizeDetail(simpleCache.get(nodeId), nodeId, jobId);
}
@@ -151,11 +155,11 @@ public class SizeDetailImpl implements SizeDetail
/**
* Converting action executor response to their respective model class.
*/
private NodeSizeDetail executorResultToSizeDetail(final Map<String,Object> result, String nodeId, String jobId)
private NodeSizeDetails executorResultToSizeDetail(final Map<String,Object> result, String nodeId, String jobId)
{
if(result.containsKey(NodeSizeDetailActionExecutor.EXCEPTION))
{
return new NodeSizeDetail(nodeId, COMPLETED.name());
return new NodeSizeDetails(nodeId, COMPLETED.name());
}
// Check for the presence of "size" key.
@@ -163,21 +167,22 @@ public class SizeDetailImpl implements SizeDetail
if (hasSizeKey)
{
NodeSizeDetail nodeSizeDetail = new NodeSizeDetail((String) result.get("nodeId"),
NodeSizeDetails nodeSizeDetails = new NodeSizeDetails((String) result.get("nodeId"),
(Long) result.get("size"),
(String) result.get("calculatedAt"),
(Integer) result.get("numberOfFiles"),
COMPLETED.name(),
(String) result.get(ACTIONID));
if(!nodeSizeDetail.getJobId().equalsIgnoreCase(jobId)) {
if(!nodeSizeDetails.getJobId().equalsIgnoreCase(jobId))
{
throw new UnprocessableContentException(INVALID_JOBID);
}
return nodeSizeDetail;
return nodeSizeDetails;
}
else
{
return new NodeSizeDetail(nodeId, IN_PROGRESS.name());
return new NodeSizeDetails(nodeId, IN_PROGRESS.name());
}
}

View File

@@ -25,9 +25,11 @@
*/
package org.alfresco.rest.api.model;
import org.json.simple.JSONObject;
import java.util.Objects;
public class NodeSizeDetail
public class NodeSizeDetails
{
private String nodeId;
private Long size;
@@ -36,16 +38,18 @@ public class NodeSizeDetail
private String status;
private String jobId;
public NodeSizeDetail(String jobId) {
public NodeSizeDetails(String jobId)
{
this.jobId = jobId;
}
public NodeSizeDetail(String nodeId, String status) {
public NodeSizeDetails(String nodeId, String status)
{
this.nodeId = nodeId;
this.status = status;
}
public NodeSizeDetail(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId)
public NodeSizeDetails(String nodeId, Long size, String calculatedAt, Integer numberOfFiles, String status, String jobId)
{
this.nodeId = nodeId;
this.size = size;
@@ -105,26 +109,46 @@ public class NodeSizeDetail
this.status = status;
}
public String getJobId() { return jobId; }
public String getJobId()
{
return jobId;
}
public void setJobId(String jobId) { this.jobId = jobId; }
public void setJobId(String jobId)
{
this.jobId = jobId;
}
public static String parseJson(JSONObject jsonObject)
{
if (jsonObject == null)
{
return null;
}
String jobId = (String)jsonObject.get("jobId");
return jobId;
}
@Override
public boolean equals(Object o) {
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeSizeDetail that = (NodeSizeDetail) o;
NodeSizeDetails that = (NodeSizeDetails) o;
return Objects.equals(nodeId, that.nodeId) && Objects.equals(size, that.size) && Objects.equals(calculatedAt, that.calculatedAt) && Objects.equals(numberOfFiles, that.numberOfFiles) && Objects.equals(status, that.status) && Objects.equals(jobId, that.jobId);
}
@Override
public int hashCode() {
public int hashCode()
{
return Objects.hash(nodeId, size, calculatedAt, numberOfFiles, status, jobId);
}
@Override
public String toString() {
return "NodeSizeDetail{" +
public String toString()
{
return "NodeSizeDetails{" +
"nodeId='" + nodeId + '\'' +
", size=" + size +
", calculatedAt='" + calculatedAt + '\'' +

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2023 Alfresco Software Limited
* Copyright (C) 2005 - 2024 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -27,8 +27,8 @@
package org.alfresco.rest.api.nodes;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.SizeDetail;
import org.alfresco.rest.api.model.NodeSizeDetail;
import org.alfresco.rest.api.SizeDetails;
import org.alfresco.rest.api.model.NodeSizeDetails;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.WebApiParam;
import org.alfresco.rest.framework.WebApiParameters;
@@ -47,22 +47,22 @@ import java.util.List;
@RelationshipResource(name = "size-details", entityResource = NodesEntityResource.class, title = "Node Size Details")
public class NodeSizeDetailsRelation implements
RelationshipResourceAction.ReadById<NodeSizeDetail>,
RelationshipResourceAction.Create<NodeSizeDetail>,
RelationshipResourceAction.ReadById<NodeSizeDetails>,
RelationshipResourceAction.Create<NodeSizeDetails>,
InitializingBean {
private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsRelation.class);
private Nodes nodes;
private SizeDetail sizeDetail;
private SizeDetails sizeDetails;
public void setNodes(Nodes nodes)
{
this.nodes = nodes;
}
public void setSizeDetail(SizeDetail sizeDetail)
public void setSizeDetails(SizeDetails sizeDetails)
{
this.sizeDetail = sizeDetail;
this.sizeDetails = sizeDetails;
}
@Override
@@ -75,9 +75,10 @@ public class NodeSizeDetailsRelation implements
@WebApiParam(name="nodeSizeEntity", title="Node Size Details Request", description="Request for processing Node Size.",
kind= ResourceParameter.KIND.HTTP_BODY_OBJECT, allowMultiple=false)
@Override
public List<NodeSizeDetail> create(String nodeId, List<NodeSizeDetail> nodeSizeEntity, Parameters parameters) {
public List<NodeSizeDetails> create(String nodeId, List<NodeSizeDetails> nodeSizeEntity, Parameters parameters)
{
LOG.debug(" Executing generateNodeSizeDetailsRequest method ");
return Arrays.asList(sizeDetail.generateNodeSizeDetailsRequest(nodeId));
return Arrays.asList(sizeDetails.generateNodeSizeDetailsRequest(nodeId));
}
@WebApiDescription(title = "Get Node Size Details", description = "Get the Node Size Details")
@@ -85,8 +86,9 @@ public class NodeSizeDetailsRelation implements
@WebApiParam(name="nodeId", title="The unique id of the Node being addressed", description="A single node id"),
@WebApiParam(name="jobId", title="Job Id to get the NodeSizeDetails", description="JobId")})
@Override
public NodeSizeDetail readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException {
public NodeSizeDetails readById(String nodeId, String jobId, Parameters parameters) throws RelationshipResourceNotFoundException
{
LOG.debug(" Executing getNodeSizeDetails method ");
return sizeDetail.getNodeSizeDetails(nodeId,jobId);
return sizeDetails.getNodeSizeDetails(nodeId,jobId);
}
}

View File

@@ -996,7 +996,7 @@
</property>
</bean>
<bean id="sizeDetailImpl" class="org.alfresco.rest.api.impl.SizeDetailImpl">
<bean id="sizeDetailsImpl" class="org.alfresco.rest.api.impl.SizeDetailsImpl">
<property name="nodes" ref="nodes" />
<property name="nodeService" ref="NodeService" />
<property name="permissionService" ref="permissionService"/>
@@ -1005,12 +1005,12 @@
<property name="defaultItems" value="${alfresco.restApi.calculateFolderSize.items}"/>
</bean>
<bean id="sizeDetail" class="org.springframework.aop.framework.ProxyFactoryBean">
<bean id="sizeDetails" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>org.alfresco.rest.api.SizeDetail</value>
<value>org.alfresco.rest.api.SizeDetails</value>
</property>
<property name="target">
<ref bean="sizeDetailImpl" />
<ref bean="sizeDetailsImpl" />
</property>
<property name="interceptorNames">
<list>
@@ -1796,6 +1796,6 @@
<bean class="org.alfresco.rest.api.nodes.NodeSizeDetailsRelation">
<property name="nodes" ref="nodes" />
<property name="sizeDetail" ref="sizeDetail" />
<property name="sizeDetails" ref="sizeDetails" />
</bean>
</beans>

View File

@@ -25,7 +25,7 @@
*/
package org.alfresco;
import org.alfresco.rest.api.tests.NodeSizeDetailTest;
import org.alfresco.rest.api.tests.NodeSizeDetailsTest;
import org.alfresco.util.testing.category.DBTests;
import org.alfresco.util.testing.category.NonBuildTests;
import org.junit.experimental.categories.Categories;
@@ -77,7 +77,7 @@ import org.junit.runners.Suite;
org.alfresco.rest.api.tests.BufferedResponseTest.class,
org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class,
org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class,
org.alfresco.rest.api.tests.NodeSizeDetailTest.class
org.alfresco.rest.api.tests.NodeSizeDetailsTest.class
})
public class AppContext02TestSuite
{

View File

@@ -26,7 +26,7 @@
package org.alfresco;
import org.alfresco.repo.web.scripts.TestWebScriptRepoServer;
import org.alfresco.rest.api.impl.SizeDetailImplTest;
import org.alfresco.rest.api.impl.SizeDetailsImplTest;
import org.alfresco.util.testing.category.DBTests;
import org.alfresco.util.testing.category.NonBuildTests;
import org.junit.experimental.categories.Categories;
@@ -79,7 +79,7 @@ import org.junit.runners.Suite;
org.alfresco.rest.api.impl.CommentsImplUnitTest.class,
org.alfresco.rest.api.impl.DownloadsImplCheckArchiveStatusUnitTest.class,
org.alfresco.rest.api.impl.RestApiDirectUrlConfigUnitTest.class,
org.alfresco.rest.api.impl.SizeDetailImplTest.class
org.alfresco.rest.api.impl.SizeDetailsImplTest.class
})
public class AppContext04TestSuite
{

View File

@@ -29,7 +29,7 @@ import org.alfresco.repo.action.executer.NodeSizeDetailActionExecutor;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.NodeSizeDetail;
import org.alfresco.rest.api.model.NodeSizeDetails;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -42,18 +42,18 @@ import org.junit.Test;
import java.io.Serializable;
import java.util.Map;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Unit tests for {@link SizeDetailImpl} class.
* Unit tests for {@link SizeDetailsImpl} class.
*
*/
public class SizeDetailImplTest
public class SizeDetailsImplTest
{
private final static int DEFAULT_ITEMS = 1000;
private SizeDetailImpl sizeDetailImpl;
private SizeDetailsImpl sizeDetailsImpl;
private Nodes nodes;
private NodeService nodeService;
private ActionService actionService;
@@ -64,7 +64,7 @@ public class SizeDetailImplTest
@Before
public void setUp()
{
sizeDetailImpl = new SizeDetailImpl();
sizeDetailsImpl = new SizeDetailsImpl();
nodes = mock(Nodes.class);
nodeService = mock(NodeService.class);
PermissionService permissionService = mock(PermissionService.class);
@@ -72,19 +72,20 @@ public class SizeDetailImplTest
action = mock(Action.class);
SimpleCache<Serializable, Map<String, Object>> simpleCache = mock(SimpleCache.class);
sizeDetailImpl.setNodes(nodes);
sizeDetailImpl.setNodeService(nodeService);
sizeDetailImpl.setPermissionService(permissionService);
sizeDetailImpl.setActionService(actionService);
sizeDetailImpl.setSimpleCache(simpleCache);
sizeDetailImpl.setDefaultItems(DEFAULT_ITEMS);
sizeDetailsImpl.setNodes(nodes);
sizeDetailsImpl.setNodeService(nodeService);
sizeDetailsImpl.setPermissionService(permissionService);
sizeDetailsImpl.setActionService(actionService);
sizeDetailsImpl.setSimpleCache(simpleCache);
sizeDetailsImpl.setDefaultItems(DEFAULT_ITEMS);
}
@Test
public void calculateNodeSize()
public void calculateNodeSizeDetails()
{
String nodeName = "folderNode";
String nodeId = "node-id";
String jobId = "job-id";
NodeRef nodeRef = new NodeRef("protocol", "identifier", nodeId);
action.setTrackStatus(true);
action.setExecuteAsynchronously(true);
@@ -101,8 +102,13 @@ public class SizeDetailImplTest
when(nodes.getNode(nodeId)).thenReturn(node);
when(nodeService.getType(nodeRef)).thenReturn(TYPE_FOLDER);
when(actionService.createAction(NodeSizeDetailActionExecutor.NAME)).thenReturn(action);
NodeSizeDetail nodeSizeDetail = sizeDetailImpl.getNodeSizeDetails(nodeId,"");
assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code", nodeSizeDetail);
NodeSizeDetails requestSizeDetails = sizeDetailsImpl.generateNodeSizeDetailsRequest(nodeId);
assertNotNull("After executing POST/size-details, it will provide with 202 status code", requestSizeDetails);
NodeSizeDetails nodeSizeDetails = sizeDetailsImpl.getNodeSizeDetails(nodeId,jobId);
assertNotNull("After executing GET/size-details, it will provide with 200 status code", nodeSizeDetails);
}
}

View File

@@ -105,7 +105,7 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
private static final String URL_CHILDREN = "children";
private static final String URL_CONTENT = "content";
private static final String URL_CALCULATEFOLDERSIZE = "request-size-detail";
private static final String URL_CALCULATEFOLDERSIZE = "size-details";
protected static final String TYPE_CM_FOLDER = "cm:folder";
protected static final String TYPE_CM_CONTENT = "cm:content";
@@ -1122,9 +1122,14 @@ public abstract class AbstractBaseApiTest extends EnterpriseTestApi
restDauConfig.setEnabled(false);
}
protected String getCalculateFolderSizeUrl(String nodeId)
protected String generateNodeSizeDetailsUrl(String nodeId)
{
return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE;
}
protected String getNodeSizeDetailsUrl(String nodeId, String jobId)
{
return URL_NODES + "/" + nodeId + "/" + URL_CALCULATEFOLDERSIZE + "/" + jobId;
}
}

View File

@@ -26,16 +26,15 @@
package org.alfresco.rest.api.tests;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.NodeSizeDetails;
import org.alfresco.rest.api.model.Site;
import org.alfresco.rest.api.tests.client.HttpResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient;
import org.alfresco.rest.api.tests.client.data.ContentInfo;
import org.alfresco.rest.api.tests.client.data.Document;
import org.alfresco.rest.api.tests.client.data.UserInfo;
import org.alfresco.rest.api.tests.client.data.Node;
import org.alfresco.rest.api.tests.client.data.*;
import org.alfresco.rest.api.tests.util.RestApiUtil;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.json.simple.JSONObject;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
@@ -62,9 +61,9 @@ import static org.junit.Assert.assertNull;
*/
@FixMethodOrder (MethodSorters.NAME_ASCENDING)
@RunWith (JUnit4.class)
public class NodeSizeDetailTest extends AbstractBaseApiTest
public class NodeSizeDetailsTest extends AbstractBaseApiTest
{
private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailTest.class);
private static final Logger LOG = LoggerFactory.getLogger(NodeSizeDetailsTest.class);
private Site userOneN1Site;
private String folderId;
@@ -92,7 +91,7 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
}
catch (Exception e)
{
LOG.error("Exception occurred in NodeSizeDetailTest:addToDocumentLibrary {}", e.getMessage());
LOG.error("Exception occurred in NodeSizeDetailsTest:addToDocumentLibrary {}", e.getMessage());
}
return null;
}
@@ -115,11 +114,13 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
}
/**
* Test case for POST/request-size-detail, which calculates and retrieve size of a folder.
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/request-size-detail}
* Test case for POST/size-details, which request and calculates the size of a folder.
* GET/size-details, which retrieve the SizeDetails of the folder Node.
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details}
* {@literal <host>:<port>/alfresco/api/<networkId>/public/alfresco/versions/1/nodes/<nodeId>/size-details/<jobId>}
*/
@Test
public void testPostAndGetFolderSize() throws Exception
public void testPostAndGetFolderSizeDetails() throws Exception
{
// Prepare parameters
Map<String, String> params = new HashMap<>();
@@ -127,14 +128,19 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
params.put("maxItems", "1000");
// Perform POST request
HttpResponse postResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 202);
HttpResponse postResponse = post(generateNodeSizeDetailsUrl(folderId), toJsonAsStringNonNull(params), 202);
assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse());
assertNotNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse());
HttpResponse getResponse = post(getCalculateFolderSizeUrl(folderId), toJsonAsStringNonNull(params), 200);
String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry"));
assertNotNull("In response, JobId should be present", jobId);
HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200);
assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse());
String getJsonResponse = String.valueOf(getResponse.getJsonResponse());
assertNotNull("JSON response should not be null", getJsonResponse);
assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status"));
}
@@ -168,7 +174,7 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
assertEquals(500, nodes.size());
//Start Time before triggering POST/calculate-folder-size API
//Start Time before triggering POST/size-details API
LocalTime expectedTime = LocalTime.now().plusSeconds(5);
// Prepare parameters.
@@ -176,18 +182,23 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
params.put("nodeId", folderId);
// Perform POST request
HttpResponse postResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 202);
HttpResponse postResponse = post(generateNodeSizeDetailsUrl(parentFolder), toJsonAsStringNonNull(params), 202);
assertNull("After executing POST/request-size-detail first time, it will provide null with 202 status code",postResponse.getJsonResponse());
assertNull("After executing POST/size-details first time, it will provide jobId with 202 status code",postResponse.getJsonResponse());
HttpResponse getResponse = post(getCalculateFolderSizeUrl(parentFolder), toJsonAsStringNonNull(params), 200);
String jobId = NodeSizeDetails.parseJson((JSONObject)postResponse.getJsonResponse().get("entry"));
assertNotNull("In response, JobId should be present", jobId);
HttpResponse getResponse = get(getNodeSizeDetailsUrl(folderId, jobId), params, 200);
assertNotNull("After executing GET/size-details, it will provide NodeSizeDetails with 200 status code",getResponse.getJsonResponse());
String getJsonResponse = String.valueOf(getResponse.getJsonResponse());
assertNotNull("JSON response should not be null", getJsonResponse);
assertTrue("We are not getting correct response "+getJsonResponse,getJsonResponse.contains("size") || getJsonResponse.contains("status"));
//current Time after executing GET/request-size-details
//current Time after executing GET/size-details
LocalTime actualTime = LocalTime.now();
assertTrue("Calculating folder node is taking time greater than 5 seconds ",actualTime.isBefore(expectedTime));
}
@@ -199,12 +210,12 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
public void testHTTPStatus() throws Exception
{
setRequestContext(null);
delete(getCalculateFolderSizeUrl(folderId), folderId, null, 401);
delete(generateNodeSizeDetailsUrl(folderId), folderId, null, 401);
setRequestContext(user1);
String folderName = "folder0" + System.currentTimeMillis();
HttpResponse responseForNotFound = post(getCalculateFolderSizeUrl(folderName), null, 404);
HttpResponse responseForNotFound = post(generateNodeSizeDetailsUrl(folderName), null, 404);
assertNotNull(responseForNotFound);
folderName = "folder1" + System.currentTimeMillis();
@@ -219,7 +230,7 @@ public class NodeSizeDetailTest extends AbstractBaseApiTest
params.put("maxItems", "1000");
// Perform POST request
HttpResponse responseForInvalidNode = post(getCalculateFolderSizeUrl(n1Id), toJsonAsStringNonNull(params), 422);
HttpResponse responseForInvalidNode = post(generateNodeSizeDetailsUrl(n1Id), toJsonAsStringNonNull(params), 422);
assertNotNull(responseForInvalidNode);
}