mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Story: RM-1212 (As a records user I want to perform a records search, select multiple records/record folders from the results and add them all to a hold(s) I have permission to see so that I can easily discover and freeze relevant records)
Sub-tasks: * RM-1400 (Change the service so that all holds will be retrieved when adding multiple records/folders) * RM-1402 (Change the REST API so that all holds will be retrieved when adding multiple records/folders) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@65918 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -9,7 +9,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Base hold web script unit test.
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
@@ -19,7 +19,10 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
|
||||
protected NodeRef hold1NodeRef;
|
||||
protected NodeRef hold2NodeRef;
|
||||
protected List<NodeRef> holds;
|
||||
|
||||
protected List<NodeRef> records;
|
||||
protected List<NodeRef> recordFolders;
|
||||
protected List<NodeRef> filePlanComponents;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest#before()
|
||||
*/
|
||||
@@ -27,13 +30,22 @@ public abstract class BaseHoldWebScriptUnitTest extends BaseWebScriptUnitTest
|
||||
public void before()
|
||||
{
|
||||
super.before();
|
||||
|
||||
|
||||
// generate test holds
|
||||
hold1NodeRef = generateHoldNodeRef("hold1");
|
||||
hold2NodeRef = generateHoldNodeRef("hold2");
|
||||
|
||||
|
||||
// list of holds
|
||||
holds = new ArrayList<NodeRef>(2);
|
||||
Collections.addAll(holds, hold1NodeRef, hold2NodeRef);
|
||||
|
||||
// list of records
|
||||
records = Collections.singletonList(record);
|
||||
|
||||
// list of record folders
|
||||
recordFolders = Collections.singletonList(recordFolder);
|
||||
|
||||
// list of file plan components
|
||||
filePlanComponents = Collections.singletonList(filePlanComponent);
|
||||
}
|
||||
}
|
||||
|
@@ -13,34 +13,51 @@ import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
/**
|
||||
* Base hold web script with content unit test.
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebScriptUnitTest
|
||||
{
|
||||
{
|
||||
/**
|
||||
* Helper method to build JSON content to send to hold webscripts.
|
||||
*/
|
||||
protected String buildContent(NodeRef nodeRef, List<NodeRef> holds)
|
||||
protected String buildContent(List<NodeRef> nodeRefs, List<NodeRef> holds)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(255);
|
||||
builder.append("{");
|
||||
|
||||
if (nodeRef != null)
|
||||
|
||||
if (nodeRefs != null)
|
||||
{
|
||||
builder.append("'nodeRef':'").append(nodeRef.toString()).append("'");
|
||||
builder.append("'nodeRefs':[");
|
||||
|
||||
boolean bFirst = true;
|
||||
for (NodeRef nodeRef : nodeRefs)
|
||||
{
|
||||
if (bFirst == false)
|
||||
{
|
||||
builder.append(",");
|
||||
}
|
||||
else
|
||||
{
|
||||
bFirst = false;
|
||||
}
|
||||
|
||||
builder.append("'" + nodeRef.toString() + "'");
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
if (nodeRef != null && holds != null)
|
||||
|
||||
if (nodeRefs != null && holds != null)
|
||||
{
|
||||
builder.append(",");
|
||||
}
|
||||
|
||||
|
||||
if (holds != null)
|
||||
{
|
||||
builder.append("'holds':[");
|
||||
|
||||
|
||||
boolean bFirst = true;
|
||||
for (NodeRef hold : holds)
|
||||
{
|
||||
@@ -52,18 +69,18 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
{
|
||||
bFirst = false;
|
||||
}
|
||||
|
||||
|
||||
builder.append("'" + hold.toString() + "'");
|
||||
}
|
||||
|
||||
|
||||
builder.append("]");
|
||||
}
|
||||
|
||||
|
||||
builder.append("}");
|
||||
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when invalid JSON sent
|
||||
*/
|
||||
@@ -72,16 +89,16 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
public void sendInvalidJSON() throws Exception
|
||||
{
|
||||
// invalid JSON
|
||||
String content = "invalid JSON";
|
||||
|
||||
String content = "invalid JSON";
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when one of the holds doesn't exist.
|
||||
*/
|
||||
@@ -91,40 +108,40 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
{
|
||||
// setup interactions
|
||||
when(mockedNodeService.exists(eq(hold1NodeRef))).thenReturn(false);
|
||||
|
||||
// build content
|
||||
String content = buildContent(record, holds);
|
||||
|
||||
|
||||
// build content
|
||||
String content = buildContent(records, holds);
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected excpetion when the item being added to the hold
|
||||
* does not exist.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@Test
|
||||
public void nodeRefDoesNotExist() throws Exception
|
||||
{
|
||||
// setup interactions
|
||||
when(mockedNodeService.exists(eq(record))).thenReturn(false);
|
||||
|
||||
// build content
|
||||
String content = buildContent(record, holds);
|
||||
|
||||
|
||||
// build content
|
||||
String content = buildContent(records, holds);
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when hold information is missing from
|
||||
* sent JSON.
|
||||
@@ -134,16 +151,16 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
public void holdMissingFromContent() throws Exception
|
||||
{
|
||||
// build content
|
||||
String content = buildContent(record, null);
|
||||
|
||||
String content = buildContent(records, null);
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when noderef information is missing
|
||||
* from send JSON.
|
||||
@@ -154,15 +171,15 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
{
|
||||
// build content
|
||||
String content = buildContent(null, holds);
|
||||
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when adding an item to something
|
||||
* that isn't a hold.
|
||||
@@ -173,16 +190,16 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
{
|
||||
// build json content to send to server
|
||||
List<NodeRef> notAHold = Collections.singletonList(recordFolder);
|
||||
String content = buildContent(record, notAHold);
|
||||
|
||||
String content = buildContent(records, notAHold);
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
exception.expect(badRequest());
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test for expected exception when adding an item to a hold
|
||||
* that isn't a record or record folder.
|
||||
@@ -193,13 +210,13 @@ public abstract class BaseHoldWebScriptWithContentUnitTest extends BaseHoldWebSc
|
||||
{
|
||||
// build json content to send to server
|
||||
List<NodeRef> notAHold = Collections.singletonList(recordFolder);
|
||||
String content = buildContent(filePlanComponent, notAHold);
|
||||
|
||||
String content = buildContent(filePlanComponents, notAHold);
|
||||
|
||||
// expected exception
|
||||
exception.expect(WebScriptException.class);
|
||||
exception.expect(badRequest());
|
||||
|
||||
exception.expect(badRequest());
|
||||
|
||||
// execute web script
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
executeWebScript(Collections.EMPTY_MAP, content);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
/**
|
||||
* Hold ReST API POST implementation unit test.
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
@@ -40,10 +40,10 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
{
|
||||
/** classpath location of ftl template for web script */
|
||||
private static final String WEBSCRIPT_TEMPLATE = WEBSCRIPT_ROOT_RM + "hold.post.json.ftl";
|
||||
|
||||
|
||||
/** HoldPost webscript instance */
|
||||
protected @Spy @InjectMocks HoldPost webScript;
|
||||
|
||||
protected @Spy @InjectMocks HoldPost webScript;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScript()
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
{
|
||||
return webScript;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScriptTemplate()
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
{
|
||||
return WEBSCRIPT_TEMPLATE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that a record can be added to holds.
|
||||
*/
|
||||
@@ -70,16 +70,16 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
public void addRecordToHolds() throws Exception
|
||||
{
|
||||
// build json to send to server
|
||||
String content = buildContent(record, holds);
|
||||
|
||||
String content = buildContent(records, holds);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
assertNotNull(json);
|
||||
|
||||
|
||||
// verify that the record was added to the holds
|
||||
verify(mockedHoldService, times(1)).addToHolds(holds, record);
|
||||
verify(mockedHoldService, times(1)).addToHolds(holds, records);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that a record folder can be added to holds.
|
||||
*/
|
||||
@@ -88,13 +88,13 @@ public class HoldPostUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
public void addRecordFolderToHolds() throws Exception
|
||||
{
|
||||
// build json to send to server
|
||||
String content = buildContent(recordFolder, holds);
|
||||
|
||||
String content = buildContent(recordFolders, holds);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
assertNotNull(json);
|
||||
|
||||
|
||||
// verify that the record was added to the holds
|
||||
verify(mockedHoldService, times(1)).addToHolds(holds, recordFolder);
|
||||
verify(mockedHoldService, times(1)).addToHolds(holds, recordFolders);
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
|
||||
/**
|
||||
* Hold ReST API PUT implementation unit test.
|
||||
*
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
@@ -40,10 +40,10 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
{
|
||||
/** classpath location of ftl template for web script */
|
||||
private static final String WEBSCRIPT_TEMPLATE = WEBSCRIPT_ROOT_RM + "hold.put.json.ftl";
|
||||
|
||||
|
||||
/** HoldPut webscript instance */
|
||||
protected @Spy @InjectMocks HoldPut webScript;
|
||||
|
||||
protected @Spy @InjectMocks HoldPut webScript;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScript()
|
||||
*/
|
||||
@@ -52,7 +52,7 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
{
|
||||
return webScript;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest#getWebScriptTemplate()
|
||||
*/
|
||||
@@ -60,8 +60,8 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
protected String getWebScriptTemplate()
|
||||
{
|
||||
return WEBSCRIPT_TEMPLATE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that a record can be removed from holds.
|
||||
*/
|
||||
@@ -70,16 +70,16 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
public void removeRecordFromHolds() throws Exception
|
||||
{
|
||||
// build json to send to server
|
||||
String content = buildContent(record, holds);
|
||||
|
||||
String content = buildContent(records, holds);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
assertNotNull(json);
|
||||
|
||||
|
||||
// verify that the record was removed from holds
|
||||
verify(mockedHoldService, times(1)).removeFromHolds(holds, record);
|
||||
verify(mockedHoldService, times(1)).removeFromHolds(holds, records);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test that a record folder can be removed from holds.
|
||||
*/
|
||||
@@ -88,13 +88,13 @@ public class HoldPutUnitTest extends BaseHoldWebScriptWithContentUnitTest
|
||||
public void removeRecordFolderFromHolds() throws Exception
|
||||
{
|
||||
// build json to send to server
|
||||
String content = buildContent(recordFolder, holds);
|
||||
|
||||
String content = buildContent(recordFolders, holds);
|
||||
|
||||
// execute web script
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
JSONObject json = executeJSONWebScript(Collections.EMPTY_MAP, content);
|
||||
assertNotNull(json);
|
||||
|
||||
|
||||
// verify that the record was removed from holds
|
||||
verify(mockedHoldService, times(1)).removeFromHolds(holds, recordFolder);
|
||||
verify(mockedHoldService, times(1)).removeFromHolds(holds, recordFolders);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user