Add active content to hold through rest api

This commit is contained in:
cagache
2019-08-09 12:07:24 +03:00
parent dded7766c7
commit 2f88cee847
14 changed files with 208 additions and 23 deletions

View File

@@ -53,6 +53,7 @@ import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
@@ -69,6 +70,7 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -91,6 +93,8 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
protected NodeRef hold2;
protected NodeRef activeContent;
@Mock (name="capabilityService")
protected CapabilityService mockedCapabilityService;
@Spy @InjectMocks HoldServiceImpl holdService;
@Before
@@ -104,6 +108,9 @@ public class HoldServiceImplUnitTest extends BaseUnitTest
hold = generateNodeRef(TYPE_HOLD);
hold2 = generateNodeRef(TYPE_HOLD);
when(mockedCapabilityService.getCapabilityAccessState(hold, RMPermissionModel.ADD_TO_HOLD)).thenReturn(AccessStatus.ALLOWED);
when(mockedCapabilityService.getCapabilityAccessState(hold2, RMPermissionModel.ADD_TO_HOLD)).thenReturn(AccessStatus.ALLOWED);
activeContent = generateNodeRef();
QName contentSubtype = QName.createQName("contentSubtype", "contentSubtype");
when(mockedNodeService.getType(activeContent)).thenReturn(contentSubtype);

View File

@@ -27,12 +27,17 @@
package org.alfresco.module.org_alfresco_module_rm.script.hold;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Base hold web script unit test.
@@ -45,10 +50,12 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
/** test holds */
protected NodeRef hold1NodeRef;
protected NodeRef hold2NodeRef;
protected NodeRef dmNodeRef;
protected List<NodeRef> holds;
protected List<NodeRef> records;
protected List<NodeRef> recordFolders;
protected List<NodeRef> filePlanComponents;
protected List<NodeRef> activeContents;
/**
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
@@ -62,6 +69,14 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
hold1NodeRef = generateHoldNodeRef("hold1");
hold2NodeRef = generateHoldNodeRef("hold2");
// generate active content
dmNodeRef = generateNodeRef(TYPE_CONTENT);
when(mockedExtendedPermissionService.hasPermission(dmNodeRef, PermissionService.WRITE)).thenReturn(AccessStatus.ALLOWED);
when(mockedDictionaryService.isSubClass(mockedNodeService.getType(dmNodeRef), ContentModel.TYPE_CONTENT)).thenReturn(true);
// list of active contents
activeContents = Collections.singletonList(dmNodeRef);
// list of holds
holds = new ArrayList<>(2);
Collections.addAll(holds, hold1NodeRef, hold2NodeRef);

View File

@@ -148,7 +148,7 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
}
/**
* Test for expected excpetion when the item being added to the hold
* Test for expected exception when the item being added to the hold
* does not exist.
*/
@SuppressWarnings("unchecked")
@@ -229,15 +229,14 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
/**
* Test for expected exception when adding an item to a hold
* that isn't a record or record folder.
* that isn't a record, record folder or active content.
*/
@SuppressWarnings("unchecked")
@Test
public void nodeRefIsNotARecordOrRecordFolder() throws Exception
public void nodeRefIsNotARecordOrRecordFolderOrActiveContent() throws Exception
{
// build json content to send to server
List<NodeRef> notAHold = Collections.singletonList(recordFolder);
String content = buildContent(filePlanComponents, notAHold);
String content = buildContent(filePlanComponents, holds);
// expected exception
exception.expect(WebScriptException.class);

View File

@@ -31,8 +31,11 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -106,4 +109,40 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
// verify that the record was added to the holds
verify(mockedHoldService, times(1)).addToHolds(holds, recordFolders);
}
/**
* Test that active content can be added to holds.
*/
@Test
public void addActiveContentToHolds() throws Exception
{
// build json to send to server
String content = buildContent(activeContents, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was added to the holds
verify(mockedHoldService, times(1)).addToHolds(holds, activeContents);
}
/**
* Test that active content can be added to holds along with records and record folders.
*/
@Test
public void addActiveContentAndRecordsAndRecordFoldersToHolds() throws Exception
{
List<NodeRef> items = new ArrayList<>(3);
Collections.addAll(items, dmNodeRef, record, recordFolder);
// build json to send to server
String content = buildContent(items, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was added to the holds along with records and record folders
verify(mockedHoldService, times(1)).addToHolds(holds, items);
}
}

View File

@@ -31,8 +31,11 @@ import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
import org.json.JSONObject;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -106,4 +109,40 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
// verify that the record was removed from holds
verify(mockedHoldService, times(1)).removeFromHolds(holds, recordFolders);
}
/**
* Test that active content can be removed from holds.
*/
@Test
public void removeActiveContentFromHolds() throws Exception
{
// build json to send to server
String content = buildContent(activeContents, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was removed from holds
verify(mockedHoldService, times(1)).removeFromHolds(holds, activeContents);
}
/**
* Test that active content can be removed from holds along with records and record folders.
*/
@Test
public void removeActiveContentAndRecordsAndRecordFoldersToHolds() throws Exception
{
List<NodeRef> items = new ArrayList<>(3);
Collections.addAll(items, dmNodeRef, record, recordFolder);
// build json to send to server
String content = buildContent(items, holds);
// execute web script
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
assertNotNull(json);
// verify that the active content was removed from holds along with records and record folders
verify(mockedHoldService, times(1)).removeFromHolds(holds, items);
}
}

View File

@@ -215,6 +215,60 @@ public class HoldsGetUnitTest extends BaseHoldWebScriptUnitTest
// check the JSON result
testForBothHolds(json);
}
/**
* Test the retrieval of holds that hold active content.
*/
@Test
public void getHoldsThatActiveContentIsHeldBy() throws Exception
{
// setup interactions
doReturn(holds).when(mockedHoldService).heldBy(dmNodeRef, true);
// setup web script parameters
Map<String, String> parameters = buildParameters
(
"store_type", filePlan.getStoreRef().getProtocol(),
"store_id", filePlan.getStoreRef().getIdentifier(),
"id", filePlan.getId(),
"itemNodeRef", dmNodeRef.toString()
);
// execute web script
JSONObject json = executeJSONWebScript(parameters);
assertNotNull(json);
// check the JSON result
testForBothHolds(json);
}
/**
* Test the retrieval of holds that do not hold active content.
*/
@Test
public void getHoldsThatActiveContentIsNotHeldBy() throws Exception
{
// setup interactions
doReturn(holds).when(mockedHoldService).heldBy(dmNodeRef, false);
// setup web script parameters
Map<String, String> parameters = buildParameters
(
"store_type", filePlan.getStoreRef().getProtocol(),
"store_id", filePlan.getStoreRef().getIdentifier(),
"id", filePlan.getId(),
"itemNodeRef", dmNodeRef.toString(),
"includedInHold", "false"
);
// execute web script
JSONObject json = executeJSONWebScript(parameters);
assertNotNull(json);
// check the JSON result
testForBothHolds(json);
}
public void getFileOnlyHolds() throws Exception
{