LocalNfsSecondaryStorageResource extends NfsSecondaryStorageResource { @Override public Answer executeRequest(Command cmd) { return super.executeRequest(cmd); } LocalNfsSecondaryStorageResource(); @Override void setParentPath(String path); @Override Answer executeRequest(Command cmd); @Override synchronized String getRootDir(String secUrl);  }
@Test public void testExecuteRequest() throws Exception { TemplateObjectTO template = Mockito.mock(TemplateObjectTO.class); NfsTO cacheStore = Mockito.mock(NfsTO.class); Mockito.when(cacheStore.getUrl()).thenReturn("nfs: SwiftTO swift = Mockito.mock(SwiftTO.class); Mockito.when(swift.getEndPoint()).thenReturn("https: Mockito.when(swift.getAccount()).thenReturn("cloudstack"); Mockito.when(swift.getUserName()).thenReturn("images"); Mockito.when(swift.getKey()).thenReturn("oxvELQaOD1U5_VyosGfA-wpZ7uBWEff-CUBGCM0u"); Mockito.when(template.getDataStore()).thenReturn(swift); Mockito.when(template.getPath()).thenReturn("template/1/1/"); Mockito.when(template.isRequiresHvm()).thenReturn(true); Mockito.when(template.getId()).thenReturn(1L); Mockito.when(template.getFormat()).thenReturn(Storage.ImageFormat.VHD); Mockito.when(template.getOrigUrl()).thenReturn("http: Mockito.when(template.getName()).thenReturn(UUID.randomUUID().toString()); Mockito.when(template.getObjectType()).thenReturn(DataObjectType.TEMPLATE); DownloadCommand cmd = new DownloadCommand(template, 100000L); cmd.setCacheStore(cacheStore); DownloadAnswer answer = (DownloadAnswer)resource.executeRequest(cmd); Assert.assertTrue(answer.getResult()); Mockito.when(template.getPath()).thenReturn(answer.getInstallPath()); Mockito.when(template.getDataStore()).thenReturn(swift); Mockito.when(cacheStore.getRole()).thenReturn(DataStoreRole.ImageCache); TemplateObjectTO destTemplate = Mockito.mock(TemplateObjectTO.class); Mockito.when(destTemplate.getPath()).thenReturn("template/1/2"); Mockito.when(destTemplate.getDataStore()).thenReturn(cacheStore); Mockito.when(destTemplate.getObjectType()).thenReturn(DataObjectType.TEMPLATE); CopyCommand cpyCmd = new CopyCommand(template, destTemplate, 10000, true); CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer)resource.executeRequest(cpyCmd); Assert.assertTrue(copyCmdAnswer.getResult()); ListTemplateCommand listCmd = new ListTemplateCommand(swift); ListTemplateAnswer listAnswer = (ListTemplateAnswer)resource.executeRequest(listCmd); Assert.assertTrue(listAnswer.getTemplateInfo().size() > 0); }