Package org.rhq.core.util

Examples of org.rhq.core.util.MessageDigestGenerator


        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(deploymentFile.exists(), "Deployment did not happen.");
        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

                        config.put(new PropertySimple("classpath", attributes.getValue(Attributes.Name.CLASS_PATH)));
                        config.put(new PropertySimple("sealed", attributes.getValue(Attributes.Name.SEALED)));
                    }
                    String sha256 = null;
                    try {
                        sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(file);
                    } catch (Exception e) {
                        // leave as null
                    }
   
                    ResourcePackageDetails details = new ResourcePackageDetails(new PackageDetailsKey(file.getName(),
View Full Code Here

        PowerMockito.whenNew(File.class).withParameterTypes(File.class, String.class)
            .withArguments(eq(mockDirectory), eq("testResource")).thenReturn(mockFile);

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

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

        PackageType mockPackageType = mock(PackageType.class);
        when(mockPackageType.getName()).thenReturn("script");

        //create object to test and inject required dependencies
View Full Code Here

            if (createBackup) {
                moveToBackup(destinationContentFile, ".bak");
            }
            if (unzip) {
                ZipUtil.unzipFile(sourceContentFile, destinationContentFile);
                String shaString = new MessageDigestGenerator(MessageDigestGenerator.SHA_256)
                    .calcDigestString(sourceContentFile);
                writeSHAToManifest(destinationContentFile, shaString);
            } else {
                FileUtil.copyFile(sourceContentFile, destinationContentFile);
            }
View Full Code Here

                if (sha == null || sha.trim().isEmpty()) {
                    sha = computeAndSaveSHA(deploymentFile);
                }
            } else {
                sha = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(deploymentFile);
            }
        } catch (IOException ex) {
            throw new RuntimeException("Problem calculating digest of package [" + deploymentFile.getPath() + "].", ex);
        }
View Full Code Here

     */
    private String computeAndSaveSHA(File deploymentDirectory) {
        String sha = null;
        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();
                                }
                            }
                        }
                    }
                }

                sha = messageDigest.getDigestString();
                writeSHAToManifest(deploymentDirectory, sha);
            }
        } catch (IOException e) {
            throw new RuntimeException("Error creating artifact for contentFile: " + deploymentDirectory, e);
        }
View Full Code Here

            }
            aug.save();

            toUpdate.setPath(existingConfig.getPath());
            String contents = FileUtils.readFileToString(new File(file));
            String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
            toUpdate.setContents(contents, sha256);
        } finally {
            if (aug != null) {
                aug.close();
            }
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.