1 15 package org.apache.tapestry.asset; 16 17 import java.net.URL ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.ClassResolver; 21 import org.apache.hivemind.impl.DefaultClassResolver; 22 import org.apache.hivemind.test.HiveMindTestCase; 23 import org.easymock.MockControl; 24 25 31 public class TestResourceDigestSource extends HiveMindTestCase 32 { 33 public void testSuccess() 34 { 35 ResourceDigestSourceImpl s = new ResourceDigestSourceImpl(); 36 s.setClassResolver(new DefaultClassResolver()); 37 38 assertEquals("a5f4663532ea3efe22084df086482290", s 39 .getDigestForResource("/org/apache/tapestry/asset/tapestry-in-action.png")); 40 } 41 42 public void testMissing() 43 { 44 ResourceDigestSourceImpl s = new ResourceDigestSourceImpl(); 45 s.setClassResolver(new DefaultClassResolver()); 46 47 try 48 { 49 s.getDigestForResource("/foo/bar/baz"); 50 unreachable(); 51 } 52 catch (ApplicationRuntimeException ex) 53 { 54 assertEquals("Classpath resource '/foo/bar/baz' does not exist.", ex.getMessage()); 55 } 56 } 57 58 public void testCache() 59 { 60 MockControl control = newControl(ClassResolver.class); 61 ClassResolver resolver = (ClassResolver) control.getMock(); 62 63 URL url = getClass().getResource("tapestry-in-action.png"); 64 65 resolver.getResource("/foo"); 66 control.setReturnValue(url); 67 68 replayControls(); 69 70 ResourceDigestSourceImpl s = new ResourceDigestSourceImpl(); 71 s.setClassResolver(resolver); 72 73 assertEquals("a5f4663532ea3efe22084df086482290", s.getDigestForResource("/foo")); 74 75 78 assertEquals("a5f4663532ea3efe22084df086482290", s.getDigestForResource("/foo")); 79 80 verifyControls(); 81 82 resolver.getResource("/foo"); 83 control.setReturnValue(url); 84 85 replayControls(); 86 87 89 s.resetEventDidOccur(); 90 91 93 assertEquals("a5f4663532ea3efe22084df086482290", s.getDigestForResource("/foo")); 94 95 verifyControls(); 96 97 } 98 } | Popular Tags |