changed line endings for fileplan component api unit test

This commit is contained in:
Ana Bozianu
2016-11-01 11:55:09 +02:00
parent dd9602a507
commit 3abbd9d04b

View File

@@ -1,154 +1,154 @@
/* /*
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* - * -
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* - * -
* 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/>.
* #L% * #L%
*/ */
package org.alfresco.rm.rest.api.nodes; package org.alfresco.rm.rest.api.nodes;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.AlfMock;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.rest.api.model.Node; import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException; import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.rest.framework.resource.parameters.Parameters; import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse; import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.rm.rest.api.impl.RMNodesImpl; import org.alfresco.rm.rest.api.impl.RMNodesImpl;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.springframework.extensions.webscripts.servlet.FormData; import org.springframework.extensions.webscripts.servlet.FormData;
/** /**
* Unit Test class for FileplanComponentChildrenRelation. * Unit Test class for FileplanComponentChildrenRelation.
* *
* @author Silviu Dinuta * @author Silviu Dinuta
* @since 2.6 * @since 2.6
* *
*/ */
public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest public class FileplanComponentChildrenRelationUnitTest extends BaseUnitTest
{ {
@Mock @Mock
private RMNodesImpl mockedRMNodes; private RMNodesImpl mockedRMNodes;
@InjectMocks @InjectMocks
private FileplanComponentChildrenRelation filePlanComponentChildrenRelation; private FileplanComponentChildrenRelation filePlanComponentChildrenRelation;
@Before @Before
public void before() public void before()
{ {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
} }
@Test @Test
public void testReadAll() throws Exception public void testReadAll() throws Exception
{ {
Parameters mockedParameters = mock(Parameters.class); Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
filePlanComponentChildrenRelation.readAll(parentNodeRef.getId(), mockedParameters); filePlanComponentChildrenRelation.readAll(parentNodeRef.getId(), mockedParameters);
verify(mockedRMNodes, times(1)).listChildren(parentNodeRef.getId(), mockedParameters); verify(mockedRMNodes, times(1)).listChildren(parentNodeRef.getId(), mockedParameters);
} }
@Test @Test
public void testCreate() throws Exception public void testCreate() throws Exception
{ {
Parameters mockedParameters = mock(Parameters.class); Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
List<Node> nodeInfos = new ArrayList<Node>(); List<Node> nodeInfos = new ArrayList<Node>();
Node mokedNodeInfo = mock(Node.class); Node mokedNodeInfo = mock(Node.class);
nodeInfos.add(mokedNodeInfo); nodeInfos.add(mokedNodeInfo);
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters); filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
verify(mockedRMNodes, times(1)).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters); verify(mockedRMNodes, times(1)).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
} }
@Test @Test
public void testCreateOnRMSite() throws Exception public void testCreateOnRMSite() throws Exception
{ {
Parameters mockedParameters = mock(Parameters.class); Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
List<Node> nodeInfos = new ArrayList<Node>(); List<Node> nodeInfos = new ArrayList<Node>();
Node mokedNodeInfo = mock(Node.class); Node mokedNodeInfo = mock(Node.class);
nodeInfos.add(mokedNodeInfo); nodeInfos.add(mokedNodeInfo);
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true); when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
try try
{ {
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters); filePlanComponentChildrenRelation.create(parentNodeRef.getId(), nodeInfos, mockedParameters);
fail("Expected ecxeption as POST request is not allowed in RM site."); fail("Expected ecxeption as POST request is not allowed in RM site.");
} }
catch(PermissionDeniedException ex) catch(PermissionDeniedException ex)
{ {
assertEquals("POST request not allowed in RM site.", ex.getMsgId()); assertEquals("POST request not allowed in RM site.", ex.getMsgId());
} }
verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters); verify(mockedRMNodes, never()).createNode(parentNodeRef.getId(), nodeInfos.get(0), mockedParameters);
} }
public void testUpload() throws Exception public void testUpload() throws Exception
{ {
Parameters mockedParameters = mock(Parameters.class); Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
FormData mockedFormData = mock(FormData.class); FormData mockedFormData = mock(FormData.class);
WithResponse mockedWithResponse = mock(WithResponse.class); WithResponse mockedWithResponse = mock(WithResponse.class);
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse); filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
verify(mockedRMNodes, times(1)).upload(parentNodeRef.getId(), mockedFormData, mockedParameters); verify(mockedRMNodes, times(1)).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
} }
public void testUploadOnRMSite() throws Exception public void testUploadOnRMSite() throws Exception
{ {
Parameters mockedParameters = mock(Parameters.class); Parameters mockedParameters = mock(Parameters.class);
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService); NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
FormData mockedFormData = mock(FormData.class); FormData mockedFormData = mock(FormData.class);
WithResponse mockedWithResponse = mock(WithResponse.class); WithResponse mockedWithResponse = mock(WithResponse.class);
when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true); when(mockedRMNodes.isRMSite(parentNodeRef.getId())).thenReturn(true);
try try
{ {
filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse); filePlanComponentChildrenRelation.create(parentNodeRef.getId(), mockedFormData, mockedParameters, mockedWithResponse);
fail("Expected ecxeption as POST request is not allowed in RM site."); fail("Expected ecxeption as POST request is not allowed in RM site.");
} }
catch(PermissionDeniedException ex) catch(PermissionDeniedException ex)
{ {
assertEquals("POST request not allowed in RM site.", ex.getMsgId()); assertEquals("POST request not allowed in RM site.", ex.getMsgId());
} }
verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters); verify(mockedRMNodes, never()).upload(parentNodeRef.getId(), mockedFormData, mockedParameters);
} }
} }