Package org.rhq.core.util

Examples of org.rhq.core.util.MessageDigestGenerator


        try {
            Set<RawConfiguration> configs = new HashSet<RawConfiguration>();
            RawConfiguration modules = new RawConfiguration();
            modules.setPath(MODULES_PATH);
            String contents = FileUtils.readFileToString(new File(MODULES_PATH));
            String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
            modules.setContents(contents, sha256);
            configs.add(modules);

            RawConfiguration settings = new RawConfiguration();
            settings.setPath(SETTINGS_PATH);
            contents = FileUtils.readFileToString(new File(SETTINGS_PATH));
            sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
            settings.setContents(contents, sha256);
            configs.add(settings);
            return configs;
        } catch (Exception e) {
            throw new RuntimeException(e);
View Full Code Here


        RawConfiguration raw = new RawConfiguration();

        raw.setPath(ETC_NSSWITCH_CONF);

        String contents = getContents(new File(raw.getPath()));
        String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
        raw.setContents(contents, sha256);

        raws.add(raw);
        return raws;
    }
View Full Code Here

        InputStream manifestStream = new FileInputStream(manifestFile);
        Manifest manifest = new Manifest(manifestStream);
        String actualSha256Attribute = manifest.getMainAttributes().getValue("RHQ-Sha256");
        manifestStream.close();

        MessageDigestGenerator digest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        String expectedSHA256 = digest.calcDigestString(sampleWithManifestWar);

        Assert.assertEquals(actualSha256Attribute, expectedSHA256);
        Assert.assertEquals(actualShaReturned, expectedSHA256);

        //cleanup resources created for this test
View Full Code Here

        InputStream manifestStream = new FileInputStream(manifestFile);
        Manifest manifest = new Manifest(manifestStream);
        String actualSha256Attribute = manifest.getMainAttributes().getValue("RHQ-Sha256");
        manifestStream.close();

        MessageDigestGenerator digest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        String expectedSHA256 = digest.calcDigestString(sampleWithoutManifestWar);

        Assert.assertEquals(actualSha256Attribute, expectedSHA256);
        Assert.assertEquals(actualShaReturned, expectedSHA256);

        deleteRecursive(deploymentDirectory);
View Full Code Here

        //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.");

        MessageDigestGenerator digest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
        String expectedSHA256 = digest.calcDigestString(sampleWithoutManifestWar);
        String actualSHA256OfDeployment = digest.calcDigestString(deploymentFile);

        Assert.assertEquals(actualSHA256OfDeployment, expectedSHA256);
        Assert.assertEquals(actualShaReturned, expectedSHA256);

        //cleanup resources created for this test
View Full Code Here

        //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);

        //cleanup resources created for this test
        Assert.assertEquals(actualShaReturned, expectedSHA256);
    }
View Full Code Here

       
        JarFile mockJarFile = mock(JarFile.class);
        PowerMockito.whenNew(JarFile.class).withParameterTypes(File.class).withArguments(any(File.class))
            .thenReturn(mockJarFile);

        MessageDigestGenerator mockMessageDigestGenerator = mock(MessageDigestGenerator.class);
        PowerMockito.whenNew(MessageDigestGenerator.class).withParameterTypes(String.class).withArguments(anyString())
            .thenReturn(mockMessageDigestGenerator);
        when(mockMessageDigestGenerator.calcDigestString(any(File.class))).thenReturn("abcd1234");

        //create object to test and inject required dependencies
        JarContentDelegate objectUnderTest = new JarContentDelegate(mockDirectory, "jar");

        //run code under test
View Full Code Here

            File scriptFile = new File(binDirectory, resourceContext.getResourceKey());

            String sha256 = PACKAGE_VERSION;
            try {
                sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(scriptFile);
            } catch (IOException e) {
                log.warn("Failed to compute the SHA256 digest of the script: " + scriptFile.getAbsolutePath(), e);
            }

            PackageDetailsKey key = new PackageDetailsKey(scriptFile.getName(), this.getVersion(sha256), PACKAGE_TYPE,
View Full Code Here

     */
    @Deprecated
    private String computeSHAForArchivedContent(File contentFile) {
        if (!contentFile.isDirectory()) {
            try {
                MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
                return messageDigest.calcDigestString(contentFile);
            } catch (Exception ex) {
                log.error("Not able to compute SHA256 for " + contentFile.getPath() + " .");
            }
        }

View Full Code Here

     */
    @Deprecated
    private String computeSHAForExplodedContent(File deploymentDirectory) {
        try {
            if (deploymentDirectory.isDirectory()) {
                MessageDigestGenerator messageDigest = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);

                Stack<File> unvisitedFolders = new Stack<File>();
                unvisitedFolders.add(deploymentDirectory);
                while (!unvisitedFolders.empty()) {
                    File[] files = unvisitedFolders.pop().listFiles();
                    Arrays.sort(files, new Comparator<File>() {
                        public int compare(File f1, File f2) {
                            try {
                                return f1.getCanonicalPath().compareTo(f2.getCanonicalPath());
                            } catch (IOException e) {
                                //do nothing if the sort fails at this point
                            }

                            return 0;
                        }
                    });

                    for (File file : files) {
                        if (file.isDirectory()) {
                            unvisitedFolders.add(file);
                        } else {
                            FileInputStream inputStream = null;
                            try {
                                inputStream = new FileInputStream(file);
                                messageDigest.add(inputStream);
                            } finally {
                                if (inputStream != null) {
                                    inputStream.close();
                                }
                            }
                        }
                    }
                }

                return messageDigest.getDigestString();
            }
        } catch (IOException e) {
            throw new RuntimeException("Error creating artifact for contentFile: " + deploymentDirectory, e);
        }

View Full Code Here

TOP

Related Classes of org.rhq.core.util.MessageDigestGenerator

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.