public virtual void TestFailVerifyAccess() { SharedCacheUploader spied = CreateSpiedUploader(); Org.Mockito.Mockito.DoReturn(false).When(spied).VerifyAccess(); NUnit.Framework.Assert.IsFalse(spied.Call()); }
public virtual void TestSuccess() { Configuration conf = new Configuration(); conf.SetBoolean(YarnConfiguration.SharedCacheEnabled, true); LocalResource resource = Org.Mockito.Mockito.Mock <LocalResource>(); Path localPath = Org.Mockito.Mockito.Mock <Path>(); Org.Mockito.Mockito.When(localPath.GetName()).ThenReturn("foo.jar"); string user = "******"; SCMUploaderProtocol scmClient = Org.Mockito.Mockito.Mock <SCMUploaderProtocol>(); SCMUploaderNotifyResponse response = Org.Mockito.Mockito.Mock <SCMUploaderNotifyResponse >(); Org.Mockito.Mockito.When(response.GetAccepted()).ThenReturn(true); Org.Mockito.Mockito.When(scmClient.Notify(Matchers.IsA <SCMUploaderNotifyRequest>( ))).ThenReturn(response); FileSystem fs = Org.Mockito.Mockito.Mock <FileSystem>(); // return false when rename is called Org.Mockito.Mockito.When(fs.Rename(Matchers.IsA <Path>(), Matchers.IsA <Path>())).ThenReturn (true); FileSystem localFs = FileSystem.GetLocal(conf); SharedCacheUploader spied = CreateSpiedUploader(resource, localPath, user, conf, scmClient, fs, localFs); // stub verifyAccess() to return true Org.Mockito.Mockito.DoReturn(true).When(spied).VerifyAccess(); // stub getActualPath() Org.Mockito.Mockito.DoReturn(localPath).When(spied).GetActualPath(); // stub computeChecksum() Org.Mockito.Mockito.DoReturn("abcdef0123456789").When(spied).ComputeChecksum(Matchers.IsA <Path>()); // stub uploadFile() to return true Org.Mockito.Mockito.DoReturn(true).When(spied).UploadFile(Matchers.IsA <Path>(), Matchers.IsA <Path>()); // stub notifySharedCacheManager to return true Org.Mockito.Mockito.DoReturn(true).When(spied).NotifySharedCacheManager(Matchers.IsA <string>(), Matchers.IsA <string>()); NUnit.Framework.Assert.IsTrue(spied.Call()); }