Package org.rhq.core.domain.bundle

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


    private void doAntBundleInitialInstall(boolean startClean) throws Exception {
        ResourceType resourceType = new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
        Repo repo = new Repo("test-bundle-two");
        PackageType packageType = new PackageType("test-bundle-two", resourceType);
        Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("test-bundle-two", "2.5", bundle,
            getRecipeFromFile("test-bundle-two.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle2Dest", new ResourceGroup(
            "testSimpleBundle2Group"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());

        Configuration config = new Configuration();
        String customPropName = "custom.prop";
        String customPropValue = "ABC";
        String onePropName = "one.prop";
        String onePropValue = "111";
        config.put(new PropertySimple(customPropName, customPropValue));
        config.put(new PropertySimple(onePropName, onePropValue));

        BundleDeployment deployment = new BundleDeployment();
        deployment.setId(123);
        deployment.setName("test bundle 2 deployment name");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // copy the test archive file to the bundle files dir
        FileUtil.copyFile(new File("src/test/resources/test-bundle-two-archive.zip"), new File(this.bundleFilesDir,
            "test-bundle-two-archive.zip"));

        // create test.properties file in the bundle files dir
        File file1 = new File(this.bundleFilesDir, "test.properties");
        Properties props = new Properties();
        props.setProperty(customPropName, "@@" + customPropName + "@@");
        FileOutputStream outputStream = new FileOutputStream(file1);
        props.store(outputStream, "test.properties comment");
        outputStream.close();

        // if we are not to start clean, create some junk files that will need to be backed up and moved away
        if (startClean == false) {
            this.destDir.mkdirs();
            File junk1 = new File(this.destDir, "junk1.properties");
            Properties junkProps = new Properties();
            junkProps.setProperty("junk1", "wot gorilla?");
            FileOutputStream os = new FileOutputStream(junk1);
            junkProps.store(os, "junk1.properties comment");
            os.close();

            File junk2 = new File(this.destDir, "junksubdir" + File.separatorChar + "junk2.properties");
            junk2.getParentFile().mkdirs();
            junkProps = new Properties();
            junkProps.setProperty("junk2", "more junk");
            os = new FileOutputStream(junk2);
            junkProps.store(os, "junk2.properties comment");
            os.close();
        }

        BundleDeployRequest request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);

        BundleDeployResult results = plugin.deployBundle(request);

        assertResultsSuccess(results);

        // test that the prop was replaced in raw file test.properties
        Properties realizedProps = new Properties();
        loadProperties(realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
        assert customPropValue.equals(realizedProps.getProperty(customPropName)) : "didn't replace prop";

        // test that the archive was extracted properly. These are the files in the archive:
        // zero-file.txt (content: "zero")
        // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
        // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
        File zeroFile = new File(this.destDir, "zero-file.txt");
        File oneFile = new File(this.destDir, "one/one-file.txt");
        File twoFile = new File(this.destDir, "two/two-file.txt");
        assert zeroFile.exists() : "zero file missing";
        assert oneFile.exists() : "one file missing";
        assert twoFile.exists() : "two file missing";
        assert readFile(zeroFile).startsWith("zero");
        assert readFile(oneFile).startsWith(onePropValue);
        assert readFile(twoFile).startsWith("@@two.prop@@");

        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
        assert deploymentProps.getDeploymentId() == deployment.getId();
        assert deploymentProps.getBundleName().equals(bundle.getName());
        assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
        assert deploymentProps.getManageRootDir() == true;
        DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
        assert deploymentProps.equals(currentProps);
        DeploymentProperties previousProps = metadata.getPreviousDeploymentProperties(deployment.getId());
View Full Code Here


    public void testAntBundle() throws Exception {
        ResourceType resourceType = new ResourceType("testSimpleBundle", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle", resourceType);
        Repo repo = new Repo("testSimpleBundle");
        PackageType packageType = new PackageType("testSimpleBundle", resourceType);
        Bundle bundle = new Bundle("testSimpleBundle", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("testSimpleBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle", new ResourceGroup(
            "testSimpleBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
View Full Code Here

        ResourceType resourceType = new ResourceType("testSimpleBundle", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle", resourceType);
        Repo repo = new Repo("testSimpleBundle");
        PackageType packageType = new PackageType("testSimpleBundle", resourceType);
        Bundle bundle = new Bundle("testSimpleBundle", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("testSimpleBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle-dotdot.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle", new ResourceGroup(
            "testSimpleBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();
View Full Code Here

    public void testTags() throws Exception {
        ResourceType resourceType = new ResourceType("testSimpleBundle", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle", resourceType);
        Repo repo = new Repo("testSimpleBundle");
        PackageType packageType = new PackageType("testSimpleBundle", resourceType);
        Bundle bundle = new Bundle("testSimpleBundle", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("testSimpleBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle", new ResourceGroup(
            "testSimpleBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
View Full Code Here

        ResourceType resourceType = new ResourceType("testNoManageRootDirBundle", "plugin", ResourceCategory.SERVER,
            null);
        BundleType bundleType = new BundleType("testNoManageRootDirBundle", resourceType);
        Repo repo = new Repo("testNoManageRootDirBundle");
        PackageType packageType = new PackageType("testNoManageRootDirBundle", resourceType);
        Bundle bundle = new Bundle("testNoManageRootDirBundle", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("testNoManageRootDirBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle-no-manage-root-dir.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testNoManageRootDirBundle", new ResourceGroup(
            "testNoManageRootDirBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();
View Full Code Here

    public void testAntBundleManageRootDir() throws Exception {
        ResourceType resourceType = new ResourceType("testManageRootDirBundle", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testManageRootDirBundle", resourceType);
        Repo repo = new Repo("testManageRootDirBundle");
        PackageType packageType = new PackageType("testManageRootDirBundle", resourceType);
        Bundle bundle = new Bundle("testManageRootDirBundle", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("testManageRootDirBundle", "1.0", bundle,
            getRecipeFromFile("test-bundle-manage-root-dir.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testManageRootDirBundle", new ResourceGroup(
            "testManageRootDirBundle"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
        Configuration config = new Configuration();
View Full Code Here

        // deploy upgrade and test it
        ResourceType resourceType = new ResourceType("testSimpleBundle2Type", "plugin", ResourceCategory.SERVER, null);
        BundleType bundleType = new BundleType("testSimpleBundle2BType", resourceType);
        Repo repo = new Repo("test-bundle-two");
        PackageType packageType = new PackageType("test-bundle-two", resourceType);
        Bundle bundle = new Bundle("test-bundle-two", bundleType, repo, packageType);
        BundleVersion bundleVersion = new BundleVersion("test-bundle-two", "3.0", bundle,
            getRecipeFromFile("test-bundle-three.xml"));
        BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle2Dest", new ResourceGroup(
            "testSimpleBundle2Group"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());

        Configuration config = new Configuration();
        String customPropName = "custom.prop";
        String customPropValue = "DEF";
        String onePropName = "one.prop";
        String onePropValue = "one-one-one";
        String threePropName = "three.prop";
        String threePropValue = "333";
        config.put(new PropertySimple(customPropName, customPropValue));
        config.put(new PropertySimple(onePropName, onePropValue));
        config.put(new PropertySimple(threePropName, threePropValue));

        BundleDeployment deployment = new BundleDeployment();
        deployment.setId(456);
        deployment.setName("test bundle 3 deployment name - upgrades test bundle 2");
        deployment.setBundleVersion(bundleVersion);
        deployment.setConfiguration(config);
        deployment.setDestination(destination);

        // copy the test archive file to the bundle files dir
        FileUtil.copyFile(new File("src/test/resources/test-bundle-three-archive.zip"), new File(this.bundleFilesDir,
            "test-bundle-three-archive.zip"));

        // create test.properties file in the bundle files dir
        File file1 = new File(this.bundleFilesDir, "test.properties");
        Properties props = new Properties();
        props.setProperty(customPropName, "@@" + customPropName + "@@");
        FileOutputStream outputStream = new FileOutputStream(file1);
        props.store(outputStream, "test.properties comment");
        outputStream.close();

        // create some additional files - note: recipe says to ignore "ignore/**"
        File ignoreDir = new File(this.destDir, "ignore");
        File extraDir = new File(this.destDir, "extra");
        ignoreDir.mkdirs();
        extraDir.mkdirs();
        File ignoredFile = new File(ignoreDir, "ignore-file.txt");
        File extraFile = new File(extraDir, "extra-file.txt");
        FileUtil.writeFile(new ByteArrayInputStream("ignore".getBytes()), ignoredFile);
        FileUtil.writeFile(new ByteArrayInputStream("extra".getBytes()), extraFile);

        BundleDeployRequest request = new BundleDeployRequest();
        request.setBundleFilesLocation(this.bundleFilesDir);
        request.setResourceDeployment(createNewBundleDeployment(deployment));
        request.setBundleManagerProvider(new MockBundleManagerProvider());
        request.setAbsoluteDestinationDirectory(this.destDir);
        request.setCleanDeployment(clean);

        BundleDeployResult results = plugin.deployBundle(request);

        assertResultsSuccess(results);

        // test that the prop was replaced in raw file test.properties
        Properties realizedProps = new Properties();
        loadProperties(realizedProps, new FileInputStream(new File(this.destDir, "config/test.properties")));
        assert customPropValue.equals(realizedProps.getProperty(customPropName)) : "didn't replace prop";

        // test that the archive was extracted properly. These are the files in the archive or removed from original:
        // REMOVED: zero-file.txt
        // one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
        // two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
        // three/three-file.txt (content: "@@three.prop@@") <-- recipe says this is to be replaced
        File zeroFile = new File(this.destDir, "zero-file.txt");
        File oneFile = new File(this.destDir, "one/one-file.txt");
        File twoFile = new File(this.destDir, "two/two-file.txt");
        File threeFile = new File(this.destDir, "three/three-file.txt");
        assert !zeroFile.exists() : "zero file should have been removed during upgrade";
        assert oneFile.exists() : "one file missing";
        assert twoFile.exists() : "two file missing";
        assert threeFile.exists() : "three file missing";
        if (clean) {
            assert !ignoredFile.exists() : "ignored file should have been deleted due to clean deployment request";
            assert !extraFile.exists() : "extra file should have been deleted due to clean deployment request";
        } else {
            assert ignoredFile.exists() : "ignored file wasn't ignored, it was deleted";
            assert !extraFile.exists() : "extra file ignored, but it should have been deleted/backed up";
        }
        assert readFile(oneFile).startsWith(onePropValue);
        assert readFile(twoFile).startsWith("@@two.prop@@");
        assert readFile(threeFile).startsWith(threePropValue);

        DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
        DeploymentProperties deploymentProps = metadata.getDeploymentProperties(deployment.getId());
        assert deploymentProps.getDeploymentId() == deployment.getId();
        assert deploymentProps.getBundleName().equals(bundle.getName());
        assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
        assert deploymentProps.getManageRootDir() == true;

        DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
        assert deploymentProps.equals(currentProps);
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.