01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.resource;
19:
20: import java.io.InputStream;
21: import java.net.URL;
22:
23: import org.junit.Assert;
24: import org.junit.Test;
25:
26: public class URIResolverTest extends Assert {
27:
28: private URIResolver uriResolver;
29:
30: private URL resourceURL = getClass().getResource(
31: "resources/helloworld.bpr");
32:
33: @Test
34: public void testJARProtocol() throws Exception {
35: uriResolver = new URIResolver();
36:
37: byte[] barray = new byte[] { 0 };
38: byte[] barray2 = new byte[] { 1 };
39: String uriStr = "jar:" + resourceURL.toString()
40: + "!/wsdl/hello_world.wsdl";
41:
42: // Check standard Java API's work with "jar:"
43: URL jarURL = new URL(uriStr);
44: InputStream is = jarURL.openStream();
45: assertNotNull(is);
46: if (is != null) {
47: barray = new byte[is.available()];
48: is.read(barray);
49: is.close();
50: }
51:
52: uriResolver.resolve("baseUriStr", uriStr, null);
53:
54: InputStream is2 = uriResolver.getInputStream();
55: assertNotNull(is2);
56: if (is2 != null) {
57: barray2 = new byte[is2.available()];
58: is2.read(barray2);
59: is2.close();
60:
61: }
62: assertEquals(new String(barray), new String(barray2));
63: }
64:
65: @Test
66: public void testJARResolver() throws Exception {
67: uriResolver = new URIResolver();
68:
69: String uriStr = "jar:" + resourceURL.toString()
70: + "!/wsdl/hello_world.wsdl";
71:
72: URL jarURL = new URL(uriStr);
73: InputStream is = jarURL.openStream();
74: assertNotNull(is);
75:
76: String uriStr2 = "jar:" + resourceURL.toString()
77: + "!/wsdl/hello_world_2.wsdl";
78:
79: URL jarURL2 = new URL(uriStr2);
80: InputStream is2 = jarURL2.openStream();
81: assertNotNull(is2);
82:
83: uriResolver.resolve(uriStr, "hello_world_2.wsdl", null);
84:
85: InputStream is3 = uriResolver.getInputStream();
86: assertNotNull(is3);
87: }
88:
89: }
|