mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4012: added unit test classes and implemented parts of the unit tests
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* #%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 org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
|
||||
/**
|
||||
* Unit Test class for RMNodesImpl.
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*/
|
||||
public class RMNodesImplUnitTest extends BaseUnitTest
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* #%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.nodes;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.rest.framework.webscripts.WithResponse;
|
||||
import org.alfresco.rm.rest.api.impl.RMNodesImpl;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.extensions.webscripts.servlet.FormData;
|
||||
|
||||
/**
|
||||
* Unit Test class for FileplanComponentChildrenRelation.
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*
|
||||
*/
|
||||
public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
|
||||
{
|
||||
|
||||
@Mock
|
||||
private RMNodesImpl mockedRMNodes;
|
||||
|
||||
@InjectMocks
|
||||
private FileplanComponentChildrenRelation filePlanComponentChildrenRelation;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAll() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
filePlanComponentChildrenRelation.readAll(parentNodeRef.getId(), mockedParameters);
|
||||
verify(mockedRMNodes, times(1)).listChildren(parentNodeRef.getId(), mockedParameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreate() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
|
||||
List<Node> nodeInfos = new ArrayList<Node>();
|
||||
Node mokedNodeInfo = mock(Node.class);
|
||||
nodeInfos.add(mokedNodeInfo);
|
||||
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
|
||||
verify(mockedRMNodes, times(1)).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateOnRMSite() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
|
||||
List<Node> nodeInfos = new ArrayList<Node>();
|
||||
Node mokedNodeInfo = mock(Node.class);
|
||||
nodeInfos.add(mokedNodeInfo);
|
||||
|
||||
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
|
||||
try
|
||||
{
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
|
||||
fail("Expected ecxeption as POST request is not allowed in RM site.");
|
||||
}
|
||||
catch(PermissionDeniedException ex)
|
||||
{
|
||||
assertEquals("POST request not allowed in RM site.", ex.getMsgId());
|
||||
}
|
||||
verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
|
||||
}
|
||||
|
||||
public void testUpload() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
FormData mockedFormData = mock(FormData.class);
|
||||
WithResponse mockedWithResponse = mock(WithResponse.class);
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
|
||||
verify(mockedRMNodes, times(1)).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
|
||||
}
|
||||
|
||||
public void testUploadOnRMSite() throws Exception
|
||||
{
|
||||
Parameters mockedParameters = mock(Parameters.class);
|
||||
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||
FormData mockedFormData = mock(FormData.class);
|
||||
WithResponse mockedWithResponse = mock(WithResponse.class);
|
||||
|
||||
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
|
||||
try
|
||||
{
|
||||
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
|
||||
fail("Expected ecxeption as POST request is not allowed in RM site.");
|
||||
}
|
||||
catch(PermissionDeniedException ex)
|
||||
{
|
||||
assertEquals("POST request not allowed in RM site.", ex.getMsgId());
|
||||
}
|
||||
verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* #%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.nodes;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
|
||||
import org.alfresco.rm.rest.api.impl.RMNodesImpl;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
/**
|
||||
* Unit Test class for FileplanComponentsEntityResource.
|
||||
*
|
||||
* @author Silviu Dinuta
|
||||
* @since 2.6
|
||||
*
|
||||
*/
|
||||
public class FileplanComponentsEntityResourceUnitTest extends BaseUnitTest
|
||||
{
|
||||
@Mock
|
||||
private RMNodesImpl mockedRMNodes;
|
||||
|
||||
@InjectMocks
|
||||
private FileplanComponentsEntityResource filePlanComponentsEntityResource;
|
||||
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadById() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user