Author: Alex.Kolonitsky
Date: 2010-03-12 08:16:30 -0500 (Fri, 12 Mar 2010)
New Revision: 16567
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
Log:
fix xml tests resources loading
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-03-12
12:09:36 UTC (rev 16566)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-03-12
13:16:30 UTC (rev 16567)
@@ -23,14 +23,8 @@
package org.richfaces.cdk.xmlconfig;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URL;
-
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Inject;
import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.FileManager;
import org.richfaces.cdk.Source;
@@ -39,8 +33,13 @@
import org.xml.sax.SAXException;
import org.xml.sax.ext.EntityResolver2;
-import com.google.common.collect.ImmutableMap;
-import com.google.inject.Inject;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
/**
* <p class="changed_added_4_0">
@@ -173,12 +172,12 @@
URL url;
url = CdkEntityResolver.class.getResource(SYSTEM_PREFIX + path);
- InputStream inputStream;
+ InputStream inputStream = null;
if (null != url) {
try {
inputStream = url.openStream();
} catch (IOException e) {
- inputStream =
CdkEntityResolver.class.getResourceAsStream(SYSTEM_PREFIX + path);
+ // Do nothnig.
}
if (inputStream != null) {
@@ -193,12 +192,12 @@
URL url;
url = loader.getResource(RESOURCE_PREFIX + path);
- InputStream inputStream;
+ InputStream inputStream = null;
if (null != url) {
try {
inputStream = url.openStream();
} catch (IOException e) {
- inputStream = loader.getResourceAsStream(RESOURCE_PREFIX + path);
+ // Do nothnig.
}
if (inputStream != null) {
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-03-12
12:09:36 UTC (rev 16566)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/CdkResolverTest.java 2010-03-12
13:16:30 UTC (rev 16567)
@@ -13,8 +13,11 @@
import java.io.ByteArrayInputStream;
import java.io.InputStream;
+import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
+import java.net.URLStreamHandler;
+import java.net.URLConnection;
@RunWith(CdkTestRunner.class)
public class CdkResolverTest extends CdkTestBase {
@@ -42,7 +45,7 @@
@Override
public InputStream getResourceAsStream(String name) {
if ("foo/bar.xml".equals(name)) {
- return new ByteArrayInputStream("baz".getBytes());
+ return getBarXmlStream();
} else {
return super.getResourceAsStream(name);
}
@@ -51,7 +54,8 @@
public URL getResource(String name) {
if ("foo/bar.xml".equals(name)) {
try {
- return new URL("file", "localhost",
"/foo/bar.xml");
+ MyURLStreamHandler myURLStreamHandler = new
MyURLStreamHandler(getBarXmlStream());
+ return new URL("file", "localhost",
80, "/foo/bar.xml", myURLStreamHandler);
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
@@ -68,6 +72,10 @@
}
}
+ private ByteArrayInputStream getBarXmlStream() {
+ return new ByteArrayInputStream("baz".getBytes());
+ }
+
@Test
public void testResolveSystemIdSystem() throws Exception {
@@ -103,4 +111,38 @@
verify(facesConfigSource, templatesSource);
assertNotNull(input);
}
+
+
+ private class MyURLConnection extends URLConnection {
+
+ private InputStream inputStream;
+
+ @Override
+ public void connect() throws IOException {
+ }
+
+ MyURLConnection(URL u, InputStream inputStream) {
+ super(u);
+ this.inputStream = inputStream;
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return this.inputStream;
+ }
+ }
+
+ private class MyURLStreamHandler extends URLStreamHandler {
+
+ private InputStream inputStream;
+
+ MyURLStreamHandler(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
+
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new MyURLConnection(u, inputStream);
+ }
+ }
}