001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.springframework.richclient.image; 017 018 import java.io.IOException; 019 import java.net.MalformedURLException; 020 import java.net.URL; 021 022 import junit.framework.TestCase; 023 import org.springframework.context.support.ClassPathXmlApplicationContext; 024 025 /** 026 * Tests the "image:" URL protocol handler. 027 * 028 * @author oliverh 029 */ 030 public class HandlerTestsIgnored extends TestCase { 031 032 private static boolean imageHasNotBeenInstalledInThisJVM = true; 033 034 /** 035 * NOTE: This must be one big test method because of the static dependency 036 * introduced by the strange way Java requires custom URL handlers to be 037 * registered. 038 */ 039 public void testHandler() throws IOException { 040 assertTrue("This test can only be run once in a single JVM", imageHasNotBeenInstalledInThisJVM); 041 042 URL url; 043 044 // // make sure a handler is not installed 045 // try { 046 // url = new URL("image:test"); 047 // fail("image protocol is already installed. Do any of the other tests instantiate DefaultImageSource?"); 048 // } 049 // catch (MalformedURLException e) { 050 // // expected 051 // } 052 053 // test install 054 ImageSource urlHandlerImageSource = (ImageSource) new ClassPathXmlApplicationContext( 055 "org/springframework/richclient/image/application-context.xml").getBean("imageSource"); 056 // Handler.installImageUrlHandler(urlHandlerImageSource); is not needed because imageSource calls it itself 057 try { 058 url = new URL("image:test"); 059 imageHasNotBeenInstalledInThisJVM = false; 060 } 061 catch (MalformedURLException e) { 062 fail("protocol was not installed"); 063 } 064 065 // test invalid key 066 url = new URL("image:image.that.does.not.exist"); 067 try { 068 url.openConnection(); 069 fail(); 070 } 071 catch (NoSuchImageResourceException e) { 072 // expected 073 } 074 075 // test valid key 076 url = new URL("image:test.image.key"); 077 url.openConnection(); 078 } 079 080 }