Package org.rhq.core.domain.content

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


                        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());
View Full Code Here


            assert "testMergeWithRepo-Version".equals(inRepo.get(0).getVersion());

            // sanity check - make sure our own entity manager can find the PV entity
            getTransactionManager().begin();
            try {
                PackageVersion foundPv = getEntityManager().find(PackageVersion.class, inRepo.get(0).getId());
                assert foundPv != null;
                assert foundPv.getExtraProperties() != null;
                assert foundPv.getExtraProperties().getSimple("hello").getStringValue().equals("world");
            } finally {
                getTransactionManager().rollback();
            }

            // delete the content source first
View Full Code Here

            resourceType1.addPackageType(packageType3);

            // Package 1 - Contains 2 versions
            package1 = new Package("Package1", packageType1);

            package1.addVersion(new PackageVersion(package1, "1.0.0", architecture1));
            package1.addVersion(new PackageVersion(package1, "2.0.0", architecture1));

            em.persist(package1);

            // Package 2 - Contains 2 versions
            package2 = new Package("Package2", packageType2);

            package2.addVersion(new PackageVersion(package2, "1.0.0", architecture1));
            package2.addVersion(new PackageVersion(package2, "2.0.0", architecture1));

            em.persist(package2);

            // Package 3 - Contains 1 version
            package3 = new Package("Package3", packageType3);

            package3.addVersion(new PackageVersion(package3, "1.0.0", architecture1));

            em.persist(package3);

            // Package 4 - Contains 2 versions, the first is installed
            package4 = new Package("Package4", packageType4);

            PackageVersion package4Installed = new PackageVersion(package4, "1.0.0", architecture1);
            package4.addVersion(package4Installed);
            package4.addVersion(new PackageVersion(package4, "2.0.0", architecture1));

            em.persist(package4);

            // Package 5 - Contains 1 version, it is installed
            package5 = new Package("Package5", packageType4);

            PackageVersion package5Installed = new PackageVersion(package5, "1.0.0", architecture1);
            package5.addVersion(package5Installed);

            em.persist(package5);

            // Create resource against which we'll merge the discovery report
View Full Code Here

                try {
                    Resource resource = SessionTestHelper.createNewResource(em, "testPkgBitsResource");
                    PackageType pkgType = new PackageType("testPkgBitsPT", resource.getResourceType());
                    org.rhq.core.domain.content.Package pkg = new Package("testPkgBitsP", pkgType);
                    Architecture arch = new Architecture("testPkgArch");
                    PackageVersion pkgVer = new PackageVersion(pkg, "1", arch);

                    em.persist(pkgType);
                    em.persist(pkg);
                    em.persist(arch);
                    em.persist(pkgVer);
                    em.flush();

                    // test that no bits are available right now
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits = createPackageBits();
                    pkgVer.setPackageBits(packageBits);
                    pkgVer = em.merge(pkgVer);
                    em.flush();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert packageBits.getBlob().getBits() == null;

                    // now lets store some bits in the DB
                    final String DATA = "testPackageBits data";
                    PackageBitsBlob packageBitsBlob = em.find(PackageBitsBlob.class, packageBits.getId());
                    packageBitsBlob.setBits(DATA.getBytes());
                    em.merge(packageBitsBlob);
                    em.flush();

                    // test that the bits are available and stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // let's make sure the data really is in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert DATA.equals(new String(packageBits.getBlob().getBits()));

                    ////////////////////////////////////////////////////
                    // create another package version and test with that
                    ////////////////////////////////////////////////////
                    PackageVersion pkgVer2 = new PackageVersion(pkg, "2", arch);
                    em.persist(pkgVer2);
                    em.flush();

                    // first make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that no bits are available right now
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits2 = createPackageBits();
                    pkgVer2.setPackageBits(packageBits2);
                    pkgVer2 = em.merge(pkgVer2);
                    em.flush();

                    // make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == packageBits2.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits2 = em.find(PackageBits.class, packageBits2.getId());
                    assert packageBits2 != null;
                    assert packageBits2.getBlob().getBits() == null;

                    // now lets store some bits in the DB
                    final String DATA2 = "testPackageBits more data";
                    packageBits2.getBlob().setBits(DATA2.getBytes());
                    em.merge(packageBits2.getBlob());
                    em.flush();

                    // make sure the query still gets the right answer for the first pkgVer
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // test that the bits are available and stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer2.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer2.getId();
                    assert composite.getPackageBitsId() == packageBits2.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    // let's make sure the data really is in the DB
View Full Code Here

                try {
                    Resource resource = SessionTestHelper.createNewResource(em, "testPkgBitsLargeResource");
                    PackageType pkgType = new PackageType("testPkgBitsLargePT", resource.getResourceType());
                    org.rhq.core.domain.content.Package pkg = new Package("testPkgBitsLargeP", pkgType);
                    Architecture arch = new Architecture("testPkgLargeArch");
                    PackageVersion pkgVer = new PackageVersion(pkg, "1", arch);

                    em.persist(pkgType);
                    em.persist(pkg);
                    em.persist(arch);
                    em.persist(pkgVer);
                    em.flush();

                    // test that no bits are available right now
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == null;
                    assert !composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // pretend we loaded the bits, but we stored them somewhere other then the DB
                    PackageBits packageBits = createPackageBits();
                    pkgVer.setPackageBits(packageBits);
                    pkgVer = em.merge(pkgVer);
                    em.flush();

                    // test that the bits are available, but are not stored in the DB
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert !composite.isPackageBitsInDatabase();

                    // let's make sure there really is no data in the DB
                    packageBits = em.find(PackageBits.class, packageBits.getId());
                    assert packageBits != null;
                    assert packageBits.getBlob().getBits() == null;

                    // now lets store some bits in the DB using PreparedStatements and BLOB mechanism
                    // to simulate large file transfers where streaming is used instead of reading entire
                    // contents into memory every time.

                    // destination once pulled from db
                    File tempDir = getTempDir();
                    if (!tempDir.exists()) {
                        assertTrue("Unable to mkdirs " + tempDir + " for test.", tempDir.mkdirs());
                    }
                    File retrieved = new File(tempDir, "pulled.jar");
                    if (retrieved.exists()) {
                        assertTrue("Unable to delete " + retrieved.getPath() + " for test cleanup.", retrieved.delete());
                    }

                    //any jar should be fine. Use canned jar
                    InputStream originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    String originalDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
                        .calcDigestString(originalBinaryStream);
                    originalBinaryStream.close();
                    originalBinaryStream = this.getClass().getClassLoader()
                        .getResourceAsStream("binary-blob-sample.jar");
                    contentManager.updateBlobStream(originalBinaryStream, packageBits, null);
                    packageBits = em.find(PackageBits.class, packageBits.getId());

                    // test that the bits are available and stored in the DB: Reading the Blob
                    composite = contentUIManager.getLoadedPackageBitsComposite(pkgVer.getId());
                    assert composite != null;
                    assert composite.getPackageVersionId() == pkgVer.getId();
                    assert composite.getPackageBitsId() == packageBits.getId();
                    assert composite.isPackageBitsAvailable();
                    assert composite.isPackageBitsInDatabase();

                    FileOutputStream outputStream = new FileOutputStream(retrieved);
View Full Code Here

            Map<String, String> metaData = new HashMap<String, String>();
            metaData.put(ContentManagerLocal.UPLOAD_FILE_INSTALL_DATE, Long.toString(file.lastModified()));
            metaData.put(ContentManagerLocal.UPLOAD_FILE_NAME, packageName);
            InputStream fileStream = new FileInputStream(file);
            try {
                PackageVersion packageVersion = contentManager.getUploadedPackageVersion(subject, packageName,
                    packageTypeId, version, architectureId, fileStream, metaData, repoId);
                successMsg = "success [packageVersionId=" + packageVersion.getId() + ",packageId="
                    + packageVersion.getGeneralPackage().getId() + "]";
            } finally {
                fileStream.close();
            }
        } catch (Exception e) {
            writeExceptionResponse(response, "Failed to upload file", e); // clients will look for this string!
View Full Code Here

        final PackageType pkgType = packageType1;
        final Architecture arch = architecture1;

        // these will not have any JPA stubs inside them (i.e. no lazy exceptions will occur with these)
        Package pkgPojo = new Package(pkgName, pkgType);
        PackageVersion pvPojo = new PackageVersion(pkgPojo, pvName, arch);
        Configuration configPojo = new Configuration();
        configPojo.put(new PropertySimple("one", "two"));
        pvPojo.setExtraProperties(configPojo);

        Package persistedPkg = null;
        PackageVersion persistedPV = null;

        try {
            // create the entities that we will pass to the persist methods - these will get altered
            Package pkg = new Package(pkgName, pkgType);
            PackageVersion pv = new PackageVersion(pkg, pvName, arch);
            pv.setExtraProperties(configPojo);

            persistedPkg = this.contentManager.persistOrMergePackageSafely(pkg);
            assert persistedPkg != null;
            assert persistedPkg.getId() > 0;
            assert persistedPkg.equals(pkgPojo) : "not equal: " + persistedPkg + "<>" + pkgPojo;

            persistedPV = this.contentManager.persistOrMergePackageVersionSafely(pv);
            assert persistedPV != null;
            assert persistedPV.getId() > 0;
            assert persistedPV.equals(pvPojo) : "not equal: " + persistedPV + "<>" + pvPojo;
            assert persistedPV.getExtraProperties() != null;
            assert persistedPV.getExtraProperties().getId() > 0;
            assert persistedPV.getExtraProperties().getSimple("one").getStringValue().equals("two");

            // remember their new IDs - we want to make sure the same IDs are reused later
            int pkgId = persistedPkg.getId();
            int pvId = persistedPV.getId();
            int configId = persistedPV.getExtraProperties().getId();
            int propId = persistedPV.getExtraProperties().getSimple("one").getId();

            // we've persisted them, let's make sure our "safely" methods still work
            // create new entities that we will pass to the persist methods - these will get altered
            pkg = new Package(pkgName, pkgType);
            pv = new PackageVersion(pkg, pvName, arch);
            pv.setExtraProperties(configPojo);

            persistedPkg = this.contentManager.persistOrMergePackageSafely(pkg);
            assert persistedPkg != null;
            assert persistedPkg.getId() > 0;
            assert persistedPkg.equals(pkgPojo) : "not equal: " + persistedPkg + "<>" + pkgPojo;

            persistedPV = this.contentManager.persistOrMergePackageVersionSafely(pv);
            assert persistedPV != null;
            assert persistedPV.getId() > 0;
            assert persistedPV.equals(pvPojo) : "not equal: " + persistedPV + "<>" + pvPojo;
            assert persistedPV.getExtraProperties() != null;
            assert persistedPV.getExtraProperties().getId() > 0;
            assert persistedPV.getExtraProperties().getSimple("one").getStringValue().equals("two");

            // make sure we merged the existing entities - we should not have created new ones
            assert pkgId == persistedPkg.getId();
            assert pvId == persistedPV.getId();
            assert configId == persistedPV.getExtraProperties().getId();
            assert propId == persistedPV.getExtraProperties().getSimple("one").getId();

            // now pass in existing entities with non-zero IDs
            pkg = new Package(pkgName, pkgType);
            pv = new PackageVersion(pkg, pvName, arch);
            pv.setExtraProperties(configPojo);
            pkg.setId(persistedPkg.getId());
            pv.setId(persistedPV.getId());

            persistedPkg = this.contentManager.persistOrMergePackageSafely(pkg);
            assert persistedPkg != null;
            assert persistedPkg.getId() > 0;
            assert persistedPkg.equals(pkgPojo) : "not equal: " + persistedPkg + "<>" + pkgPojo;
View Full Code Here

                List<PackageVersion> packageVersions = packageVersionQuery.getResultList();

                assert packageVersions.size() == 1 : "Incorrect number of versions for package. Expected: 1, Found: "
                    + packageVersions.size();

                PackageVersion packageVersionX = packageVersions.get(0);

                assert packageVersionX.getArchitecture().equals(architecture1) : "Incorrect architecture on package version. Expected: "
                    + architecture1 + ", Found: " + packageVersionX.getArchitecture();
                assert packageVersionX.getDisplayName().equals(package4.getDisplayName()) : "Incorrect display name on package version. Expected: "
                    + package4.getDisplayName() + ", Found: " + packageVersionX.getDisplayName();
                assert packageVersionX.getDisplayVersion().equals(package4.getDisplayVersion()) : "Incorrect display version on package version. Expected: "
                    + package4.getDisplayVersion() + ", Found: " + packageVersionX.getDisplayVersion();
                //            assert packageVersionX.getFileCreatedDate().equals(package4.getFileCreatedDate()) : "Incorrect file created date on package version. Expected: " + package4.getFileCreatedDate() + ", Found: " + packageVersionX.getFileCreatedDate();
                assert packageVersionX.getFileName().equals(package4.getFileName()) : "Incorrect file name on package version. Expected: "
                    + package4.getFileName() + ", Found: " + packageVersionX.getFileName();
                assert packageVersionX.getFileSize().equals(package4.getFileSize()) : "Incorrect file size on package version. Expected: "
                    + package4.getFileSize() + ", Found: " + packageVersionX.getFileSize();
                assert packageVersionX.getLicenseName().equals(package4.getLicenseName()) : "Incorrect license name on package version. Expected: "
                    + package4.getLicenseName() + ", Found: " + packageVersionX.getLicenseName();
                assert packageVersionX.getLicenseVersion().equals(package4.getLicenseVersion()) : "Incorrect license version on package version. Expected: "
                    + package4.getLicenseVersion() + ", Found: " + packageVersionX.getLicenseVersion();
                assert packageVersionX.getLongDescription().equals(package4.getLongDescription()) : "Incorrect long description on package version. Expected: "
                    + package4.getLongDescription() + ", Found: " + packageVersionX.getLongDescription();
                assert packageVersionX.getMD5().equals(package4.getMD5()) : "Incorrect MD5 on package version. Expected: "
                    + package4.getMD5() + ", Found: " + packageVersionX.getMD5();
                assert Arrays.equals(packageVersionX.getMetadata(), package4.getMetadata()) : "Incorrect metadata on package version.";
                assert packageVersionX.getPackageBits() == null : "Non-null package bits specified for package version: "
                    + packageVersionX.getPackageBits();
                assert packageVersionX.getSHA256().equals(package4.getSHA256()) : "Incorrect SHA256 for package version. Expected: "
                    + package4.getSHA256() + ", Found: " + packageVersionX.getSHA256();
                assert packageVersionX.getShortDescription().equals(package4.getShortDescription()) : "Incorrect short description. Expected: "
                    + package4.getShortDescription() + ", Found: " + packageVersionX.getShortDescription();
                assert packageVersionX.getVersion().equals(package4.getVersion()) : "Incorrect version. Expected: "
                    + package4.getVersion() + ", Found: " + packageVersionX.getVersion();

                Configuration extraProperties = packageVersionX.getExtraProperties();
                assert extraProperties != null : "Package version extra properties not persisted.";
                assert extraProperties.getSimple("property2") != null : "Properties inside of extra properties were missing";
                assert extraProperties.getSimple("property2").getStringValue().equals("value2") : "Incorrect value of property2";

                // Load the installed package for the above package to check for the rest of the properties
                Query packageXInstalledPackageQuery = em
                    .createNamedQuery(InstalledPackage.QUERY_FIND_BY_RESOURCE_ID_AND_PKG_VER_ID);
                packageXInstalledPackageQuery.setParameter("resourceId", resource1.getId());
                packageXInstalledPackageQuery.setParameter("packageVersionId", packageVersionX.getId());
                InstalledPackage packageXInstalledPackage = (InstalledPackage) packageXInstalledPackageQuery
                    .getSingleResult();

                assert packageXInstalledPackage != null;
            } finally {
View Full Code Here

        Subject overlord = subjectManager.getOverlord();

        Set<ResourcePackageDetails> installUs = new HashSet<ResourcePackageDetails>(2);

        // Package 1, Version 2 with configuration values
        PackageVersion packageVersion1 = package1.getVersions().get(0);
        Configuration deploymentConfiguration1 = new Configuration();
        deploymentConfiguration1.put(new PropertySimple("property1", "value1"));

        PackageDetailsKey key1 = new PackageDetailsKey(package1.getName(), packageVersion1.getVersion(), package1
            .getPackageType().getName(), packageVersion1.getArchitecture().getName());
        ResourcePackageDetails packageDetails1 = new ResourcePackageDetails(key1);
        packageDetails1.setDeploymentTimeConfiguration(deploymentConfiguration1);

        installUs.add(packageDetails1);

        // Package 2, Version 1 (intentionally older version) with no configuration values
        PackageVersion packageVersion2 = package2.getVersions().get(0);

        PackageDetailsKey key2 = new PackageDetailsKey(package2.getName(), packageVersion2.getVersion(), package2
            .getPackageType().getName(), packageVersion2.getArchitecture().getName());
        ResourcePackageDetails packageDetails2 = new ResourcePackageDetails(key2);

        installUs.add(packageDetails2);

        // Make sure the mock is configured to return a success
        this.contentAgentService.setResponseReturnStatus(ContentResponseResult.SUCCESS);
        this.contentAgentService.setThrowError(false);
        this.contentAgentService.setReturnIndividualResponses(true);

        String notes = "Test package deployment";

        // Test  --------------------------------------------

        // Perform the deploy while locking the agent service. This allows us to check the state after the request
        // is sent to the agent but before the agent has replied.
        synchronized (responseLock) {
            contentManager.deployPackages(overlord, resource1.getId(), installUs, notes);

            // Check to see if the request and installed package were created and have the right status
            getTransactionManager().begin();

            try {
                // Content request
                Query query = em.createNamedQuery(ContentServiceRequest.QUERY_FIND_BY_RESOURCE);
                query.setParameter("resourceId", resource1.getId());

                List<?> results = query.getResultList();
                assert results.size() == 1 : "Incorrect number of content service requests. Expected: 1, Found: "
                    + results.size();

                ContentServiceRequest request = (ContentServiceRequest) results.get(0);
                assert request.getContentRequestType() == ContentRequestType.DEPLOY : "Request type incorrect. Expected: DEPLOY, Found: "
                    + request.getContentRequestType();
                assert request.getStatus() == ContentRequestStatus.IN_PROGRESS : "Request status incorrect. Expected: IN_PROGRESS, Found: "
                    + request.getStatus();
                assert request.getInstalledPackageHistory().size() == 2 : "Incorrect number of installed packages attached to request. Expected: 2, Found: "
                    + request.getInstalledPackageHistory().size();
                assert request.getNotes() != null : "Null notes found";
                assert request.getNotes().equals(notes) : "Incorrect notes found: " + request.getNotes();

                // Verify a history entry has been added for each package in the request
                Set<InstalledPackageHistory> history = request.getInstalledPackageHistory();

                assert history.size() == 2 : "Incorrect number of history entries on request. Expected: 2, Found: "
                    + history.size();

                for (InstalledPackageHistory historyEntry : history) {
                    assert historyEntry.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect state on history entity. Expected: BEING_INSTALLED, Found: "
                        + historyEntry.getStatus();
                }

                // Ensure the installed package has not been added to the resource yet

                // Package 1, Version 2
                query = em.createNamedQuery(InstalledPackage.QUERY_FIND_BY_RESOURCE_ID_AND_PKG_VER_ID);
                query.setParameter("resourceId", resource1.getId());
                query.setParameter("packageVersionId", packageVersion1.getId());

                results = query.getResultList();
                assert results.size() == 0 : "Incorrect number of installed packages for package 1, version 2. Expected: 0, Found: "
                    + results.size();

                // Check status of audit trail
                query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
                query.setParameter("contentServiceRequestId", request.getId());
                query.setParameter("packageVersionId", packageVersion1.getId());

                results = query.getResultList();

                assert results.size() == 1 : "Incorrect number of audit trail entries. Expected: 1, Found: "
                    + results.size();

                InstalledPackageHistory historyEntity = (InstalledPackageHistory) results.get(0);
                assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
                    + historyEntity.getStatus();

                // Package 2, Version 1
                query = em.createNamedQuery(InstalledPackage.QUERY_FIND_BY_RESOURCE_ID_AND_PKG_VER_ID);
                query.setParameter("resourceId", resource1.getId());
                query.setParameter("packageVersionId", packageVersion2.getId());

                results = query.getResultList();
                assert results.size() == 0 : "Incorrect number of installed packages for package 2, version 1. Expected: 0, Found: "
                    + results.size();

                // Check status of audit trail
                query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
                query.setParameter("contentServiceRequestId", request.getId());
                query.setParameter("packageVersionId", packageVersion2.getId());

                results = query.getResultList();

                assert results.size() == 1 : "Incorrect number of audit trail entries. Expected: 1, Found: "
                    + results.size();

                historyEntity = (InstalledPackageHistory) results.get(0);
                assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on second entity. Expected: BEING_INSTALLED, Found: "
                    + historyEntity.getStatus();

            } finally {
                responseLock.notifyAll();

                getTransactionManager().rollback();
            }
        }

        // Verify  --------------------------------------------

        // Give the agent service a second to make sure it finishes out its call
        Thread.sleep(1000);

        getTransactionManager().begin();

        try {
            // Content request
            Query query = em.createNamedQuery(ContentServiceRequest.QUERY_FIND_BY_RESOURCE);
            query.setParameter("resourceId", resource1.getId());

            List<?> results = query.getResultList();
            assert results.size() == 1 : "Incorrect number of content service requests. Expected: 1, Found: "
                + results.size();

            ContentServiceRequest request = (ContentServiceRequest) results.get(0);
            assert request.getStatus() == ContentRequestStatus.SUCCESS : "Request status incorrect. Expected: SUCCESS, Found: "
                + request.getStatus();

            // Verify a history entry has been added for the completion of the request per package
            Set<InstalledPackageHistory> history = request.getInstalledPackageHistory();

            assert history.size() == 4 : "Incorrect number of history entries on request. Expected: 4, Found: "
                + history.size();

            // Check for Package 1
            query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
            query.setParameter("contentServiceRequestId", request.getId());
            query.setParameter("packageVersionId", packageVersion1.getId());

            results = query.getResultList();

            assert results.size() == 2 : "Incorrect number of history entries. Expected: 2, Found: " + results.size();

            InstalledPackageHistory historyEntity = (InstalledPackageHistory) results.get(0);
            assert historyEntity.getStatus() == InstalledPackageHistoryStatus.INSTALLED : "Incorrect status on first entity. Expected: INSTALLED, Found: "
                + historyEntity.getStatus();

            historyEntity = (InstalledPackageHistory) results.get(1);
            assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
                + historyEntity.getStatus();

            // Check for Package 2
            query = em.createNamedQuery(InstalledPackageHistory.QUERY_FIND_BY_CSR_ID_AND_PKG_VER_ID);
            query.setParameter("contentServiceRequestId", request.getId());
            query.setParameter("packageVersionId", packageVersion2.getId());

            results = query.getResultList();

            assert results.size() == 2 : "Incorrect number of history entries. Expected: 2, Found: " + results.size();

            historyEntity = (InstalledPackageHistory) results.get(0);
            assert historyEntity.getStatus() == InstalledPackageHistoryStatus.INSTALLED : "Incorrect status on first entity. Expected: INSTALLED, Found: "
                + historyEntity.getStatus();

            historyEntity = (InstalledPackageHistory) results.get(1);
            assert historyEntity.getStatus() == InstalledPackageHistoryStatus.BEING_INSTALLED : "Incorrect status on first entity. Expected: BEING_INSTALLED, Found: "
                + historyEntity.getStatus();

            // Add a few tests for the new Criteria Search feature
            PackageVersionCriteria criteria = new PackageVersionCriteria();
            criteria.addFilterResourceId(resource1.getId());
            PageList<PackageVersion> pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
            assertNotNull(pageList);
            ArrayList<PackageVersion> pvs = pageList.getValues();
            assertEquals(2, pvs.size());
            PackageVersion pv0 = pvs.get(0);

            criteria.addFilterPackageTypeId(pv0.getGeneralPackage().getPackageType().getId());
            pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
            assertNotNull(pageList);
            pvs = pageList.getValues();
            assertEquals(1, pvs.size());
            assertEquals(pv0.getId(), pvs.get(0).getId());

            // there is no repo assignment, any valid ID should eliminate all PVs
            criteria.addFilterRepoId(38465);
            pageList = contentManager.findPackageVersionsByCriteria(overlord, criteria);
            assertNotNull(pageList);
View Full Code Here

            resourceType.addPackageType(packageType1);

            // Package 1 - No product versions specified
            package1 = new Package("Package1", packageType1);
            PackageVersion packageVersion1 = new PackageVersion(package1, "1.0.0", architecture);
            package1.addVersion(packageVersion1);

            em.persist(package1);

            // Package 2 - Has list of product versions that contains the resource's version
            package2 = new Package("Package2", packageType1);
            PackageVersion packageVersion2 = new PackageVersion(package2, "1.0.0", architecture);
            ProductVersionPackageVersion pvpv1 = packageVersion2.addProductVersion(productVersion1);
            ProductVersionPackageVersion pvpv2 = packageVersion2.addProductVersion(productVersion2);
            package2.addVersion(packageVersion2);

            em.persist(package2);
            em.persist(pvpv1);
            em.persist(pvpv2);

            // Package 3 - Has list of product versions where the resource version is not included
            package3 = new Package("Package3", packageType1);
            PackageVersion packageVersion3 = new PackageVersion(package3, "1.0.0", architecture);
            ProductVersionPackageVersion pvpv3 = packageVersion3.addProductVersion(productVersion2);
            package3.addVersion(packageVersion3);

            em.persist(package3);
            em.persist(pvpv3);

            // Package 4 - No product version restriction, but already installed on the resource
            package4 = new Package("Package4", packageType1);
            PackageVersion packageVersion4 = new PackageVersion(package4, "1.0.0", architecture);
            package4.addVersion(packageVersion4);

            em.persist(package4);

            // Wire up the repo to the resource and add all of these packages to it
View Full Code Here

TOP

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

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.