Package org.rhq.core.domain.bundle

Examples of org.rhq.core.domain.bundle.Bundle


    public void testFindAndDeleteBundlesByCriteriaQuery() throws Exception {
        // verify that all bundle version objects are actually parsed.
        Map<String, Bundle> bundleNames = new HashMap<String, Bundle>();
        final int bundleCount = 50;

        Bundle b01 = createBundle("name01");
        for (int i = 1; i < bundleCount; i++) {
            createBundle("name" + String.format("%02d", i + 1));
        }

        BundleCriteria criteria = new BundleCriteria();
        criteria.addFilterName(TEST_PREFIX);
        final int pageSize = 10;
        criteria.setPaging(0, pageSize);
        criteria.addSortName(PageOrdering.DESC);

        // iterate over the results with CriteriaQuery
        CriteriaQueryExecutor<Bundle, BundleCriteria> queryExecutor = new CriteriaQueryExecutor<Bundle, BundleCriteria>() {
            @Override
            public PageList<Bundle> execute(BundleCriteria criteria) {
                return bundleManager.findBundlesByCriteria(overlord, criteria);
            }
        };

        CriteriaQuery<Bundle, BundleCriteria> bundles = new CriteriaQuery<Bundle, BundleCriteria>(criteria,
            queryExecutor);

        List<Integer> toRemove = new ArrayList<Integer>(bundleNames.size());
        String prevName = null;
        // iterate over the entire result set efficiently
        String errMsg = "Results should be sorted by names, something is out of order";
        for (Bundle b : bundles) {
            assertTrue(errMsg, null == prevName || prevName.compareTo(b.getName()) > 0);
            prevName = b.getName();
            toRemove.add(b.getId());
            bundleNames.remove(String.valueOf(b.getName()));
        }

        // remove the bundles
        for (int id : toRemove) {
            bundleManager.deleteBundle(overlord, id);
        }

        // check if the last name is equal to "name01"
        assertEquals("The name should be \"name01\"", b01.getName(), prevName);

        // test that entire list parsed spanning multiple pages
        assertTrue("Expected bundleNames to be empty. Still " + bundleNames.size() + " bundle(s).",
            bundleNames.isEmpty());
View Full Code Here


        assertTrue(bvs.isEmpty());
    }

    @Test(enabled = TESTS_ENABLED)
    public void testFindBundleVersionsByCriteria() throws Exception {
        Bundle b1 = createBundle("one");
        BundleVersion bv1 = createBundleVersion(b1.getName(), "1.0", b1);
        BundleVersion bv2 = createBundleVersion(b1.getName(), "2.0", b1);
        BundleVersion bv3 = createBundleVersion(b1.getName(), "2.1", b1);
        BundleVersionCriteria c = new BundleVersionCriteria();
        PageList<BundleVersion> bvs;
        BundleVersion bvOut;

        // return all with no optional data
View Full Code Here

    }

    @Test(enabled = TESTS_ENABLED)
    public void testFindBundleVersionsByCriteriaPaging() throws Exception {
        TreeMap<Integer, BundleVersion> createdBVs = new TreeMap<Integer, BundleVersion>();
        Bundle b1 = createBundle("one");
        for (int i = 0; i <= 59; i++) {
            BundleVersion bv = createBundleVersion(b1.getName(), "1." + String.format("%02d", i + 1), b1);
            createdBVs.put(bv.getId(), bv);
        }

        BundleVersionCriteria c = new BundleVersionCriteria();
        PageList<BundleVersion> bvs;
View Full Code Here

    public void testFindAndDeleteBundleVersionsByCriteriaQuery() throws Exception {
        //verify that all bundle version objects are actually parsed.
        Map<String, BundleVersion> bundleVersionVersions = new HashMap<String, BundleVersion>();

        final int bundleVersionCount = 220;
        Bundle bundle = createBundle("one");
        for (int i = 0; i < bundleVersionCount; i++) {
            String version = "1." + String.format("%03d", i + 1);
            BundleVersion bundleVersion = createBundleVersion(bundle.getName(), version, bundle);
            bundleVersionVersions.put(version, bundleVersion);
        }

        final int pageSize = 20;
        BundleVersionCriteria criteria = new BundleVersionCriteria();
View Full Code Here

        assertTrue(bvs.isEmpty());
    }

    @Test(enabled = TESTS_ENABLED)
    public void testGetAllBundleVersionFilenames() throws Exception {
        final Bundle b1 = createBundle("one");
        assertNotNull(b1);
        final BundleVersion bv1 = createBundleVersion(b1.getName(), "1.0", b1);
        assertNotNull(bv1);
        final HashMap<String, Boolean> files = bundleManager.getAllBundleVersionFilenames(overlord, bv1.getId());
        assertNotNull(files);
        assertEquals(DEFAULT_CRITERIA_PAGE_SIZE + 2, files.keySet().size());
    }
View Full Code Here

        assertEquals(DEFAULT_CRITERIA_PAGE_SIZE + 2, files.keySet().size());
    }

    @Test(enabled = TESTS_ENABLED)
    public void testCreateBundleAndBundleVersionStrictName1() throws Exception {
        final Bundle b1 = createBundle("one");
        final String name = "on";
        final String fullName = TEST_PREFIX + "-bundle-" + name;
        final BundleType type = createBundleType(name);
        final String recipe = "deploy -f " + TEST_PREFIX + ".zip -d @@ test.path @@";
        final BundleVersion bundleVerison = bundleManager.createBundleAndBundleVersion(overlord, fullName,
            "description", type.getId(), null, fullName, fullName + "-desc", "3.0", recipe);
        assertNotNull(bundleVerison);

        // find the previously created bundle
        BundleCriteria c = new BundleCriteria();
        c.addFilterName(TEST_PREFIX + "-bundle-one");
        c.setStrict(true);
        PageList<Bundle> bundles1 = bundleManager.findBundlesByCriteria(overlord, c);
        assertNotNull(bundles1);
        assertEquals(1, bundles1.size());
        Bundle fetchedBundle1 = bundles1.get(0);

        // find the newly created bundle
        c = new BundleCriteria();
        c.addFilterName(fullName);
        c.setStrict(true);
View Full Code Here

    }

    @Test(enabled = TESTS_ENABLED)
    public void testCreateBundleAndBundleVersionStrictName2() throws Exception {
        final String name = "one";
        final Bundle bundle = createBundle(name);
        final String fullName = TEST_PREFIX + "-bundle-" + name;
        final String recipe = "deploy -f " + TEST_PREFIX + ".zip -d @@ test.path @@";
        final BundleVersion bundleVerison = bundleManager.createBundleAndBundleVersion(overlord, fullName,
            "description", bundle.getBundleType().getId(), null, fullName, fullName + "-desc", "3.0", recipe);

        // find the newly created bundle
        BundleCriteria c = new BundleCriteria();
        c.addFilterName(fullName);
        c.setStrict(true);
View Full Code Here

            // expected
        }

        // allow unassigned bundle create
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle");

        // deny unassigned bundle view
        removeRolePermissions(role, Permission.CREATE_BUNDLES, Permission.VIEW_BUNDLES);
        BundleCriteria bCriteria = new BundleCriteria();
        List<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see unassigned bundle";

        // allow unassigned bundle view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see unassigned bundle", 1, bundles.size());

        // deny global perm bundle assign
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        bundleGroup = new BundleGroup(TEST_BUNDLE_GROUP_NAME);
        bundleGroup.setDescription("test");

        bundleGroup = bundleManager.createBundleGroup(subject, bundleGroup);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle assign via global manage_bundle_groups
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle unassign via global manage_bundle_groups
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // allow bundle assign via global create
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        addRolePermissions(role, Permission.CREATE_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny bundle unassign via global create
        try {
            bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle unassign via global delete
        addRolePermissions(role, Permission.DELETE_BUNDLES);
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });
        removeRolePermissions(role, Permission.DELETE_BUNDLES);

        // deny bundle assign with global create but no view
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // go back and again assign via global create and view
        addRolePermissions(role, Permission.VIEW_BUNDLES);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup.getId() },
            new int[] { bundle.getId() });

        // deny assigned, unassociated-bundle-group bundle view
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        removeRolePermissions(role, Permission.VIEW_BUNDLES);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not be able to see assigned bundle";

        // allow assigned, associated-bundle-group bundle view
        addRoleBundleGroup(role, bundleGroup);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());

        // check new bundle criteria options (no match)
        bCriteria.addFilterBundleGroupIds(87678);
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assert bundles.isEmpty() : "Should not have found anything";

        // check new bundle criteria options (match)
        bCriteria.addFilterBundleGroupIds(bundleGroup.getId());
        bCriteria.fetchBundleGroups(true);
        bundles = bundleManager.findBundlesByCriteria(subject, bCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());
        assertNotNull(bundles.get(0).getBundleGroups());
        assertEquals("Should have fetched bundlegroup", 1, bundles.get(0).getBundleGroups().size());
        assertEquals("Should have fetched expected bundlegroup", bundleGroup, bundles.get(0).getBundleGroups()
            .iterator().next());

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(87678);
        bgCriteria.addFilterBundleIds(87678);
        bgCriteria.addFilterRoleIds(87678);
        bgCriteria.fetchBundles(true);
        bgCriteria.fetchRoles(true);
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterId(bundleGroup.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (no match)
        bgCriteria.addFilterBundleIds(bundle.getId());
        bundleGroups = bundleManager.findBundleGroupsByCriteria(subject, bgCriteria);
        assertNotNull(bundleGroups);
        assert bundleGroups.isEmpty() : "Should not have found anything";

        // check new bundle group criteria options (match)
View Full Code Here

            // expected
        }

        // allow bundle creation in bg1 (has create perm)
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        Bundle bundle = createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup1.getId());

        // deny bundle version creation (perm taken away)
        removeRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        try {
            BundleVersion bv1 = createBundleVersion(subject, bundle.getName() + "-1", null, bundle);
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle version creation (perm granted)
        addRolePermissions(role, Permission.CREATE_BUNDLES_IN_GROUP);
        BundleVersion bv1 = createBundleVersion(subject, bundle.getName() + "-1", null, bundle);
        assertNotNull(bv1);
        assertEquals("1.0", bv1.getVersion());
        assert 0 == bv1.getVersionOrder();

        // create second role
        Role role2 = createNewRoleForSubject(subject, TEST_ROLE_NAME + "_2");
        addRolePermissions(role2, Permission.CREATE_BUNDLES_IN_GROUP);

        // create second bundle group
        addRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);
        BundleGroup bundleGroup2 = new BundleGroup(TEST_BUNDLE_GROUP_NAME + "_2");
        bundleGroup2.setDescription("bg-2");
        bundleGroup2 = bundleManager.createBundleGroup(subject, bundleGroup2);
        removeRolePermissions(role, Permission.MANAGE_BUNDLE_GROUPS);

        // deny bundle create in bg2 (not associated with role)
        try {
            createBundle(subject, TEST_PREFIX + ".bundle", bundleGroup2.getId());
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // deny bundle assign to bg2 (not associated with role)
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // add bg2 to the role
        addRoleBundleGroup(role2, bundleGroup2);

        // deny bundle assign to bg2 (no perm)
        removeRolePermissions(role2, Permission.CREATE_BUNDLES_IN_GROUP);
        try {
            bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow bundle assign to bg2
        addRolePermissions(role2, Permission.ASSIGN_BUNDLES_TO_GROUP);
        bundleManager.assignBundlesToBundleGroups(subject, new int[] { bundleGroup2.getId() },
            new int[] { bundle.getId() });

        // should fetch the single bundle even though it is in two groups
        BundleCriteria bundleCriteria = new BundleCriteria();
        bundleCriteria.addFilterBundleGroupIds(bundleGroup1.getId(), bundleGroup2.getId());
        List<Bundle> bundles = bundleManager.findBundlesByCriteria(subject, bundleCriteria);
        assertNotNull(bundles);
        assertEquals("Should be able to see assigned bundle", 1, bundles.size());
        assertEquals("Should have fetched bundle", bundle, bundles.get(0));

        BundleVersionCriteria bvCriteria = new BundleVersionCriteria();
        bvCriteria.addFilterBundleId(bundle.getId());
        List<BundleVersion> bundleVersions = bundleManager.findBundleVersionsByCriteria(subject, bvCriteria);
        assertNotNull(bundleVersions);
        assertEquals("Should be able to see assigned bundle bundleversion", 1, bundleVersions.size());
        assertEquals("Should have fetched bundleversion", bv1, bundleVersions.get(0));

        // deny unassign
        try {
            bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup2.getId() },
                new int[] { bundle.getId() });
            fail("Should have thrown PermissionException");
        } catch (PermissionException e) {
            // expected
        }

        // allow unassigns
        addRolePermissions(role, Permission.UNASSIGN_BUNDLES_FROM_GROUP);
        addRolePermissions(role2, Permission.UNASSIGN_BUNDLES_FROM_GROUP);
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup1.getId() },
            new int[] { bundle.getId() });
        bundleManager.unassignBundlesFromBundleGroups(subject, new int[] { bundleGroup2.getId() },
            new int[] { bundle.getId() });

        // should not find the now unassigned bundle
        bundles = bundleManager.findBundlesByCriteria(subject, bundleCriteria);
        assertNotNull(bundles);
        assertEquals("Should not be able to see unassigned bundle", 0, bundles.size());
View Full Code Here

        packageType.setDisplayName(StringUtils.deCamelCase(name));
        packageType.setDiscoveryInterval(-1L);
        packageType.setCreationData(false);
        packageType.setDeploymentConfigurationDefinition(null);

        Bundle bundle = new Bundle(name, bundleType, repo, packageType);
        bundle.setDescription(description);
        bundle.setPackageType(packageType);

        LOG.info("Creating bundle: " + bundle);
        entityManager.persist(bundle);

        for (BundleGroup bundleGroup : bundleGroups) {
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.bundle.Bundle

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.