public void testCanDownloadScript() throws Exception {
RhqFacade rhqFacade = mock(RhqFacade.class);
RepoManagerRemote repoManager = mock(RepoManagerRemote.class);
ContentManagerRemote contentManager = mock(ContentManagerRemote.class);
when(rhqFacade.getProxy(RepoManagerRemote.class)).thenReturn(repoManager);
when(rhqFacade.getProxy(ContentManagerRemote.class)).thenReturn(contentManager);
when(repoManager.findReposByCriteria(any(Subject.class), any(RepoCriteria.class))).then(
new Answer<List<Repo>>() {
@Override
public List<Repo> answer(InvocationOnMock invocation) throws Throwable {
RepoCriteria crit = (RepoCriteria) invocation.getArguments()[1];
//this is so wrong...
Field f = RepoCriteria.class.getDeclaredField("filterName");
f.setAccessible(true);
String name = (String) f.get(crit);
if (CORRECT_REPO_NAME.equals(name)) {
Repo repo = new Repo(CORRECT_REPO_NAME);
repo.setId(CORRECT_REPO_ID);
PageList<Repo> ret = new PageList<Repo>(PageControl.getUnlimitedInstance());
ret.add(repo);
return ret;
} else {
return new PageList<Repo>(PageControl.getUnlimitedInstance());
}
}
});
when(contentManager.findPackagesWithLatestVersion(any(Subject.class), any(PackageCriteria.class))).then(
new Answer<List<PackageAndLatestVersionComposite>>() {
@Override
public List<PackageAndLatestVersionComposite> answer(InvocationOnMock invocation) throws Throwable {
PackageCriteria crit = (PackageCriteria) invocation.getArguments()[1];