Changed line endings for RM site test files

This commit is contained in:
Ana Bozianu
2016-10-31 15:08:31 +02:00
parent 6e1e6e9d9f
commit fab6126db0
2 changed files with 652 additions and 652 deletions

View File

@@ -1,332 +1,332 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.impl;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.rest.api.impl.SiteImportPackageHandler;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rm.rest.api.model.RMSite;
import org.alfresco.rm.rest.api.model.RMSiteCompliance;
import org.alfresco.rm.rest.api.model.SiteUpdate;
import org.alfresco.service.cmr.favourites.FavouritesService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.view.ImporterBinding;
import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Unit Test class for RMSitesImpl.
*
* @author Silviu Dinuta
* @since 2.6
*
*/
public class RMSitesImplUnitTest extends BaseUnitTest
{
private static final String RM_SITE_TITLE_AFTER_UPDATE = "Updated Title";
private static final String RM_SITE_DESCRIPTION_AFTER_UPDATE = "Updated Description";
private static final String RM_SITE_ID = "rm";
private static final String RM_SITE_MANAGER_ROLE = "SiteManager";
private static final String RM_SITE_TITLE = "RM Site Title";
private static final String RM_SITE_DESCRIPTION = "RM Site Description";
private static final String RM_SITE_PRESET = "rm-site-dashboard";
private static final String PARAM_SKIP_ADDTOFAVORITES = "skipAddToFavorites";
@InjectMocks
private RMSitesImpl rmSitesImpl;
@Mock
private SiteService mockedSiteService;
@Mock
AuthenticationUtil mockAuthenticationUtil;
@Mock
private ImporterService mockedImporterService;
@Mock
private FavouritesService mockedFavouritesService;
@Before
public void before()
{
MockitoAnnotations.initMocks(this);
}
@Test
public void createRMStandardSite() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call createRMSite method
RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
//check siteService.createSite parameters
ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
assertEquals(RM_SITE_ID, idCaptor.getValue());
assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
assertEquals(RecordsManagementModel.TYPE_RM_SITE, siteTypeCaptor.getValue());
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, times(1)).addFavourite(any(String.class), any(NodeRef.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.STANDARD, createdRMSite.getCompliance());
assertEquals(null, createdRMSite.getRole());
assertEquals(RM_SITE_ID, createdRMSite.getId());
assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
@Test
public void createRMDOD5015Site() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
toCreate.setCompliance(RMSiteCompliance.DOD5015);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call createRMSite method
RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
//check siteService.createSite parameters
ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
assertEquals(RM_SITE_ID, idCaptor.getValue());
assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
assertEquals(DOD5015Model.TYPE_DOD_5015_SITE, siteTypeCaptor.getValue());
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, times(1)).addFavourite(any(String.class), any(NodeRef.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.DOD5015, createdRMSite.getCompliance());
assertEquals(null, createdRMSite.getRole());
assertEquals(RM_SITE_ID, createdRMSite.getId());
assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
@Test
public void createRMSiteWithSkipAddToFavouritesParameter() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
when(mockedParameters.getParameter(PARAM_SKIP_ADDTOFAVORITES)).thenReturn(Boolean.toString(true));
//call createRMSite method
rmSitesImpl.createRMSite(toCreate, mockedParameters);
verify(mockedSiteService, times(1)).createSite(RM_SITE_PRESET, RM_SITE_ID, RM_SITE_TITLE, RM_SITE_DESCRIPTION, SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, never()).addFavourite(any(String.class), any(NodeRef.class));
}
@Test
public void updateRMSite() throws Exception
{
String siteId = RM_SITE_ID;
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
//mock SiteInfo
when(mockedSiteInfo.getShortName()).thenReturn(siteId);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION)
.thenReturn(RM_SITE_DESCRIPTION_AFTER_UPDATE);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE)
.thenReturn(RM_SITE_TITLE_AFTER_UPDATE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedNodeService.getType(siteNodeRef)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
when(mockedSiteService.getSite(siteId)).thenReturn(mockedSiteInfo);
when(mockedSiteService.getMembersRole(eq(siteId), any(String.class))).thenReturn(RM_SITE_MANAGER_ROLE);
//mock UpdateSite
SiteUpdate mockedSiteUpdate= mock(SiteUpdate.class);
when(mockedSiteUpdate.getDescription()).thenReturn(RM_SITE_DESCRIPTION_AFTER_UPDATE);
when(mockedSiteUpdate.getTitle()).thenReturn(RM_SITE_TITLE_AFTER_UPDATE);
when(mockedSiteUpdate.getVisibility()).thenReturn(null);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call updateRMSite method
RMSite updatedRMSite = rmSitesImpl.updateRMSite(siteId, mockedSiteUpdate, mockedParameters);
//check if the new title is set to siteInfo
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
verify(mockedSiteInfo, times(1)).setTitle(titleCaptor.capture());
assertEquals(RM_SITE_TITLE_AFTER_UPDATE, titleCaptor.getValue());
//check that new description is set to siteInfo
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
verify(mockedSiteInfo, times(1)).setDescription(descriptionCaptor.capture());
assertEquals(RM_SITE_DESCRIPTION_AFTER_UPDATE, descriptionCaptor.getValue());
//check that site visibility is not changed
verify(mockedSiteInfo, never()).setVisibility(any(SiteVisibility.class));
//check that updateSite is called
verify(mockedSiteService, times(1)).updateSite(any(SiteInfo.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.STANDARD, updatedRMSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, updatedRMSite.getRole());
assertEquals(siteId, updatedRMSite.getId());
assertEquals(siteNodeRef.getId(), updatedRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION_AFTER_UPDATE, updatedRMSite.getDescription());
assertEquals(RM_SITE_TITLE_AFTER_UPDATE, updatedRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, updatedRMSite.getVisibility());
}
@Test
public void getRMSite() throws Exception
{
String siteId = RM_SITE_ID;
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(siteId);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedNodeService.getType(siteNodeRef)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
when(mockedSiteService.getSite(siteId)).thenReturn(mockedSiteInfo);
when(mockedSiteService.getMembersRole(eq(siteId), any(String.class))).thenReturn(RM_SITE_MANAGER_ROLE);
//STANDARD compliance
RMSite rmSite = rmSitesImpl.getRMSite(siteId);
assertEquals(RMSiteCompliance.STANDARD, rmSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
assertEquals(siteId, rmSite.getId());
assertEquals(siteNodeRef.getId(), rmSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
assertEquals(RM_SITE_TITLE, rmSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
//DOD5015 compliance
when(mockedNodeService.getType(siteNodeRef)).thenReturn(DOD5015Model.TYPE_DOD_5015_SITE);
rmSite = rmSitesImpl.getRMSite(siteId);
assertEquals(RMSiteCompliance.DOD5015, rmSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
assertEquals(siteId, rmSite.getId());
assertEquals(siteNodeRef.getId(), rmSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
assertEquals(RM_SITE_TITLE, rmSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
}
}
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.impl;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.rest.api.impl.SiteImportPackageHandler;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rm.rest.api.model.RMSite;
import org.alfresco.rm.rest.api.model.RMSiteCompliance;
import org.alfresco.rm.rest.api.model.SiteUpdate;
import org.alfresco.service.cmr.favourites.FavouritesService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.service.cmr.view.ImporterBinding;
import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.namespace.QName;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Unit Test class for RMSitesImpl.
*
* @author Silviu Dinuta
* @since 2.6
*
*/
public class RMSitesImplUnitTest extends BaseUnitTest
{
private static final String RM_SITE_TITLE_AFTER_UPDATE = "Updated Title";
private static final String RM_SITE_DESCRIPTION_AFTER_UPDATE = "Updated Description";
private static final String RM_SITE_ID = "rm";
private static final String RM_SITE_MANAGER_ROLE = "SiteManager";
private static final String RM_SITE_TITLE = "RM Site Title";
private static final String RM_SITE_DESCRIPTION = "RM Site Description";
private static final String RM_SITE_PRESET = "rm-site-dashboard";
private static final String PARAM_SKIP_ADDTOFAVORITES = "skipAddToFavorites";
@InjectMocks
private RMSitesImpl rmSitesImpl;
@Mock
private SiteService mockedSiteService;
@Mock
AuthenticationUtil mockAuthenticationUtil;
@Mock
private ImporterService mockedImporterService;
@Mock
private FavouritesService mockedFavouritesService;
@Before
public void before()
{
MockitoAnnotations.initMocks(this);
}
@Test
public void createRMStandardSite() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call createRMSite method
RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
//check siteService.createSite parameters
ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
assertEquals(RM_SITE_ID, idCaptor.getValue());
assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
assertEquals(RecordsManagementModel.TYPE_RM_SITE, siteTypeCaptor.getValue());
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, times(1)).addFavourite(any(String.class), any(NodeRef.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.STANDARD, createdRMSite.getCompliance());
assertEquals(null, createdRMSite.getRole());
assertEquals(RM_SITE_ID, createdRMSite.getId());
assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
@Test
public void createRMDOD5015Site() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
toCreate.setCompliance(RMSiteCompliance.DOD5015);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call createRMSite method
RMSite createdRMSite = rmSitesImpl.createRMSite(toCreate, mockedParameters);
//check siteService.createSite parameters
ArgumentCaptor<String> sitePresetCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> idCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<SiteVisibility> visibilityCaptor = ArgumentCaptor.forClass(SiteVisibility.class);
ArgumentCaptor<QName> siteTypeCaptor = ArgumentCaptor.forClass(QName.class);
verify(mockedSiteService, times(1)).createSite(sitePresetCaptor.capture(), idCaptor.capture(), titleCaptor.capture(), descriptionCaptor.capture(), visibilityCaptor.capture(), siteTypeCaptor.capture());
assertEquals(RM_SITE_PRESET, sitePresetCaptor.getValue());
assertEquals(RM_SITE_ID, idCaptor.getValue());
assertEquals(RM_SITE_TITLE, titleCaptor.getValue());
assertEquals(RM_SITE_DESCRIPTION, descriptionCaptor.getValue());
assertEquals(SiteVisibility.PUBLIC, visibilityCaptor.getValue());
assertEquals(DOD5015Model.TYPE_DOD_5015_SITE, siteTypeCaptor.getValue());
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, times(1)).addFavourite(any(String.class), any(NodeRef.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.DOD5015, createdRMSite.getCompliance());
assertEquals(null, createdRMSite.getRole());
assertEquals(RM_SITE_ID, createdRMSite.getId());
assertEquals(siteNodeRef.getId(), createdRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, createdRMSite.getDescription());
assertEquals(RM_SITE_TITLE, createdRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, createdRMSite.getVisibility());
}
@Test
public void createRMSiteWithSkipAddToFavouritesParameter() throws Exception
{
RMSite toCreate = new RMSite();
toCreate.setTitle(RM_SITE_TITLE);
toCreate.setDescription(RM_SITE_DESCRIPTION);
//mocked SiteInfo
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(RM_SITE_ID);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedSiteService.createSite(any(String.class), any(String.class), any(String.class), any(String.class), any(SiteVisibility.class), any(QName.class))).thenReturn(mockedSiteInfo);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
when(mockedParameters.getParameter(PARAM_SKIP_ADDTOFAVORITES)).thenReturn(Boolean.toString(true));
//call createRMSite method
rmSitesImpl.createRMSite(toCreate, mockedParameters);
verify(mockedSiteService, times(1)).createSite(RM_SITE_PRESET, RM_SITE_ID, RM_SITE_TITLE, RM_SITE_DESCRIPTION, SiteVisibility.PUBLIC, RecordsManagementModel.TYPE_RM_SITE);
verify(mockedImporterService, times(1)).importView(any(SiteImportPackageHandler.class), any(Location.class), any(ImporterBinding.class), eq(null));
verify(mockedSiteService, times(1)).createContainer(RM_SITE_ID, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
verify(mockedFavouritesService, never()).addFavourite(any(String.class), any(NodeRef.class));
}
@Test
public void updateRMSite() throws Exception
{
String siteId = RM_SITE_ID;
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
//mock SiteInfo
when(mockedSiteInfo.getShortName()).thenReturn(siteId);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION)
.thenReturn(RM_SITE_DESCRIPTION_AFTER_UPDATE);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE)
.thenReturn(RM_SITE_TITLE_AFTER_UPDATE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedNodeService.getType(siteNodeRef)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
when(mockedSiteService.getSite(siteId)).thenReturn(mockedSiteInfo);
when(mockedSiteService.getMembersRole(eq(siteId), any(String.class))).thenReturn(RM_SITE_MANAGER_ROLE);
//mock UpdateSite
SiteUpdate mockedSiteUpdate= mock(SiteUpdate.class);
when(mockedSiteUpdate.getDescription()).thenReturn(RM_SITE_DESCRIPTION_AFTER_UPDATE);
when(mockedSiteUpdate.getTitle()).thenReturn(RM_SITE_TITLE_AFTER_UPDATE);
when(mockedSiteUpdate.getVisibility()).thenReturn(null);
//mock Parameters
Parameters mockedParameters = mock(Parameters.class);
//call updateRMSite method
RMSite updatedRMSite = rmSitesImpl.updateRMSite(siteId, mockedSiteUpdate, mockedParameters);
//check if the new title is set to siteInfo
ArgumentCaptor<String> titleCaptor = ArgumentCaptor.forClass(String.class);
verify(mockedSiteInfo, times(1)).setTitle(titleCaptor.capture());
assertEquals(RM_SITE_TITLE_AFTER_UPDATE, titleCaptor.getValue());
//check that new description is set to siteInfo
ArgumentCaptor<String> descriptionCaptor = ArgumentCaptor.forClass(String.class);
verify(mockedSiteInfo, times(1)).setDescription(descriptionCaptor.capture());
assertEquals(RM_SITE_DESCRIPTION_AFTER_UPDATE, descriptionCaptor.getValue());
//check that site visibility is not changed
verify(mockedSiteInfo, never()).setVisibility(any(SiteVisibility.class));
//check that updateSite is called
verify(mockedSiteService, times(1)).updateSite(any(SiteInfo.class));
//verify returned values for RM site are the right ones
assertEquals(RMSiteCompliance.STANDARD, updatedRMSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, updatedRMSite.getRole());
assertEquals(siteId, updatedRMSite.getId());
assertEquals(siteNodeRef.getId(), updatedRMSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION_AFTER_UPDATE, updatedRMSite.getDescription());
assertEquals(RM_SITE_TITLE_AFTER_UPDATE, updatedRMSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, updatedRMSite.getVisibility());
}
@Test
public void getRMSite() throws Exception
{
String siteId = RM_SITE_ID;
SiteInfo mockedSiteInfo = mock(SiteInfo.class);
NodeRef siteNodeRef = AlfMock.generateNodeRef(mockedNodeService);
when(mockedSiteInfo.getShortName()).thenReturn(siteId);
when(mockedSiteInfo.getNodeRef()).thenReturn(siteNodeRef);
when(mockedSiteInfo.getDescription()).thenReturn(RM_SITE_DESCRIPTION);
when(mockedSiteInfo.getTitle()).thenReturn(RM_SITE_TITLE);
when(mockedSiteInfo.getVisibility()).thenReturn(SiteVisibility.PUBLIC);
when(mockedNodeService.getType(siteNodeRef)).thenReturn(RecordsManagementModel.TYPE_RM_SITE);
when(mockedSiteService.getSite(siteId)).thenReturn(mockedSiteInfo);
when(mockedSiteService.getMembersRole(eq(siteId), any(String.class))).thenReturn(RM_SITE_MANAGER_ROLE);
//STANDARD compliance
RMSite rmSite = rmSitesImpl.getRMSite(siteId);
assertEquals(RMSiteCompliance.STANDARD, rmSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
assertEquals(siteId, rmSite.getId());
assertEquals(siteNodeRef.getId(), rmSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
assertEquals(RM_SITE_TITLE, rmSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
//DOD5015 compliance
when(mockedNodeService.getType(siteNodeRef)).thenReturn(DOD5015Model.TYPE_DOD_5015_SITE);
rmSite = rmSitesImpl.getRMSite(siteId);
assertEquals(RMSiteCompliance.DOD5015, rmSite.getCompliance());
assertEquals(RM_SITE_MANAGER_ROLE, rmSite.getRole());
assertEquals(siteId, rmSite.getId());
assertEquals(siteNodeRef.getId(), rmSite.getGuid());
assertEquals(RM_SITE_DESCRIPTION, rmSite.getDescription());
assertEquals(RM_SITE_TITLE, rmSite.getTitle());
assertEquals(SiteVisibility.PUBLIC, rmSite.getVisibility());
}
}

View File

@@ -1,320 +1,320 @@
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.sites;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rm.rest.api.RMSites;
import org.alfresco.rm.rest.api.model.RMSite;
import org.alfresco.rm.rest.api.model.RMSiteCompliance;
import org.alfresco.rm.rest.api.model.SiteUpdate;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Unit Test class for RMSiteEntityResource.
*
* @author Silviu Dinuta
* @since 2.6
*/
public class RMSiteEntityResourceUnitTest extends BaseUnitTest
{
private static final String NON_RM_SITE_ID = "not_rm";
private static final String PERMANENT_PARAMETER = "permanent";
private static final String RM_SITE_ID = "rm";
private static final String RM_SITE_DESCRIPTION = "RM Site Description";
private static final String RM_SITE_TITLE = "RM Site Title";
@Mock
private RMSites mockedRMSites;
@InjectMocks
private RMSiteEntityResource rmSiteEntityResource;
@Before
public void before()
{
MockitoAnnotations.initMocks(this);
}
@Test
public void create() throws Exception
{
RMSite rmSite = new RMSite();
rmSite.setTitle(RM_SITE_TITLE);
rmSite.setId(RM_SITE_ID);
rmSite.setDescription(RM_SITE_DESCRIPTION);
rmSite.setCompliance(RMSiteCompliance.STANDARD);
List<RMSite> entity = new ArrayList<RMSite>();
Params parameters = mock(Params.class);
entity.add(rmSite);
when(mockedRMSites.createRMSite(rmSite, parameters)).thenReturn(rmSite);
List<RMSite> createdRMSites = rmSiteEntityResource.create(entity, parameters);
verify(mockedRMSites, times(1)).createRMSite(rmSite, parameters);
assertEquals("Created sites size should be 1.", 1, createdRMSites.size());
assertNotNull(createdRMSites.get(0));
assertEquals(rmSite, createdRMSites.get(0));
}
@Test
public void happyPathDelete() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(null);
rmSiteEntityResource.delete(siteId, parameters);
verify(mockedRMSites, times(1)).deleteSite(siteId, parameters);
}
@Test
public void deleteNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(null);
try
{
rmSiteEntityResource.delete(siteId, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("The Deletion is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).deleteSite(siteId, parameters);
}
@Test
public void deleteRMSiteWithPermanentParam() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(Boolean.toString(true));
try
{
rmSiteEntityResource.delete(siteId, parameters);
fail("Expected ecxeption as parameter permanent was present in the request.");
}
catch(InvalidArgumentException ex)
{
assertEquals("DELETE does not support parameter: permanent", ex.getMsgId());
}
verify(mockedRMSites, never()).deleteSite(siteId, parameters);
}
@Test
public void happyPathGet() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
rmSiteEntityResource.readById(siteId, parameters);
verify(mockedRMSites, times(1)).getRMSite(siteId);
}
@Test
public void getNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
try
{
rmSiteEntityResource.readById(siteId, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("GET is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).getRMSite(siteId);
}
@Test
public void happyPathUpdate() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
rmSiteEntityResource.update(siteId, site, parameters);
verify(mockedRMSites, times(1)).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("The Update is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteId() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setId("newSiteID");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site id cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: id", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteGuid() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setGuid("newGUID");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site guid cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: guid", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteRole() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setRole("newRole");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site role cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: role", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteCompliance() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setCompliance(RMSiteCompliance.STANDARD);
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site compliance cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: compliance", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteVisibility() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setVisibility(SiteVisibility.PRIVATE);
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site visibility cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: visibility", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
}
/*
* #%L
* Alfresco Records Management Module
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rm.rest.api.sites;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.resource.parameters.Params;
import org.alfresco.rm.rest.api.RMSites;
import org.alfresco.rm.rest.api.model.RMSite;
import org.alfresco.rm.rest.api.model.RMSiteCompliance;
import org.alfresco.rm.rest.api.model.SiteUpdate;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Unit Test class for RMSiteEntityResource.
*
* @author Silviu Dinuta
* @since 2.6
*/
public class RMSiteEntityResourceUnitTest extends BaseUnitTest
{
private static final String NON_RM_SITE_ID = "not_rm";
private static final String PERMANENT_PARAMETER = "permanent";
private static final String RM_SITE_ID = "rm";
private static final String RM_SITE_DESCRIPTION = "RM Site Description";
private static final String RM_SITE_TITLE = "RM Site Title";
@Mock
private RMSites mockedRMSites;
@InjectMocks
private RMSiteEntityResource rmSiteEntityResource;
@Before
public void before()
{
MockitoAnnotations.initMocks(this);
}
@Test
public void create() throws Exception
{
RMSite rmSite = new RMSite();
rmSite.setTitle(RM_SITE_TITLE);
rmSite.setId(RM_SITE_ID);
rmSite.setDescription(RM_SITE_DESCRIPTION);
rmSite.setCompliance(RMSiteCompliance.STANDARD);
List<RMSite> entity = new ArrayList<RMSite>();
Params parameters = mock(Params.class);
entity.add(rmSite);
when(mockedRMSites.createRMSite(rmSite, parameters)).thenReturn(rmSite);
List<RMSite> createdRMSites = rmSiteEntityResource.create(entity, parameters);
verify(mockedRMSites, times(1)).createRMSite(rmSite, parameters);
assertEquals("Created sites size should be 1.", 1, createdRMSites.size());
assertNotNull(createdRMSites.get(0));
assertEquals(rmSite, createdRMSites.get(0));
}
@Test
public void happyPathDelete() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(null);
rmSiteEntityResource.delete(siteId, parameters);
verify(mockedRMSites, times(1)).deleteSite(siteId, parameters);
}
@Test
public void deleteNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(null);
try
{
rmSiteEntityResource.delete(siteId, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("The Deletion is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).deleteSite(siteId, parameters);
}
@Test
public void deleteRMSiteWithPermanentParam() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
when(parameters.getParameter(PERMANENT_PARAMETER)).thenReturn(Boolean.toString(true));
try
{
rmSiteEntityResource.delete(siteId, parameters);
fail("Expected ecxeption as parameter permanent was present in the request.");
}
catch(InvalidArgumentException ex)
{
assertEquals("DELETE does not support parameter: permanent", ex.getMsgId());
}
verify(mockedRMSites, never()).deleteSite(siteId, parameters);
}
@Test
public void happyPathGet() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
rmSiteEntityResource.readById(siteId, parameters);
verify(mockedRMSites, times(1)).getRMSite(siteId);
}
@Test
public void getNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
try
{
rmSiteEntityResource.readById(siteId, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("GET is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).getRMSite(siteId);
}
@Test
public void happyPathUpdate() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
rmSiteEntityResource.update(siteId, site, parameters);
verify(mockedRMSites, times(1)).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateNonRMSite() throws Exception
{
String siteId = NON_RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as siteId was different than rm");
}
catch(InvalidParameterException ex)
{
assertEquals("The Update is supported only for siteId = rm.", ex.getMessage());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteId() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setId("newSiteID");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site id cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: id", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteGuid() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setGuid("newGUID");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site guid cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: guid", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteRole() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setRole("newRole");
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site role cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: role", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteCompliance() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setCompliance(RMSiteCompliance.STANDARD);
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site compliance cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: compliance", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
@Test
public void updateRMSiteVisibility() throws Exception
{
String siteId = RM_SITE_ID;
Params parameters = mock(Params.class);
RMSite site = new RMSite();
site.setTitle("New Title");
site.setDescription("New Description");
site.setVisibility(SiteVisibility.PRIVATE);
try
{
rmSiteEntityResource.update(siteId, site, parameters);
fail("Expected ecxeption as rm site visibility cannot be changed.");
}
catch(InvalidArgumentException ex)
{
assertEquals("Site update does not support field: visibility", ex.getMsgId());
}
verify(mockedRMSites, never()).updateRMSite(any(String.class), any(SiteUpdate.class), any(Parameters.class));
}
}