1 /*
2 * Copyright 2002-2004 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.springframework.richclient.image;
17
18 import java.io.IOException;
19 import java.net.MalformedURLException;
20 import java.net.URL;
21
22 import junit.framework.TestCase;
23 import org.springframework.context.support.ClassPathXmlApplicationContext;
24
25 /**
26 * Tests the "image:" URL protocol handler.
27 *
28 * @author oliverh
29 */
30 public class HandlerTestsIgnored extends TestCase {
31
32 private static boolean imageHasNotBeenInstalledInThisJVM = true;
33
34 /**
35 * NOTE: This must be one big test method because of the static dependency
36 * introduced by the strange way Java requires custom URL handlers to be
37 * registered.
38 */
39 public void testHandler() throws IOException {
40 assertTrue("This test can only be run once in a single JVM", imageHasNotBeenInstalledInThisJVM);
41
42 URL url;
43
44 // // make sure a handler is not installed
45 // try {
46 // url = new URL("image:test");
47 // fail("image protocol is already installed. Do any of the other tests instantiate DefaultImageSource?");
48 // }
49 // catch (MalformedURLException e) {
50 // // expected
51 // }
52
53 // test install
54 ImageSource urlHandlerImageSource = (ImageSource) new ClassPathXmlApplicationContext(
55 "org/springframework/richclient/image/application-context.xml").getBean("imageSource");
56 // Handler.installImageUrlHandler(urlHandlerImageSource); is not needed because imageSource calls it itself
57 try {
58 url = new URL("image:test");
59 imageHasNotBeenInstalledInThisJVM = false;
60 }
61 catch (MalformedURLException e) {
62 fail("protocol was not installed");
63 }
64
65 // test invalid key
66 url = new URL("image:image.that.does.not.exist");
67 try {
68 url.openConnection();
69 fail();
70 }
71 catch (NoSuchImageResourceException e) {
72 // expected
73 }
74
75 // test valid key
76 url = new URL("image:test.image.key");
77 url.openConnection();
78 }
79
80 }