Package org.rhq.plugins.jbossas.util

Examples of org.rhq.plugins.jbossas.util.FileContentDelegate


                "Path to deploy (deployDirectory) may not reference the parent directory. Path specified: "
                    + deployDirectory);
          }

          // Perform the deployment
            FileContentDelegate deployer = new FileContentDelegate(new File(getConfigurationPath(), deployDirectory),
                    "", details.getPackageTypeName());

            PropertySimple zipProperty = deployTimeConfiguration.getSimple("deployZipped");

          if (zipProperty != null && zipProperty.getBooleanValue() != null) {
            boolean zip = zipProperty.getBooleanValue();

              File tempDir = resourceContext.getTemporaryDirectory();
              File tempFile = new File(tempDir.getAbsolutePath(), "esb.bin");
              OutputStream osForTempDir = new BufferedOutputStream(new FileOutputStream(tempFile));

              contentContext = resourceContext.getContentContext();
              ContentServices contentServices = contentContext.getContentServices();
              contentServices
                      .downloadPackageBitsForChildResource(contentContext, resourceTypeName, key, osForTempDir);

              osForTempDir.close();

              InputStream isForTempDir = new BufferedInputStream(new FileInputStream(tempFile));
              deployer.createContent(details, isForTempDir, !zip, false);

                // Resource key should match the following:     
                // ESB: jboss.esb:deployment=jbossesb.esb

                String resourceKey;
View Full Code Here


        File sampleWithManifestWar = new File(this.getClass().getResource("/sampleWithManifest.war").getFile());
        Assert.assertTrue(sampleWithManifestWar.exists());

        //create object to test and inject required dependencies
        FileContentDelegate objectUnderTest = new FileContentDelegate(deploymentDirectory, "", null);

        PackageDetails mockPackageDetails = mock(PackageDetails.class);
        PackageDetailsKey mockPackageDetailsKey = mock(PackageDetailsKey.class);
        when(mockPackageDetails.getKey()).thenReturn(mockPackageDetailsKey);
        when(mockPackageDetailsKey.getName()).thenReturn("deploymentFile");

        //run code under test
        objectUnderTest.createContent(mockPackageDetails, sampleWithManifestWar, true, false);
        String actualShaReturned = objectUnderTest.getSHA(new File(deploymentDirectory, "/deploymentFile"));

        //verify the results (Assert and mock verification)
        File manifestFile = new File(deploymentDirectory.getAbsolutePath() + "/deploymentFile/META-INF/MANIFEST.MF");
        Assert.assertTrue(manifestFile.exists(), "Manifest file not created properly!");
        Assert.assertNotEquals(manifestFile.length(), 0, "Empty manifest!!");
View Full Code Here

        Assert.assertTrue(sampleWithManifestWar.exists());

        ZipUtil.unzipFile(sampleWithManifestWar, deploymentDirectory);

        //create object to test and inject required dependencies
        FileContentDelegate objectUnderTest = new FileContentDelegate(deploymentDirectory, null, null);

        //run code under test
        String actualShaReturned = objectUnderTest.getSHA(deploymentDirectory);

        //verify the results (Assert and mock verification)
        File manifestFile = new File(deploymentDirectory.getAbsolutePath() + "/META-INF/MANIFEST.MF");
        Assert.assertTrue(manifestFile.exists(), "Manifest file not created properly!");
        Assert.assertNotEquals(manifestFile.length(), 0, "Empty manifest!!");
View Full Code Here

        File sampleWithoutManifestWar = new File(this.getClass().getResource("/sampleWithoutManifest.war").getFile());
        Assert.assertTrue(sampleWithoutManifestWar.exists());

        //create object to test and inject required dependencies
        FileContentDelegate objectUnderTest = new FileContentDelegate(deploymentDirectory, "", null);

        PackageDetails mockPackageDetails = mock(PackageDetails.class);
        PackageDetailsKey mockPackageDetailsKey = mock(PackageDetailsKey.class);
        when(mockPackageDetails.getKey()).thenReturn(mockPackageDetailsKey);
        when(mockPackageDetailsKey.getName()).thenReturn("deploymentFile");

        //run code under test
        objectUnderTest.createContent(mockPackageDetails, sampleWithoutManifestWar, true, false);
        String actualShaReturned = objectUnderTest.getSHA(new File(deploymentDirectory, "/deploymentFile"));

        //verify the results (Assert and mock verification)
        File manifestFile = new File(deploymentDirectory.getAbsolutePath() + "/deploymentFile/META-INF/MANIFEST.MF");
        Assert.assertTrue(manifestFile.exists(), "Manifest file not created properly!");
        Assert.assertNotEquals(manifestFile.length(), 0, "Empty manifest!!");
View Full Code Here

        //create object to test and inject required dependencies
        ZipUtil.unzipFile(sampleWithoutManifestWar, deploymentDirectory);

        //run code under test
        FileContentDelegate objectUnderTest = new FileContentDelegate(deploymentDirectory, null, null);
        String actualShaReturned = objectUnderTest.getSHA(deploymentDirectory);

        //verify the results (Assert and mock verification)
        File manifestFile = new File(deploymentDirectory.getAbsolutePath() + "/META-INF/MANIFEST.MF");
        Assert.assertTrue(manifestFile.exists(), "Manifest file not created properly!");
        Assert.assertNotEquals(manifestFile.length(), 0, "Empty manifest!!");
View Full Code Here

        Assert.assertTrue(sampleWithoutManifestWar.exists());

        File deploymentFile = new File(deploymentDirectory, sampleWithoutManifestWar.getName());

        //create object to test and inject required dependencies
        FileContentDelegate objectUnderTest = new FileContentDelegate(deploymentDirectory, "", null);

        PackageDetails mockPackageDetails = mock(PackageDetails.class);
        PackageDetailsKey mockPackageDetailsKey = mock(PackageDetailsKey.class);
        when(mockPackageDetails.getKey()).thenReturn(mockPackageDetailsKey);
        when(mockPackageDetailsKey.getName()).thenReturn(sampleWithoutManifestWar.getName());

        //run code under test
        objectUnderTest.createContent(mockPackageDetails, sampleWithoutManifestWar, false, false);
        String actualShaReturned = objectUnderTest.getSHA(sampleWithoutManifestWar);

        //verify the results (Assert and mock verification)
        Assert.assertTrue(deploymentDirectory.exists(), "Deployment did not happen.");
        Assert.assertTrue(deploymentDirectory.isDirectory(), "Deployment directory is no longer a directory!!");
        Assert.assertFalse(deploymentFile.isDirectory(), "Deployment was exploded when it should not have been.");
View Full Code Here

        //those dependencies to get the method under test to completion.
        File sampleWithoutManifestWar = new File(this.getClass().getResource("/sampleWithoutManifest.war").getFile());
        Assert.assertTrue(sampleWithoutManifestWar.exists());

        //create object to test and inject required dependencies
        FileContentDelegate objectUnderTest = new FileContentDelegate(sampleWithoutManifestWar, null, null);

        //run code under test
        String actualShaReturned = objectUnderTest.getSHA(sampleWithoutManifestWar);

        //verify the results (Assert and mock verification)
        MessageDigestGenerator digest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        String expectedSHA256 = digest.calcDigestString(sampleWithoutManifestWar);
View Full Code Here

            .thenReturn(mockFile);
        when(mockFile.exists()).thenReturn(true);

        when(mockFile.getName()).thenReturn("testFileName");

        FileContentDelegate mockFileContentDelegate = mock(FileContentDelegate.class);
        PowerMockito.whenNew(FileContentDelegate.class).withArguments(any(File.class), isNull(), isNull())
            .thenReturn(mockFileContentDelegate);
        when(mockFileContentDelegate.getSHA(any(File.class))).thenReturn("abcd1234");

        JarContentFileInfo mockJarContentFileInfo = mock(JarContentFileInfo.class);
        PowerMockito.whenNew(JarContentFileInfo.class).withParameterTypes(File.class).withArguments(any(File.class))
            .thenReturn(mockJarContentFileInfo);
        when(mockJarContentFileInfo.getVersion(isNull(String.class))).thenReturn("testDisplayVersion");
View Full Code Here

        if (backupProperty != null && backupProperty.getBooleanValue() != null && backupProperty.getBooleanValue())
            createBackup = true;

        // Perform the deployment
        File deployDir = new File(getConfigurationPath(), deployDirectory);
        FileContentDelegate deployer = new FileContentDelegate(deployDir, "", details.getPackageTypeName());

        File path = deployer.getPath(details);
        if (!createBackup && path.exists()) {
            setErrorOnCreateResourceReport(report, "A " + resourceTypeName + " file named " + path.getName()
                + " is already deployed with path " + path + ".");
            return;
        }

        PropertySimple zipProperty = deployTimeConfiguration.getSimple("deployZipped");

        if (zipProperty == null || zipProperty.getBooleanValue() == null) {
            setErrorOnCreateResourceReport(report, "Zipped property is required.");
            return;
        }

        boolean zip = zipProperty.getBooleanValue();

        File tempDir = resourceContext.getTemporaryDirectory();
        File tempFile = new File(tempDir.getAbsolutePath(), "ear_war.bin");
        OutputStream osForTempDir = new BufferedOutputStream(new FileOutputStream(tempFile));

        ContentServices contentServices = contentContext.getContentServices();
        contentServices.downloadPackageBitsForChildResource(contentContext, resourceTypeName, key, osForTempDir);

        osForTempDir.close();

        // check for content
        boolean valid = isOfType(tempFile, resourceTypeName);
        if (!valid) {
            setErrorOnCreateResourceReport(report, "Expected a " + resourceTypeName
                + " file, but its format/content did not match");
            return;
        }

        deployer.createContent(details, tempFile, !zip, createBackup);

        String vhost = null;
        if (resourceTypeName.equals(RESOURCE_TYPE_WAR)) {
            vhost = getVhostFromWarFile(tempFile);
        }
View Full Code Here

    private String getSHA256(File file) {
        String sha256 = null;

        try {
            FileContentDelegate fileContentDelegate = new FileContentDelegate(file, null, null);
            sha256 = fileContentDelegate.getSHA(file);
        } catch (Exception iex) {
            //log exception but move on, discovery happens often. No reason to hold up anything.
            if (log.isDebugEnabled()) {
                log.debug("Problem calculating digest of package [" + file.getPath() + "]." + iex.getMessage());
            }
View Full Code Here

TOP

Related Classes of org.rhq.plugins.jbossas.util.FileContentDelegate

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.