1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.springframework.richclient.image;
17
18 import java.awt.Image;
19 import java.io.IOException;
20
21 import junit.framework.TestCase;
22
23 import org.springframework.context.ApplicationContext;
24 import org.springframework.context.support.ClassPathXmlApplicationContext;
25 import org.springframework.core.io.Resource;
26
27
28
29
30
31
32 public class ImageSourceTests extends TestCase {
33 private ApplicationContext context;
34
35 public void testValidImageAccess() throws IOException {
36 ImageSource source = (ImageSource)context.getBean("imageSource");
37 Resource resource = source.getImageResource("test.image.key");
38 assertNotNull(resource);
39 String urlExternalForm = resource.getURL().toExternalForm();
40 assertTrue(urlExternalForm.endsWith("org/springframework/richclient/image/test.gif"));
41 Image image = source.getImage("test.image.key");
42 assertNotNull(image);
43 }
44
45 public void testBrokenImageAccess() throws IOException {
46 ImageSource source = (ImageSource)context.getBean("imageSourceBroken");
47 Resource resource = source.getImageResource("bogus.image.key");
48 assertNotNull(resource);
49 String urlExternalForm = resource.getURL().toExternalForm();
50 assertTrue(urlExternalForm.endsWith("org/springframework/richclient/image/broken.gif"));
51 Image image = source.getImage("bogus.image.key");
52 assertNotNull(image);
53 }
54
55 public void testInvalidImageAccess() {
56 ImageSource source = (ImageSource)context.getBean("imageSourceBroken");
57 try {
58 source.getImageResource("invalid.image.key");
59 }
60 catch (NoSuchImageResourceException e) {
61
62 }
63 try {
64 source.getImage("invalid.image.key");
65 }
66 catch (NoSuchImageResourceException e) {
67
68 }
69 }
70
71 protected void setUp() throws Exception {
72 context = new ClassPathXmlApplicationContext("org/springframework/richclient/image/application-context.xml");
73 }
74 }