Package org.rhq.enterprise.server.content

Examples of org.rhq.enterprise.server.content.RepoManagerRemote


    private static final int CORRECT_PACKAGE_VERSION_ID = 2;

    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];

                    //this is so wrong...
                    Field f = PackageCriteria.class.getDeclaredField("filterName");
                    f.setAccessible(true);
                    String name = (String) f.get(crit);

                    if (CORRECT_PACKAGE_NAME.equals(name)) {
                        PackageAndLatestVersionComposite composite = new PackageAndLatestVersionComposite();

                        composite
                            .setGeneralPackage(new org.rhq.core.domain.content.Package(CORRECT_PACKAGE_NAME, null));

                        PackageVersion pv = new PackageVersion();
                        pv.setId(CORRECT_PACKAGE_VERSION_ID);

                        composite.setLatestPackageVersion(pv);

                        PageList<PackageAndLatestVersionComposite> ret = new PageList<PackageAndLatestVersionComposite>(
                            PageControl.getUnlimitedInstance());
                        ret.add(composite);
                        return ret;
                    } else {
                        return new PageList<PackageAndLatestVersionComposite>(PageControl.getUnlimitedInstance());
                    }
                }
            });

        when(repoManager.getPackageVersionBytes(any(Subject.class), anyInt(), anyInt())).then(
            new Answer<byte[]>() {
                @Override
                public byte[] answer(InvocationOnMock invocation) throws Throwable {
                    int repoId = (Integer) invocation.getArguments()[1];
                    int packageId = (Integer) invocation.getArguments()[2];
View Full Code Here


        String repoName = path.substring(0, slashIdx);
        String scriptName = path.substring(slashIdx + 1);

        try {
            final RepoManagerRemote repoManager = rhqFacade.getProxy(RepoManagerRemote.class);

            final RepoCriteria repoCrit = new RepoCriteria();
            repoCrit.addFilterName(repoName);

            //Use CriteriaQuery to automatically chunk/page through criteria query results
            CriteriaQueryExecutor<Repo, RepoCriteria> queryExecutor = new CriteriaQueryExecutor<Repo, RepoCriteria>() {
                @Override
                public PageList<Repo> execute(RepoCriteria criteria) {
                    return repoManager.findReposByCriteria(rhqFacade.getSubject(), repoCrit);
                }
            };

            CriteriaQuery<Repo, RepoCriteria> repos = new CriteriaQuery<Repo, RepoCriteria>(repoCrit, queryExecutor);

            if (!repos.iterator().hasNext()) {
                return null;
            }

            final ContentManagerRemote contentManager = rhqFacade.getProxy(ContentManagerRemote.class);

            for (Repo repo : repos) {
                final PackageCriteria pCrit = new PackageCriteria();
                pCrit.addFilterName(scriptName);
                pCrit.addFilterRepoId(repo.getId());

                //Use CriteriaQuery to automatically chunk/page through criteria query results
                CriteriaQueryExecutor<PackageAndLatestVersionComposite, PackageCriteria> pQueryExecutor = new CriteriaQueryExecutor<PackageAndLatestVersionComposite, PackageCriteria>() {
                    @Override
                    public PageList<PackageAndLatestVersionComposite> execute(PackageCriteria criteria) {
                        return contentManager.findPackagesWithLatestVersion(rhqFacade.getSubject(), pCrit);
                    }
                };

                CriteriaQuery<PackageAndLatestVersionComposite, PackageCriteria> pvs = new CriteriaQuery<PackageAndLatestVersionComposite, PackageCriteria>(
                    pCrit, pQueryExecutor);

                //                if (!pvs.iterator().hasNext()) {
                if (pvs.iterator().hasNext()) {
                    PackageAndLatestVersionComposite pv = pvs.iterator().next();

                    byte[] bytes = repoManager.getPackageVersionBytes(rhqFacade.getSubject(), repo.getId(), pv
                        .getLatestPackageVersion().getId());

                    return new InputStreamReader(new ByteArrayInputStream(bytes), Charset.forName("UTF-8"));
                }
            }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.content.RepoManagerRemote

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.