Package org.rhq.core.domain.content

Examples of org.rhq.core.domain.content.Repo


                    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 {
View Full Code Here


            assert contentSource != null;
            contentSourceId = contentSource.getId();
            assert contentSourceId > 0;

            // create a repo
            Repo repo = new Repo("testRepo");
            repo = repoManager.createRepo(overlord, repo);
            repoId = repo.getId();

            // this report will add a mapping to PV->CS
            // we didn't set up any mappings like that yet - this will be the first one
            PackageSyncReport report = new PackageSyncReport();
            ContentProviderPackageDetailsKey key = new ContentProviderPackageDetailsKey("testCreateContentSourceFoo",
                "testCreateContentSourceVer", packageType1.getName(), architecture1.getName(), resourceType1.getName(),
                resourceType1.getPlugin());
            ContentProviderPackageDetails details = new ContentProviderPackageDetails(key);
            details.setLocation("dummy-location");
            details.setMetadata("dummy-metadata".getBytes());
            details.addResourceVersion("1.0.0");
            details.addResourceVersion("2.0.0");
            report.addNewPackage(details);
            Map<ContentProviderPackageDetailsKey, PackageVersionContentSource> previous;
            previous = new HashMap<ContentProviderPackageDetailsKey, PackageVersionContentSource>();

            // merge the report!
            RepoSyncResults results = new RepoSyncResults(repo);
            results = repoManager.persistRepoSyncResults(results);
            assert results != null;

            results = contentSourceManager.mergePackageSyncReport(contentSource, repo, report, previous, results);
            assert results != null;

            // Verify the product version was created
            getTransactionManager().begin();

            try {
                resourceType1 = em.find(ResourceType.class, resourceType1.getId());

                Query productVersionQuery = em.createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
                productVersionQuery.setParameter("resourceType", resourceType1);
                productVersionQuery.setParameter("version", "1.0.0");

                List productVersionList = productVersionQuery.getResultList();
                assert productVersionList.size() > 0 : "Could not find product version for 1.0.0";

                productVersionQuery = em.createNamedQuery(ProductVersion.QUERY_FIND_BY_RESOURCE_TYPE_AND_VERSION);
                productVersionQuery.setParameter("resourceType", resourceType1);
                productVersionQuery.setParameter("version", "2.0.0");

                productVersionList = productVersionQuery.getResultList();
                assert productVersionList.size() > 0 : "Could not find product version for 2.0.0";
            } finally {
                getTransactionManager().rollback();
            }

            // see that the resource sees no metadata yet - not subscribed yet
            pc = PageControl.getUnlimitedInstance();
            PageList<PackageVersionMetadataComposite> metadataList;
            metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
            assert metadataList != null;
            assert metadataList.size() == 0 : "-->" + metadataList;
            String metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
            assert metadataMd5 != null;
            assert metadataMd5.length() == 32 : "-->" + metadataMd5;
            assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;

            // just to make sure the MD5 for empty data is what we think it is...
            metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(Integer.MIN_VALUE); // should find no metadata at all
            assert metadataMd5 != null;
            assert metadataMd5.length() == 32 : "-->" + metadataMd5;
            assert metadataMd5.equals("d41d8cd98f00b204e9800998ecf8427e") : "-->" + metadataMd5;

            // add the content source's packages to the repo
            repoManager.addContentSourcesToRepo(overlord, repoId, new int[] { contentSourceId });

            // see the package versions have been assigned to the repo and content source
            List<PackageVersion> inRepo;
            List<PackageVersionContentSource> inContentSources;
            List<PackageVersionContentSource> inContentSource;

            pc = PageControl.getUnlimitedInstance();
            inRepo = repoManager.findPackageVersionsInRepo(overlord, repoId, pc);
            pc = PageControl.getUnlimitedInstance();
            inContentSources = contentSourceManager.getPackageVersionsFromContentSources(overlord,
                new int[] { contentSourceId }, pc);
            inContentSource = contentSourceManager.getPackageVersionsFromContentSource(overlord, contentSourceId, pc);
            assert inRepo != null;
            assert inContentSources != null;
            assert inContentSource != null;
            assert inRepo.size() == 1 : inRepo;
            assert inContentSources.size() == 1 : inContentSources;
            assert inContentSource.size() == 1 : inContentSource;

            // confirm that we didn't load the bits yet
            pc = PageControl.getUnlimitedInstance();
            List<PackageVersionContentSource> unloaded;
            unloaded = contentSourceManager.getUnloadedPackageVersionsFromContentSourceInRepo(overlord,
                contentSourceId, repoId, pc);
            assert unloaded != null;
            assert unloaded.size() == 1;

            // check the counts
            long pvccount = repoManager.getPackageVersionCountFromRepo(overlord, repo.getId());
            assert (pvccount == 1) : "-->" + pvccount;
            long pvcscount = contentSourceManager.getPackageVersionCountFromContentSource(overlord, contentSourceId);
            assert (pvcscount == 1) : "-->" + pvcscount;

            // subscribe the resource
            repoManager.subscribeResourceToRepos(overlord, resource1.getId(), new int[] { repoId });

            // confirm the resource is subscribed
            pc = PageControl.getUnlimitedInstance();
            metadataList = contentSourceManager.getPackageVersionMetadata(resource1.getId(), pc);
            assert metadataList != null;
            assert metadataList.size() == 1 : "-->" + metadataList;
            metadataMd5 = contentSourceManager.getResourceSubscriptionMD5(resource1.getId());
            assert metadataMd5 != null;
            assert metadataMd5.length() == 32 : "-->" + metadataMd5;

            // MD5 is based on the hash code of last modified time
            repo = repoManager.getRepo(overlord, repoId);
            long modifiedTimestamp = repo.getLastModifiedDate();
            Date modifiedDate = new Date(modifiedTimestamp);
            String datehash = Integer.toString(modifiedDate.hashCode());
            assert metadataMd5.equals(MessageDigestGenerator.getDigestString(datehash)) : "-->" + metadataMd5;

            repoManager.unsubscribeResourceFromRepos(overlord, resource1.getId(), new int[] { repoId });
View Full Code Here

            contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);
            contentSourceId = contentSource.getId();
            assert contentSourceId > 0;

            // create repo
            Repo repo = new Repo("testRepo");
            repo = repoManager.createRepo(overlord, repo);
            repoId = repo.getId();

            // just make sure there are no package versions yet
            inCS = contentSourceManager.getPackageVersionsFromContentSource(overlord, contentSourceId, pc);
            assert inCS != null;
            assert inCS.size() == 0 : inCS;
View Full Code Here

                if (repos != null) {
                    origsize = repos.size();
                }
                for (int i = 0; i < 10; i++) {
                    Random r = new Random(System.currentTimeMillis());
                    Repo repo = new Repo(r.nextLong() + "");
                    repoManager.createRepo(overlord, repo);
                }
                repos = repoManager.findRepos(overlord, new PageControl());

                assert repos.size() == (origsize + 10);
View Full Code Here

    public void createDeleteRepo() throws Exception {
        executeInTransaction(new TransactionCallback() {

            public void execute() throws Exception {

                Repo repo = new Repo("testCreateDeleteRepo");
                int id = repoManager.createRepo(overlord, repo).getId();
                Repo lookedUp = repoManager.getRepo(overlord, id);
                assert lookedUp != null;
                Repo lookedUp2 = repoManager.getRepoByName(lookedUp.getName()).get(0);
                assert lookedUp2 != null;
                assert id == lookedUp.getId();
                assert id == lookedUp2.getId();

                repoManager.deleteRepo(overlord, id);
                lookedUp = repoManager.getRepo(overlord, id);
                assert lookedUp == null;
            }
View Full Code Here

    public void createFindDeleteCandidateRepo() throws Exception {
        executeInTransaction(new TransactionCallback() {

            public void execute() throws Exception {

                Repo repo = new Repo("test create candidate repo");

                PageList<Repo> importedRepos = repoManager.findRepos(overlord, new PageControl());
                int origSize = 0;
                if (importedRepos != null) {
                    origSize = importedRepos.size();
                }

                // Test
                repo.setCandidate(true);
                repo = repoManager.createRepo(overlord, repo);

                // Verify
                try {
                    assert repo.isCandidate();

                    // Should not be returned from this call since it's a candidate repo
                    importedRepos = repoManager.findRepos(overlord, new PageControl());
                    assert importedRepos.size() == origSize;
                    assert repoManager.getRepo(overlord, repo.getId()) != null;
                } finally {
                    repoManager.deleteRepo(overlord, repo.getId());
                }
            }
        });
    }
View Full Code Here

            public void execute() throws Exception {

                EntityManager entityManager = getEntityManager();

                Repo repo = new Repo("repo1");
                Repo relatedRepo = new Repo("repo2");

                repo = repoManager.createRepo(overlord, repo);
                relatedRepo = repoManager.createRepo(overlord, relatedRepo);

                String relationshipTypeName = "testRelationshipType";
                RepoRelationshipType relationshipType = new RepoRelationshipType(relationshipTypeName);
                entityManager.persist(relationshipType);
                entityManager.flush();

                // Test
                repoManager.addRepoRelationship(overlord, repo.getId(), relatedRepo.getId(), relationshipTypeName);

                // Verify
                RepoCriteria repoCriteria = new RepoCriteria();
                repoCriteria.fetchRepoRepoGroups(true);
                repoCriteria.addFilterId(repo.getId());

                PageList<Repo> repoPageList = repoManager.findReposByCriteria(overlord, repoCriteria);
                assert repoPageList.size() == 1;

                Repo persistedRepo = repoPageList.get(0);
                Set<RepoRepoRelationship> relationships = persistedRepo.getRepoRepoRelationships();
                assert relationships.size() == 1;

                RepoRepoRelationship relationship = relationships.iterator().next();
                assert relationship.getRepoRepoRelationshipPK().getRepo().getName().equals("repo1");
                assert relationship.getRepoRepoRelationshipPK().getRepoRelationship().getRelatedRepo().getName()
View Full Code Here

                contentSourceMetadataManager.registerTypes(types); // this blows away any previous existing types
                ContentSource contentSource = new ContentSource("testGetSyncResultsListCS", type);
                contentSource = contentSourceManager.simpleCreateContentSource(overlord, contentSource);

                //   Create an imported (non-candidate) repo associated with the source
                Repo importedRepo = new Repo("imported repo");
                importedRepo.addContentSource(contentSource);
                importedRepo = repoManager.createRepo(overlord, importedRepo);

                //   Create a candidate repo associated with that source
                Repo candidateRepo = new Repo(candidateRepoName);
                candidateRepo.setCandidate(true);
                candidateRepo.addContentSource(contentSource);
                candidateRepo = repoManager.createRepo(overlord, candidateRepo);

                // Test
                RepoCriteria criteria = new RepoCriteria();
                criteria.addFilterCandidate(true);
                criteria.addFilterContentSourceIds(contentSource.getId());
                criteria.fetchRepoContentSources(true);

                PageList<Repo> foundRepos = repoManager.findReposByCriteria(overlord, criteria);

                // Verify

                //   Make sure only one of the two repos from above came back
                assert foundRepos.size() == 1;

                Repo foundRepo = foundRepos.get(0);
                assert foundRepo.getName().equals(candidateRepoName);
                assert foundRepo.isCandidate();

            }
        });
    }
View Full Code Here

    public void importCandidateRepo() throws Exception {
        executeInTransaction(new TransactionCallback() {

            public void execute() throws Exception {

                Repo candidate = new Repo("create me");
                candidate.setCandidate(true);
                Repo created = repoManager.createRepo(overlord, candidate);

                // Test
                List<Integer> repoIds = new ArrayList<Integer>(1);
                repoIds.add(created.getId());
                repoManager.importCandidateRepo(overlord, repoIds);

                // Verify
                RepoCriteria repoCriteria = new RepoCriteria();
                repoCriteria.addFilterId(created.getId());

                PageList<Repo> repoList = repoManager.findReposByCriteria(overlord, repoCriteria);
                assert repoList.size() == 1;

                Repo verify = repoList.get(0);
                assert verify != null;
                assert !verify.isCandidate();
            }
        });
    }
View Full Code Here

    public void importNonCandidateRepo() throws Exception {
        executeInTransaction(new TransactionCallback() {

            public void execute() throws Exception {

                Repo nonCandidate = new Repo("create me");
                Repo created = repoManager.createRepo(overlord, nonCandidate);

                // Test
                try {
                    List<Integer> repoIds = new ArrayList<Integer>(1);
                    repoIds.add(created.getId());
                    repoManager.importCandidateRepo(overlord, repoIds);
                    assert false;
                } catch (RepoException e) {
                    // Expected
                }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.content.Repo

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.