mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
minor formating issue
This commit is contained in:
@@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.alfresco.repo.web.scripts.roles;
|
package org.alfresco.repo.web.scripts.roles;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
import static java.util.Collections.emptyMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
@@ -111,185 +111,187 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
||||||
@Mock
|
@Mock
|
||||||
private ContentStreamer contentStreamer;
|
private ContentStreamer contentStreamer;
|
||||||
|
|
||||||
/** test component */
|
/** test component */
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private DynamicAuthoritiesGet webScript;
|
private DynamicAuthoritiesGet webScript;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractWebScript getWebScript()
|
protected AbstractWebScript getWebScript()
|
||||||
{
|
{
|
||||||
return webScript;
|
return webScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getWebScriptTemplate()
|
protected String getWebScriptTemplate()
|
||||||
{
|
{
|
||||||
return "alfresco/templates/webscripts/org/alfresco/repository/roles/rm-dynamicauthorities.get.json.ftl";
|
return "alfresco/templates/webscripts/org/alfresco/repository/roles/rm-dynamicauthorities.get.json.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before test
|
* Before test
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Before
|
@Before
|
||||||
public void before()
|
public void before()
|
||||||
{
|
{
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
webScript.setNodeService(mockedNodeService);
|
webScript.setNodeService(mockedNodeService);
|
||||||
webScript.setPermissionService(mockedPermissionService);
|
webScript.setPermissionService(mockedPermissionService);
|
||||||
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
||||||
// setup retrying transaction helper
|
// setup retrying transaction helper
|
||||||
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
||||||
{
|
{
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||||
{
|
{
|
||||||
RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
|
RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
|
||||||
return callback.execute();
|
return callback.execute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper)
|
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper)
|
||||||
.<Object> doInTransaction(any(RetryingTransactionCallback.class), anyBoolean(), anyBoolean());
|
.<Object> doInTransaction(any(RetryingTransactionCallback.class), anyBoolean(), anyBoolean());
|
||||||
|
|
||||||
when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
|
when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
|
||||||
|
|
||||||
// max node id
|
// max node id
|
||||||
when(mockedPatchDAO.getMaxAdmNodeID()).thenReturn(500000L);
|
when(mockedPatchDAO.getMaxAdmNodeID()).thenReturn(500000L);
|
||||||
|
|
||||||
// aspect
|
// aspect
|
||||||
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(new Pair<Long, QName>(ASPECT_ID, ASPECT));
|
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(new Pair<Long, QName>(ASPECT_ID, ASPECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that there are no nodes with the extended security aspect When the action is executed Nothing happens
|
* Given that there are no nodes with the extended security aspect When the action is executed Nothing happens
|
||||||
*
|
* @throws Exception
|
||||||
* @throws Exception
|
*/
|
||||||
*/
|
@SuppressWarnings({ "unchecked" })
|
||||||
@SuppressWarnings({ "unchecked" })
|
@Test
|
||||||
@Test
|
public void noNodesWithExtendedSecurity() throws Exception
|
||||||
public void noNodesWithExtendedSecurity() throws Exception
|
{
|
||||||
{
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
.thenReturn(Collections.emptyList());
|
||||||
.thenReturn(Collections.emptyList());
|
|
||||||
|
// Set up parameters.
|
||||||
// Set up parameters.
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "3");
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "3");
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
assertNotNull(json);
|
||||||
assertNotNull(json);
|
String actualJSONString = json.toString();
|
||||||
String actualJSONString = json.toString();
|
|
||||||
|
// Check the JSON result using Jackson to allow easy equality testing.
|
||||||
// Check the JSON result using Jackson to allow easy equality testing.
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 0 records.\"}";
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 0 records.\"}";
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
|
||||||
|
|
||||||
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
verify(mockedNodeService, never()).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, never()).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
||||||
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
||||||
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
||||||
verify(mockedExtendedSecurityService, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
verify(mockedExtendedSecurityService, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that there are records with the extended security aspect When the action is executed Then the aspect is
|
* Given that there are records with the extended security aspect When the action is executed Then the aspect is
|
||||||
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API
|
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API
|
||||||
*
|
* @throws Exception
|
||||||
* @throws Exception
|
*/
|
||||||
*/
|
@SuppressWarnings("unchecked")
|
||||||
@SuppressWarnings("unchecked")
|
@Test
|
||||||
@Test
|
public void recordsWithExtendedSecurityAspect() throws Exception
|
||||||
public void recordsWithExtendedSecurityAspect() throws Exception
|
{
|
||||||
{
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
|
||||||
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
.thenReturn(ids)
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
assertNotNull(json);
|
assertNotNull(json);
|
||||||
String actualJSONString = json.toString();
|
String actualJSONString = json.toString();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
verify(mockedExtendedSecurityService, times(3)).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
||||||
|
verify(mockedExtendedSecurityService, times(3)).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
}
|
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Given that there are non-records with the extended security aspect When the web script is executed Then the
|
/**
|
||||||
* aspect is removed And the dynamic authorities permissions are cleared
|
* Given that there are non-records with the extended security aspect When the web script is executed Then the aspect is
|
||||||
*
|
* removed And the dynamic authorities permissions are cleared
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void nonRecordsWithExtendedSecurityAspect() throws Exception
|
public void nonRecordsWithExtendedSecurityAspect() throws Exception
|
||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(ids)
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
ids.stream().forEach((i) -> {
|
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
ids.stream().forEach((i) -> {
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
});
|
|
||||||
|
});
|
||||||
// Set up parameters.
|
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
// Set up parameters.
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
||||||
assertNotNull(json);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
String actualJSONString = json.toString();
|
assertNotNull(json);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
String actualJSONString = json.toString();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
|
||||||
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
verify(mockedExtendedSecurityService, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
}
|
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
||||||
|
verify(mockedExtendedSecurityService, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
@Test
|
}
|
||||||
public void missingBatchSizeParameter() throws Exception
|
|
||||||
{
|
@Test
|
||||||
|
public void missingBatchSizeParameter() throws Exception
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
executeJSONWebScript(emptyMap());
|
executeJSONWebScript(emptyMap());
|
||||||
@@ -300,15 +302,15 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is not provided then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is not provided then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidBatchSizeParameter() throws Exception
|
public void invalidBatchSizeParameter() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "dd");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "dd");
|
||||||
executeJSONWebScript(parameters);
|
executeJSONWebScript(parameters);
|
||||||
fail("Expected exception as parameter batchsize is invalid.");
|
fail("Expected exception as parameter batchsize is invalid.");
|
||||||
}
|
}
|
||||||
@@ -317,15 +319,15 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is invalid then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is invalid then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void batchSizeShouldBeGraterThanZero() throws Exception
|
public void batchSizeShouldBeGraterThanZero() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "0");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "0");
|
||||||
executeJSONWebScript(parameters);
|
executeJSONWebScript(parameters);
|
||||||
fail("Expected exception as parameter batchsize is not a number greater than 0.");
|
fail("Expected exception as parameter batchsize is not a number greater than 0.");
|
||||||
}
|
}
|
||||||
@@ -334,79 +336,81 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is not a number greater than 0 then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is not a number greater than 0 then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extendedSecurityAspectNotCreated() throws Exception
|
public void extendedSecurityAspectNotCreated() throws Exception
|
||||||
{
|
{
|
||||||
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(null);
|
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(null);
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "3");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "3");
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
assertNotNull(json);
|
assertNotNull(json);
|
||||||
String actualJSONString = json.toString();
|
String actualJSONString = json.toString();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"There where no records to be processed.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"There where no records to be processed.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception
|
public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception
|
||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l, 4l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l,4l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(ids)
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
ids.stream().forEach((i) -> {
|
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
ids.stream().forEach((i) -> {
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
});
|
|
||||||
|
});
|
||||||
// Set up parameters.
|
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "0");
|
// Set up parameters.
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "0");
|
||||||
assertNotNull(json);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
String actualJSONString = json.toString();
|
assertNotNull(json);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
String actualJSONString = json.toString();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 4 records.\"}";
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 4 records.\"}";
|
||||||
}
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
}
|
||||||
@Test
|
|
||||||
public void whenMaxProcessedRecordsIsMissingItDefaultsToBatchSize() throws Exception
|
@Test
|
||||||
{
|
public void whenMaxProcessedRecordsIsMissingItDefaultsToBatchSize() throws Exception
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList());
|
{
|
||||||
|
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList());
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
|
||||||
.thenReturn(Collections.emptyList());
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
|
.thenReturn(ids)
|
||||||
ids.stream().forEach((i) -> {
|
.thenReturn(Collections.emptyList());
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
ids.stream().forEach((i) -> {
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
});
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
|
||||||
// Set up parameters.
|
});
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "4");
|
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
// Set up parameters.
|
||||||
assertNotNull(json);
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "4");
|
||||||
String actualJSONString = json.toString();
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
assertNotNull(json);
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed first 4 records.\"}";
|
String actualJSONString = json.toString();
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
}
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed first 4 records.\"}";
|
||||||
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
@@ -414,7 +418,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
|
.thenReturn(ids)
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
|
Reference in New Issue
Block a user