Package org.auraframework.util.text

Examples of org.auraframework.util.text.Hash


        File dest = File.createTempFile(getName(), "");

        try {
            TestCommonJavascriptGroupImpl test = new TestCommonJavascriptGroupImpl("test", newFile.getParentFile());
            Hash hash = test.getGroupHash();
            assertEquals("Unexpected hash", "1B2M2Y8AsgTpgAmY7PhCfg", hash.toString());

            // Need this sleep so the last modified time changes, otherwise the
            // test runs too fast and the test fails
            // because the last modified time was not updated by the OS
            Thread.sleep(2000);
            // Update a js file which is part of the group
            writer = new FileWriter(newFile, false);
            writer.append("var simple='bye';");
            writer.close();

            // hash value is retained after update, but recalculated when adding
            // file to the group
            hash = test.getGroupHash();
            assertEquals("Hash shouldn't be updated without a manual reset", "1B2M2Y8AsgTpgAmY7PhCfg", hash.toString());
            // just add same file to trigger
            test.addFile("testGetGroupHash.js");
            hash = test.getGroupHash();
            assertEquals("Hash should have been updated after file added to group", "4EZCacmVcFMwWJRaluefgw",
                    hash.toString());

            // hash value doesn't change when adding empty directory to group
            test.addDirectory("testDir");
            hash = test.getGroupHash();
            assertEquals("Hash should not have changed after adding empty directory to group",
                    "4EZCacmVcFMwWJRaluefgw", hash.toString());

            // hash value should change when adding non-empty directory to group
            writer = new FileWriter(nestedFile, false);
            try {
                writer.append("var simple='sayonara';");
                writer.flush();
            } finally {
                writer.close();
            }

            test.addDirectory("testDir");
            hash = test.getGroupHash();
            assertEquals("Hash should have been updated after adding non-empty directory to group",
                    "CUadD1uu9gF9HA_AFPb0Cg", hash.toString());
        } finally {
            IOUtil.delete(dest);
            IOUtil.delete(nestedFile.getParentFile());
            newFile.delete();
        }
View Full Code Here


     */
    public void testHashingReaderProgress() throws Exception {
        int expectedHashCode = getHashCode("hi");

        Source<?> src = new StringSource<>(null, "hi", null, null);
        Hash hash = src.getHash();

        // hash not set initially
        assertHash(hash, false, DEFAULT_HASHCODE);

        // hash still not set
View Full Code Here

     */
    public void testHashingReaderLargerBuffer() throws Exception {
        int expectedHashCode = getHashCode("hi");

        Source<?> src = new StringSource<>(null, "hi", null, null);
        Hash hash = src.getHash();
        Reader reader = src.getHashingReader();
        char[] buffer = new char[50];
        assertEquals(2, reader.read(buffer));
        assertHash(hash, false, DEFAULT_HASHCODE);
        assertEquals("hi", new String(buffer, 0, 2));
View Full Code Here

     */
    public void testHashingReaderNull() throws Exception {
        int expectedHashCode = getHashCode("");

        Source<?> src = new StringSource<>(null, null, null, null);
        Hash hash = src.getHash();
        Reader reader = src.getHashingReader();
        char[] buffer = new char[50];
        assertEquals(-1, reader.read(buffer));
        assertHash(hash, true, expectedHashCode);

View Full Code Here

     */
    public void testHashingReaderEmpty() throws Exception {
        int expectedHashCode = getHashCode("");

        Source<?> src = new StringSource<>(null, "", null, null);
        Hash hash = src.getHash();
        Reader reader = src.getHashingReader();
        char[] buffer = new char[50];
        assertEquals(-1, reader.read(buffer));
        assertHash(hash, true, expectedHashCode);

View Full Code Here

    protected static Hash computeGroupHash(Set<File> files) throws IOException {
        Set<URL> urls = new TreeSet<URL>(compareUrls);
        for (File file : files) {
            urls.add(file.toURI().toURL());
        }
        return new Hash(new MultiStreamReader(urls));
    }
View Full Code Here

         *
         * @returns a non-{@code null} {@link Hash} for the group.
         * @throws java.io.IOException
         */
        public Hash getHash() throws IOException {
            Hash retVal = null;
            try {
                bundleLock.readLock().lock();
                retVal = groupHash;
            } finally {
                bundleLock.readLock().unlock();
View Full Code Here

        if (!isGroupHashKnown()) {
            return true;
        }
        // Otherwise, we're stale IFF we have changed contents.
        try {
            Hash currentTextHash = computeGroupHash(getFiles());
            return !currentTextHash.equals(getGroupHash());
        } catch (IOException e) {
            // presume we're stale; we'll probably try to regenerate and die from that.
            return true;
        }
    }
View Full Code Here

        }
    }

    protected String makeHash(String one, String two) throws IOException {
        StringReader reader = new StringReader(one + two);
        return new Hash(reader).toString();
    }
View Full Code Here

     * Also testing the hash results are consistent
     */
    public void testFrameworkUid() throws Exception {

        final AuraJavascriptGroup jsGroup = mock(AuraJavascriptGroup.class);
        Hash jsHash = mock(Hash.class);
        when(jsGroup.isStale()).thenReturn(false);
        when(jsGroup.getGroupHash()).thenReturn(jsHash);

        final AuraResourcesHashingGroup resourcesGroup = mock(AuraResourcesHashingGroup.class);
        Hash resourcesHash = mock(Hash.class);
        when(resourcesGroup.isStale()).thenReturn(false);
        when(resourcesGroup.getGroupHash()).thenReturn(resourcesHash);

        ConfigAdapterImpl configAdapter = new ConfigAdapterImpl() {
            @Override
            protected AuraJavascriptGroup newAuraJavascriptGroup() throws IOException {
                return jsGroup;
            }

            @Override
            protected FileGroup newAuraResourcesHashingGroup() throws IOException {
                return resourcesGroup;
            }
        };

        ConfigAdapterImpl spy = Mockito.spy(configAdapter);

        when(jsHash.toString()).thenReturn("jsGroup");
        when(resourcesHash.toString()).thenReturn("resourcesGroup");

        String uid = spy.getAuraFrameworkNonce();
        verify(spy, Mockito.times(1)).makeHash(anyString(), anyString());
        assertEquals("Framework uid is not correct", "9YifBh-oLwXkDGW3d3qyDQ", uid);

        reset(spy);
        uid = spy.getAuraFrameworkNonce();
        // test that makeHash is not called because jsHash and resourcesHash has not changed
        verify(spy, Mockito.never()).makeHash(anyString(), anyString());
        assertEquals("Framework uid is not correct", "9YifBh-oLwXkDGW3d3qyDQ", uid);

        // change js hash, verify changes framework nonce
        when(jsHash.toString()).thenReturn("MocKitYMuCK");
        reset(spy);
        uid = spy.getAuraFrameworkNonce();
        verify(spy, Mockito.times(1)).makeHash(anyString(), anyString());
        assertEquals("Framework uid is not correct", "ltz-V8xGPGhXbOiTtfSApQ", uid);

        // change resource hash, verify changes framework nonce
        when(resourcesHash.toString()).thenReturn("MuCkiTyMocK");
        reset(spy);
        uid = spy.getAuraFrameworkNonce();
        verify(spy, Mockito.times(1)).makeHash(anyString(), anyString());
        assertEquals("Framework uid is not correct", uid, "BJTaoiCDxoAF4Wbh0iC9lA");

View Full Code Here

TOP

Related Classes of org.auraframework.util.text.Hash

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.