Search in sources :

Example 1 with TransferTargetImpl

use of org.alfresco.repo.transfer.TransferTargetImpl in project alfresco-repository by Alfresco.

the class ScriptTransferServiceTest method testJSAPI.

// == Test the JavaScript API ==
@Test
public void testJSAPI() throws Exception {
    /**
     * Prepare some dummy data for tests
     */
    TransferTargetImpl dummyTarget = new TransferTargetImpl();
    dummyTarget.setName("dummyTarget");
    dummyTarget.setNodeRef(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "4"));
    Set<TransferTarget> dummyTargets = new HashSet<TransferTarget>();
    dummyTargets.add(dummyTarget);
    TransferService mockedTransferService = Mockito.mock(TransferService.class);
    scriptTransferService.setTransferService(mockedTransferService);
    // When the transfer method is called return a node ref - mocks a good call.
    // When the transfer method is called with a transfer name of exception - throw a transferException
    Mockito.when(mockedTransferService.transfer(Matchers.anyString(), Matchers.isA(TransferDefinition.class))).thenReturn(new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "123"));
    Mockito.when(mockedTransferService.transfer(Matchers.eq("exception"), Matchers.isA(TransferDefinition.class))).thenThrow(new TransferException("mocked transfer exception"));
    // When getTransferTarget called return a TransferTarget
    Mockito.when(mockedTransferService.getTransferTarget(Matchers.anyString())).thenReturn(dummyTarget);
    Mockito.when(mockedTransferService.getTransferTargets(Matchers.anyString())).thenReturn(dummyTargets);
    Mockito.when(mockedTransferService.getTransferTargets()).thenReturn(dummyTargets);
    // Execute the unit test script
    Map<String, Object> model = new HashMap<String, Object>(1);
    ScriptLocation location = new ClasspathScriptLocation("org/alfresco/repo/transfer/script/test_transferService.js");
    this.scriptService.executeScript(location, model);
}
Also used : HashMap(java.util.HashMap) TransferTarget(org.alfresco.service.cmr.transfer.TransferTarget) ScriptLocation(org.alfresco.service.cmr.repository.ScriptLocation) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) TransferDefinition(org.alfresco.service.cmr.transfer.TransferDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) TransferException(org.alfresco.service.cmr.transfer.TransferException) ClasspathScriptLocation(org.alfresco.repo.jscript.ClasspathScriptLocation) TransferService(org.alfresco.service.cmr.transfer.TransferService) TransferTargetImpl(org.alfresco.repo.transfer.TransferTargetImpl) HashSet(java.util.HashSet) Test(org.junit.Test) BaseAlfrescoSpringTest(org.alfresco.util.BaseAlfrescoSpringTest)

Aggregations

HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ClasspathScriptLocation (org.alfresco.repo.jscript.ClasspathScriptLocation)1 TransferTargetImpl (org.alfresco.repo.transfer.TransferTargetImpl)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 ScriptLocation (org.alfresco.service.cmr.repository.ScriptLocation)1 TransferDefinition (org.alfresco.service.cmr.transfer.TransferDefinition)1 TransferException (org.alfresco.service.cmr.transfer.TransferException)1 TransferService (org.alfresco.service.cmr.transfer.TransferService)1 TransferTarget (org.alfresco.service.cmr.transfer.TransferTarget)1 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)1 Test (org.junit.Test)1