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);
}
Aggregations