You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/10/02 01:54:29 UTC
svn commit: r700975 [2/2] - in /incubator/shindig/trunk/java:
common/src/main/java/org/apache/shindig/common/uri/
common/src/main/java/org/apache/shindig/common/xml/
common/src/test/java/org/apache/shindig/common/xml/
gadgets/src/main/java/org/apache/s...
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicMessageBundleFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicMessageBundleFactoryTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicMessageBundleFactoryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicMessageBundleFactoryTest.java Wed Oct 1 16:54:27 2008
@@ -18,31 +18,33 @@
*/
package org.apache.shindig.gadgets;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
import org.apache.shindig.common.cache.CacheProvider;
import org.apache.shindig.common.cache.DefaultCacheProvider;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.http.HttpFetcher;
import org.apache.shindig.gadgets.http.HttpRequest;
import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.http.HttpResponseBuilder;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import org.apache.shindig.gadgets.spec.MessageBundle;
+
import org.easymock.EasyMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
-import static org.junit.Assert.assertEquals;
import org.junit.Test;
-import java.net.URI;
import java.util.Locale;
/**
* Tests for BasicMessageBundleFactory
*/
public class BasicMessageBundleFactoryTest {
- private static final URI BUNDLE_URI = URI.create("http://example.org/messagex.xml");
- private static final URI SPEC_URI = URI.create("http://example.org/gadget.xml");
+ private static final Uri BUNDLE_URI = Uri.parse("http://example.org/messagex.xml");
+ private static final Uri SPEC_URI = Uri.parse("http://example.org/gadget.xml");
private static final String MSG_0_NAME = "messageZero";
private static final String MSG_1_NAME = "message1";
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java Wed Oct 1 16:54:27 2008
@@ -20,10 +20,13 @@
import static org.easymock.EasyMock.expect;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import com.google.common.collect.Maps;
+import junitx.framework.StringAssert;
+
import org.apache.commons.lang.StringEscapeUtils;
import java.net.URI;
@@ -32,8 +35,6 @@
import java.util.Locale;
import java.util.Map;
-import junitx.framework.StringAssert;
-
/**
* Tests for DefaultUrlGenerator.
*/
@@ -123,7 +124,7 @@
" <Content type='html'/>" +
" <UserPref name='" + UP_NAME + "' datatype='string'/>" +
"</Module>";
- GadgetSpec spec = new GadgetSpec(URI.create(SPEC_URL), xml);
+ GadgetSpec spec = new GadgetSpec(Uri.parse(SPEC_URL), xml);
replay();
Gadget gadget = new Gadget()
@@ -147,7 +148,7 @@
" <Content type='url' href='" + StringEscapeUtils.escapeHtml(TYPE_URL_HREF) + "'/>" +
" <UserPref name='" + UP_NAME + "' datatype='string'/>" +
"</Module>";
- GadgetSpec spec = new GadgetSpec(URI.create(SPEC_URL), xml);
+ GadgetSpec spec = new GadgetSpec(Uri.parse(SPEC_URL), xml);
replay();
Gadget gadget = new Gadget()
.setContext(context)
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/FakeGadgetSpecFactory.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/FakeGadgetSpecFactory.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/FakeGadgetSpecFactory.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/FakeGadgetSpecFactory.java Wed Oct 1 16:54:27 2008
@@ -18,42 +18,43 @@
*/
package org.apache.shindig.gadgets;
-import java.net.URI;
-
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.oauth.GadgetTokenStoreTest;
import org.apache.shindig.gadgets.spec.GadgetSpec;
+import java.net.URI;
+
/**
* Fakes out a gadget spec factory
*/
public class FakeGadgetSpecFactory implements GadgetSpecFactory {
public static final String SERVICE_NAME = "testservice";
public static final String SERVICE_NAME_NO_KEY = "nokey";
-
+
public GadgetSpec getGadgetSpec(GadgetContext context) {
// we don't need this one yet
return null;
}
-
- public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache)
- throws GadgetException {
- String gadget = gadgetUri.toString();
+
+ public GadgetSpec getGadgetSpec(URI gadgetUri, boolean ignoreCache) throws GadgetException {
+ Uri uri = Uri.fromJavaUri(gadgetUri);
+ String gadget = uri.toString();
String baseSpec = GadgetTokenStoreTest.GADGET_SPEC;
if (gadget.contains("nokey")) {
// For testing key lookup failures
String nokeySpec = baseSpec.replace(SERVICE_NAME, SERVICE_NAME_NO_KEY);
- return new GadgetSpec(gadgetUri, nokeySpec);
+ return new GadgetSpec(uri, nokeySpec);
} else if (gadget.contains("header")) {
// For testing oauth data in header
String headerSpec = baseSpec.replace("uri-query", "auth-header");
- return new GadgetSpec(gadgetUri, headerSpec);
+ return new GadgetSpec(uri, headerSpec);
} else if (gadget.contains("body")) {
// For testing oauth data in body
String bodySpec = baseSpec.replace("uri-query", "post-body");
bodySpec = bodySpec.replace("'GET'", "'POST'");
- return new GadgetSpec(gadgetUri, bodySpec);
+ return new GadgetSpec(uri, bodySpec);
} else {
- return new GadgetSpec(gadgetUri, baseSpec);
+ return new GadgetSpec(uri, baseSpec);
}
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/GadgetTest.java Wed Oct 1 16:54:27 2008
@@ -20,13 +20,12 @@
import static org.junit.Assert.assertEquals;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.spec.GadgetSpec;
import org.apache.shindig.gadgets.spec.LocaleSpec;
import org.junit.Test;
-import java.net.URI;
-
/**
* Tests for Gadget
*/
@@ -51,7 +50,7 @@
public void getLocale() throws Exception {
Gadget gadget = new Gadget()
.setContext(context)
- .setSpec(new GadgetSpec(URI.create(SPEC_URL), SPEC_XML));
+ .setSpec(new GadgetSpec(Uri.parse(SPEC_URL), SPEC_XML));
LocaleSpec localeSpec = gadget.getLocale();
assertEquals("VALUE", localeSpec.getMessageBundle().getMessages().get("name"));
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/HashLockedDomainServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/HashLockedDomainServiceTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/HashLockedDomainServiceTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/HashLockedDomainServiceTest.java Wed Oct 1 16:54:27 2008
@@ -25,9 +25,9 @@
import static org.easymock.EasyMock.isA;
import org.apache.shindig.common.ContainerConfig;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.spec.GadgetSpec;
-import java.net.URI;
import java.util.Arrays;
public class HashLockedDomainServiceTest extends EasyMockTestCase {
@@ -49,7 +49,7 @@
}
try {
- return new GadgetSpec(URI.create(url), gadgetXml);
+ return new GadgetSpec(Uri.parse(url), gadgetXml);
} catch (GadgetException e) {
return null;
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthArgumentsTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthArgumentsTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthArgumentsTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthArgumentsTest.java Wed Oct 1 16:54:27 2008
@@ -23,6 +23,7 @@
import static org.junit.Assert.fail;
import org.apache.shindig.common.testing.FakeHttpServletRequest;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.AuthType;
import org.apache.shindig.gadgets.GadgetException;
@@ -48,7 +49,7 @@
"OAUTH_USE_TOKEN='never' " +
"/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), Uri.parse(""));
OAuthArguments params = new OAuthArguments(preload);
assertEquals("service", params.getServiceName());
assertEquals("token", params.getTokenName());
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/HttpPreloaderTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/HttpPreloaderTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/HttpPreloaderTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/preload/HttpPreloaderTest.java Wed Oct 1 16:54:27 2008
@@ -24,6 +24,7 @@
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.common.testing.FakeGadgetToken;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.AuthType;
import org.apache.shindig.gadgets.GadgetContext;
import org.apache.shindig.gadgets.http.ContentFetcherFactory;
@@ -54,7 +55,7 @@
private static final String PRELOAD_HREF2 = "http://www.example.org/file";
private static final String PRELOAD_CONTENT = "Preloaded data";
private static final String CONTAINER = "some-container";
- private static final URI GADGET_URL = URI.create("http://example.org/gadget.xml");
+ private static final Uri GADGET_URL = Uri.parse("http://example.org/gadget.xml");
private static final Map<String, String> PRELOAD_METADATA = Maps.immutableMap("foo", "bar");
private final RecordingHttpFetcher plainFetcher = new RecordingHttpFetcher();
private final RecordingHttpFetcher oauthFetcher = new RecordingHttpFetcher();
@@ -82,7 +83,7 @@
@Override
public URI getUrl() {
- return GADGET_URL;
+ return GADGET_URL.toJavaUri();
}
};
@@ -122,7 +123,6 @@
}
@Test
- @SuppressWarnings("unchecked")
public void signedPreloads() throws Exception {
String xml =
"<Module><ModulePrefs title=''>" +
@@ -143,7 +143,6 @@
}
@Test
- @SuppressWarnings("unchecked")
public void oauthPreloads() throws Exception {
String xml =
"<Module><ModulePrefs title=''>" +
@@ -163,7 +162,6 @@
}
@Test
- @SuppressWarnings("unchecked")
public void multiplePreloads() throws Exception {
String xml =
"<Module><ModulePrefs title=''>" +
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/process/ProcessorTest.java Wed Oct 1 16:54:27 2008
@@ -175,7 +175,7 @@
if (exception != null) {
throw exception;
}
- return new GadgetSpec(context.getUrl(), GADGET);
+ return new GadgetSpec(Uri.fromJavaUri(context.getUrl()), GADGET);
}
public GadgetSpec getGadgetSpec(URI uri, boolean ignoreCache) {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/HtmlRendererTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/HtmlRendererTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/HtmlRendererTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/HtmlRendererTest.java Wed Oct 1 16:54:27 2008
@@ -71,7 +71,7 @@
private final HtmlRenderer renderer = new HtmlRenderer(fetcher, preloaderService, rewriter);
private Gadget makeGadget(String content) throws GadgetException {
- GadgetSpec spec = new GadgetSpec(URI.create("#"),
+ GadgetSpec spec = new GadgetSpec(SPEC_URL,
"<Module><ModulePrefs title=''/><Content><![CDATA[" + content + "]]></Content></Module>");
return new Gadget()
@@ -83,7 +83,7 @@
private Gadget makeHrefGadget(String authz) throws Exception {
Gadget gadget = makeGadget("");
String doc = "<Content href='" + PROXIED_HTML_HREF + "' authz='" + authz + "'/>";
- View view = new View("proxied", Arrays.asList(XmlUtil.parse(doc)));
+ View view = new View("proxied", Arrays.asList(XmlUtil.parse(doc)), SPEC_URL);
gadget.setCurrentView(view);
return gadget;
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RendererTest.java Wed Oct 1 16:54:27 2008
@@ -40,13 +40,13 @@
import org.junit.Before;
import org.junit.Test;
-import java.net.URI;
import java.util.Arrays;
/**
* Tests for Renderer.
*/
public class RendererTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/gadget.xml");
private static final Uri TYPE_URL_HREF = Uri.parse("http://example.org/gadget.php");
private static final String BASIC_HTML_CONTENT = "Hello, World!";
private static final String GADGET =
@@ -132,7 +132,7 @@
assertEquals(RenderingResults.Status.ERROR, results.getStatus());
assertNotNull("No error message provided for bad parent.", results.getErrorMessage());
}
-
+
@Test
public void handlesNoCurrentViewGracefully() throws Exception {
RenderingResults results = renderer.render(makeContext("bad-view-name"));
@@ -198,7 +198,7 @@
}
try {
- GadgetSpec spec = new GadgetSpec(URI.create("#"), GADGET);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, GADGET);
View view = spec.getView(context.getView());
return new Gadget()
.setContext(context)
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingContentRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingContentRewriterTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingContentRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/RenderingContentRewriterTest.java Wed Oct 1 16:54:27 2008
@@ -29,6 +29,7 @@
import static org.junit.Assert.assertTrue;
import org.apache.shindig.common.ContainerConfig;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.Gadget;
import org.apache.shindig.gadgets.GadgetContext;
import org.apache.shindig.gadgets.GadgetException;
@@ -58,7 +59,6 @@
import org.junit.Before;
import org.junit.Test;
-import java.net.URI;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -73,6 +73,7 @@
* Tests for RenderingContentRewriter.
*/
public class RenderingContentRewriterTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/gadget.xml");
private static final String BODY_CONTENT = "Some body content";
private final IMocksControl control = EasyMock.createNiceControl();
private final FakeMessageBundleFactory messageBundleFactory = new FakeMessageBundleFactory();
@@ -90,7 +91,7 @@
}
private Gadget makeGadgetWithSpec(String gadgetXml) throws GadgetException {
- GadgetSpec spec = new GadgetSpec(URI.create("#"), gadgetXml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, gadgetXml);
return new Gadget()
.setContext(new GadgetContext())
.setPreloads(new NullPreloads())
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/BaseRewriterTestCase.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/BaseRewriterTestCase.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/BaseRewriterTestCase.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/BaseRewriterTestCase.java Wed Oct 1 16:54:27 2008
@@ -17,21 +17,22 @@
*/
package org.apache.shindig.gadgets.rewrite;
-import com.google.common.collect.Sets;
-
-import org.apache.commons.lang.StringUtils;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.EasyMockTestCase;
import org.apache.shindig.gadgets.GadgetException;
import org.apache.shindig.gadgets.spec.GadgetSpec;
-import java.net.URI;
+import com.google.common.collect.Sets;
+
+import org.apache.commons.lang.StringUtils;
+
import java.util.Set;
/**
* Base class for testing content rewriting functionality
*/
public abstract class BaseRewriterTestCase extends EasyMockTestCase {
- static final URI SPEC_URL = URI.create("http://example.org/g.xml");
+ static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
protected Set<String> tags;
protected ContentRewriterFeature contentRewriterFeature;
protected LinkRewriter defaultRewriter;
@@ -43,7 +44,7 @@
contentRewriterFeature = new ContentRewriterFeature(getSpecWithoutRewrite(), ".*", "", "HTTP",
tags);
defaultRewriter = new ProxyingLinkRewriter(
- SPEC_URL,
+ SPEC_URL.toJavaUri(),
contentRewriterFeature,
"http://www.test.com/proxy?url=");
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/CachingContentRewriterRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/CachingContentRewriterRegistryTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/CachingContentRewriterRegistryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/CachingContentRewriterRegistryTest.java Wed Oct 1 16:54:27 2008
@@ -35,11 +35,11 @@
import org.junit.Test;
-import java.net.URI;
import java.util.List;
import java.util.Map;
public class CachingContentRewriterRegistryTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/gadget.xml");
private final CaptureRewriter captureRewriter = new CaptureRewriter();
private final List<CaptureRewriter> rewriters
= Lists.newArrayList(captureRewriter, new ModifyingCaptureContentRewriter());
@@ -53,7 +53,7 @@
public void gadgetGetsCached() throws Exception {
String body = "Hello, world";
String xml = "<Module><ModulePrefs title=''/><Content/></Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
GadgetContext context = new GadgetContext();
Gadget gadget = new Gadget()
.setContext(context)
@@ -70,7 +70,7 @@
public void gadgetFetchedFromCache() throws Exception {
String body = "Hello, world";
String xml = "<Module><ModulePrefs title=''/><Content/></Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
GadgetContext context = new GadgetContext();
@@ -89,7 +89,7 @@
public void noCacheGadgetDoesNotGetCached() throws Exception {
String body = "Hello, world";
String xml = "<Module><ModulePrefs title=''/><Content/></Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
GadgetContext context = new GadgetContext() {
@Override
public boolean getIgnoreCache() {
@@ -112,7 +112,7 @@
@Test
public void httpResponseGetsCached() throws Exception {
String body = "Hello, world";
- HttpRequest request = new HttpRequest(Uri.parse("#"));
+ HttpRequest request = new HttpRequest(SPEC_URL);
HttpResponse response = new HttpResponse(body);
registry.rewriteHttpResponse(request, response);
@@ -124,7 +124,7 @@
@Test
public void httpResponseFetchedFromCache() throws Exception {
String body = "Hello, world";
- HttpRequest request = new HttpRequest(Uri.parse("#"));
+ HttpRequest request = new HttpRequest(SPEC_URL);
HttpResponse response = new HttpResponse(body);
registry.rewriteHttpResponse(request, response);
@@ -138,7 +138,7 @@
@Test
public void noCacheHttpResponseDoesNotGetCached() throws Exception {
String body = "Hello, world";
- HttpRequest request = new HttpRequest(Uri.parse("#")).setIgnoreCache(true);
+ HttpRequest request = new HttpRequest(SPEC_URL).setIgnoreCache(true);
HttpResponse response = new HttpResponse(body);
registry.rewriteHttpResponse(request, response);
@@ -158,7 +158,7 @@
// Just HTTP here; we'll assume this code is common between both methods.
String body = "Hello, world";
- HttpRequest request = new HttpRequest(Uri.parse("#"));
+ HttpRequest request = new HttpRequest(SPEC_URL);
HttpResponse response = new HttpResponse(body);
registry.rewriteHttpResponse(request, response);
@@ -186,7 +186,7 @@
String body = "Hello, world";
String xml = "<Module><ModulePrefs title=''/><Content/></Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
GadgetContext context = new GadgetContext();
// We have to re-create Gadget objects because they get mutated directly, which is really
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/DefaultContentRewriterRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/DefaultContentRewriterRegistryTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/DefaultContentRewriterRegistryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/DefaultContentRewriterRegistryTest.java Wed Oct 1 16:54:27 2008
@@ -31,11 +31,11 @@
import org.junit.Test;
-import java.net.URI;
import java.util.Arrays;
import java.util.List;
public class DefaultContentRewriterRegistryTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/gadget.xml");
private final List<CaptureRewriter> rewriters
= Arrays.asList(new CaptureRewriter(), new CaptureRewriter());
private final List<ContentRewriter> contentRewriters
@@ -47,7 +47,7 @@
public void rewriteGadget() throws Exception {
String body = "Hello, world";
String xml = "<Module><ModulePrefs title=''/><Content>" + body + "</Content></Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(SPEC_URL, xml);
GadgetContext context = new GadgetContext();
Gadget gadget = new Gadget()
.setContext(context)
@@ -64,7 +64,7 @@
@Test
public void rewriteHttpResponse() throws Exception {
String body = "Hello, world";
- HttpRequest request = new HttpRequest(Uri.parse("#"));
+ HttpRequest request = new HttpRequest(SPEC_URL);
HttpResponse response = new HttpResponse(body);
HttpResponse rewritten = registry.rewriteHttpResponse(request, response);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/FeatureBasedRewriterTestBase.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/FeatureBasedRewriterTestBase.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/FeatureBasedRewriterTestBase.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/FeatureBasedRewriterTestBase.java Wed Oct 1 16:54:27 2008
@@ -20,16 +20,17 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.replay;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.Gadget;
import org.apache.shindig.gadgets.GadgetContext;
import org.apache.shindig.gadgets.parse.GadgetHtmlParser;
import org.apache.shindig.gadgets.parse.ParsedHtmlNode;
import org.apache.shindig.gadgets.spec.GadgetSpec;
-import org.easymock.classextension.EasyMock;
-
import junit.framework.TestCase;
+import org.easymock.classextension.EasyMock;
+
import java.net.URI;
import java.util.Arrays;
import java.util.HashSet;
@@ -75,7 +76,7 @@
MutableContent mc = new MutableContent(parser);
mc.setContent(s);
- GadgetSpec spec = new GadgetSpec(baseUri,
+ GadgetSpec spec = new GadgetSpec(Uri.fromJavaUri(baseUri),
"<Module><ModulePrefs title=''/><Content><![CDATA[" + s + "]]></Content></Module>");
GadgetContext context = new GadgetContext() {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/JsTagConcatContentRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/JsTagConcatContentRewriterTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/JsTagConcatContentRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/JsTagConcatContentRewriterTest.java Wed Oct 1 16:54:27 2008
@@ -18,19 +18,21 @@
*/
package org.apache.shindig.gadgets.rewrite;
-import org.easymock.classextension.EasyMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.replay;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.parse.GadgetHtmlNodeTest;
import org.apache.shindig.gadgets.parse.ParsedHtmlNode;
import org.apache.shindig.gadgets.spec.GadgetSpec;
+import org.easymock.classextension.EasyMock;
+
public class JsTagConcatContentRewriterTest extends FeatureBasedRewriterTestBase {
private ContentRewriterFeature jsFeature;
private JsTagConcatContentRewriter rewriter;
private String concatBase;
-
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -38,7 +40,7 @@
ContentRewriterFeature.Factory factory = mockContentRewriterFeatureFactory(jsFeature);
rewriter = new JsTagConcatContentRewriter(factory, null);
GadgetSpec spec = EasyMock.createNiceMock(GadgetSpec.class);
- expect(spec.getUrl()).andReturn(baseUri).anyTimes();
+ expect(spec.getUrl()).andReturn(Uri.fromJavaUri(baseUri)).anyTimes();
replay(spec);
concatBase = rewriter.getJsConcatBase(spec, jsFeature);
}
@@ -172,7 +174,7 @@
String s = "<script src=\"/1.js\"></script>";
String[][] attr1 = { { "src", "/1.js" } };
ParsedHtmlNode[] p = {
- GadgetHtmlNodeTest.makeParsedTagNode("script", attr1, null)
+ GadgetHtmlNodeTest.makeParsedTagNode("script", attr1, null)
};
String rewritten
= "<script src=\"" + concatBase + "1=http%3A%2F%2Fgadget.org%2F1.js\"></script>";
@@ -183,7 +185,7 @@
String s = "<script src=\"1.js\"></script>";
String[][] attr1 = { { "src", "1.js" } };
ParsedHtmlNode[] p = {
- GadgetHtmlNodeTest.makeParsedTagNode("script", attr1, null)
+ GadgetHtmlNodeTest.makeParsedTagNode("script", attr1, null)
};
String rewritten
= "<script src=\"" + concatBase + "1=http%3A%2F%2Fgadget.org%2Fdir%2F1.js\"></script>";
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ProxyingLinkRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ProxyingLinkRewriterTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ProxyingLinkRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ProxyingLinkRewriterTest.java Wed Oct 1 16:54:27 2008
@@ -23,11 +23,11 @@
* Test of proxying rewriter
*/
public class ProxyingLinkRewriterTest extends BaseRewriterTestCase {
-
+
private String rewrite(String uri) {
- return defaultRewriter.rewrite(uri, SPEC_URL);
+ return defaultRewriter.rewrite(uri, SPEC_URL.toJavaUri());
}
-
+
public void testAbsoluteRewrite() {
String val = "http://a.b.com";
assertEquals("http://www.test.com/proxy?url=http%3A%2F%2Fa.b.com&gadget=http%3A%2F%2Fexample.org%2Fg.xml&fp=-840722081",
@@ -57,12 +57,12 @@
getSpecWithoutRewrite(), ".*", "", "86400",
Sets.newHashSet("embed", "img", "script", "link"));
ProxyingLinkRewriter rewriter = new ProxyingLinkRewriter(
- SPEC_URL,
+ SPEC_URL.toJavaUri(),
contentRewriterFeature,
"http://www.test.com/proxy?url=");
String val = " test.gif ";
assertEquals("http://www.test.com/proxy?url=http%3A%2F%2Fexample.org%2Ftest.gif&gadget=http%3A%2F%2Fexample.org%2Fg.xml&fp=-840722081&refresh=86400",
- rewriter.rewrite(val, SPEC_URL));
+ rewriter.rewrite(val, SPEC_URL.toJavaUri()));
}
public void testInvalidCharRewrite() {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcHandlerTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcHandlerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcHandlerTest.java Wed Oct 1 16:54:27 2008
@@ -243,7 +243,7 @@
}
try {
- GadgetSpec spec = new GadgetSpec(URI.create("#"), gadgets.get(context.getUrl()));
+ GadgetSpec spec = new GadgetSpec(Uri.parse("#"), gadgets.get(context.getUrl()));
View view = spec.getView(context.getView());
return new Gadget()
.setContext(context)
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java Wed Oct 1 16:54:27 2008
@@ -19,16 +19,15 @@
package org.apache.shindig.gadgets.spec;
-import junit.framework.TestCase;
-
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.GadgetException;
import org.apache.shindig.gadgets.variables.Substitutions;
import org.apache.shindig.gadgets.variables.Substitutions.Type;
-import java.net.URI;
+import junit.framework.TestCase;
public class GadgetSpecTest extends TestCase {
- private static final URI SPEC_URL = URI.create("http://example.org/g.xml");
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
public void testBasic() throws Exception {
String xml = "<Module>" +
"<ModulePrefs title=\"title\"/>" +
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LinkSpecTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LinkSpecTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LinkSpecTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LinkSpecTest.java Wed Oct 1 16:54:27 2008
@@ -20,38 +20,50 @@
import static org.junit.Assert.assertEquals;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.variables.Substitutions;
import org.junit.Test;
-import java.net.URI;
-
/**
* Tests for Link.
*/
public class LinkSpecTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
private static final String REL_VALUE = "foo";
- private static final URI HREF_VALUE = URI.create("http://example.org/foo");
+ private static final Uri HREF_VALUE = Uri.parse("http://example.org/foo");
@Test
public void parseBasicLink() throws Exception {
String xml = "<Link rel='" + REL_VALUE + "' href='" + HREF_VALUE + "'/>";
- LinkSpec link = new LinkSpec(XmlUtil.parse(xml));
+ LinkSpec link = new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
assertEquals(REL_VALUE, link.getRel());
assertEquals(HREF_VALUE, link.getHref());
}
@Test
+ public void parseRelativeLink() throws Exception {
+ String xml = "<Link rel='" + REL_VALUE + "' href='/foo'/>";
+
+ LinkSpec link = new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
+
+ link = link.substitute(new Substitutions());
+
+ assertEquals(REL_VALUE, link.getRel());
+ assertEquals(HREF_VALUE.resolve(Uri.parse("/foo")), link.getHref());
+ }
+
+ @Test
public void substitutionsPerformed() throws Exception {
String rel = "foo.bar";
String href = "jp-DE.xml";
- URI expectedHref = URI.create("http://example.org/jp-DE.xml");
+ Uri expectedHref = Uri.parse("http://example.org/jp-DE.xml");
String xml = "<Link rel='__MSG_rel__' href='http://example.org/__MSG_href__'/>";
- LinkSpec link = new LinkSpec(XmlUtil.parse(xml));
+ LinkSpec link = new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
Substitutions substitutions = new Substitutions();
substitutions.addSubstitution(Substitutions.Type.MESSAGE, "rel", rel);
substitutions.addSubstitution(Substitutions.Type.MESSAGE, "href", href);
@@ -64,27 +76,27 @@
@Test(expected = SpecParserException.class)
public void parseNoRel() throws Exception {
String xml = "<Link href='foo'/>";
- new LinkSpec(XmlUtil.parse(xml));
+ new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
}
@Test(expected = SpecParserException.class)
public void parseNoHref() throws Exception {
String xml = "<Link rel='bar'/>";
- new LinkSpec(XmlUtil.parse(xml));
+ new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
}
@Test(expected = SpecParserException.class)
public void parseBogusHref() throws Exception {
String xml = "<Link rel='foo' href='$%^$#%$#$%'/>";
- new LinkSpec(XmlUtil.parse(xml));
+ new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
}
@Test
public void toStringIsSane() throws Exception {
String xml = "<Link rel='" + REL_VALUE + "' href='" + HREF_VALUE + "'/>";
- LinkSpec link = new LinkSpec(XmlUtil.parse(xml));
- LinkSpec link2 = new LinkSpec(XmlUtil.parse(link.toString()));
+ LinkSpec link = new LinkSpec(XmlUtil.parse(xml), SPEC_URL);
+ LinkSpec link2 = new LinkSpec(XmlUtil.parse(link.toString()), SPEC_URL);
assertEquals(link.getRel(), link2.getRel());
assertEquals(link.getHref(), link2.getHref());
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LocaleSpecTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LocaleSpecTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LocaleSpecTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/LocaleSpecTest.java Wed Oct 1 16:54:27 2008
@@ -21,14 +21,13 @@
import static org.junit.Assert.assertEquals;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.junit.Test;
-import java.net.URI;
-
public class LocaleSpecTest {
- private static final URI SPEC_URL = URI.create("http://example.org/foo.xml");
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/foo.xml");
@Test
public void normalLocale() throws Exception {
@@ -42,16 +41,14 @@
assertEquals("en", locale.getLanguage());
assertEquals("US", locale.getCountry());
assertEquals("rtl", locale.getLanguageDirection());
- assertEquals("http://example.org/msgs.xml",
- locale.getMessages().toString());
+ assertEquals("http://example.org/msgs.xml", locale.getMessages().toString());
}
@Test
public void relativeLocale() throws Exception {
String xml = "<Locale messages=\"/test/msgs.xml\"/>";
LocaleSpec locale = new LocaleSpec(XmlUtil.parse(xml), SPEC_URL);
- assertEquals("http://example.org/test/msgs.xml",
- locale.getMessages().toString());
+ assertEquals("http://example.org/test/msgs.xml", locale.getMessages().toString());
}
@Test
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/MessageBundleTest.java Wed Oct 1 16:54:27 2008
@@ -19,18 +19,21 @@
package org.apache.shindig.gadgets.spec;
-import com.google.common.collect.Maps;
-import org.apache.shindig.common.xml.XmlUtil;
import static org.junit.Assert.assertEquals;
+
+import org.apache.shindig.common.uri.Uri;
+import org.apache.shindig.common.xml.XmlUtil;
+
+import com.google.common.collect.Maps;
+
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Element;
-import java.net.URI;
import java.util.Map;
public class MessageBundleTest {
- private static final URI BUNDLE_URL = URI.create("http://example.org/m.xml");
+ private static final Uri BUNDLE_URL = Uri.parse("http://example.org/m.xml");
private static final String LOCALE
= "<Locale lang='en' country='US' messages='" + BUNDLE_URL + "'/>";
private static final String PARENT_LOCALE
@@ -58,7 +61,7 @@
@Before
public void setUp() throws Exception {
- locale = new LocaleSpec(XmlUtil.parse(LOCALE), URI.create("http://example.org/gadget"));
+ locale = new LocaleSpec(XmlUtil.parse(LOCALE), Uri.parse("http://example.org/gadget"));
}
@Test
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ModulePrefsTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ModulePrefsTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ModulePrefsTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ModulePrefsTest.java Wed Oct 1 16:54:27 2008
@@ -24,16 +24,16 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.variables.Substitutions;
import org.junit.Test;
-import java.net.URI;
import java.util.Locale;
public class ModulePrefsTest {
- private static final URI SPEC_URL = URI.create("http://example.org/g.xml");
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
private static final String FULL_XML
= "<ModulePrefs" +
" title='title'" +
@@ -66,10 +66,10 @@
" <Link rel='link' href='http://example.org/link'/>" +
" <OAuth>" +
" <Service name='serviceOne'>" +
- " <Request url='http://www.example.com/request'" +
+ " <Request url='http://www.example.com/request'" +
" method='GET' param_location='auth-header' />" +
" <Authorization url='http://www.example.com/authorize'/>" +
- " <Access url='http://www.example.com/access' method='GET'" +
+ " <Access url='http://www.example.com/access' method='GET'" +
" param_location='auth-header' />" +
" </Service>" +
" </OAuth>" +
@@ -77,12 +77,12 @@
private void doAsserts(ModulePrefs prefs) {
assertEquals("title", prefs.getTitle());
- assertEquals("title_url", prefs.getTitleUrl().toString());
+ assertEquals(SPEC_URL.resolve(Uri.parse("title_url")), prefs.getTitleUrl());
assertEquals("description", prefs.getDescription());
assertEquals("author", prefs.getAuthor());
assertEquals("author_email", prefs.getAuthorEmail());
- assertEquals("screenshot", prefs.getScreenshot().toString());
- assertEquals("thumbnail", prefs.getThumbnail().toString());
+ assertEquals(SPEC_URL.resolve(Uri.parse("screenshot")), prefs.getScreenshot());
+ assertEquals(SPEC_URL.resolve(Uri.parse("thumbnail")), prefs.getThumbnail());
assertEquals("directory_title", prefs.getDirectoryTitle());
assertEquals(1, prefs.getWidth());
assertEquals(2, prefs.getHeight());
@@ -92,7 +92,8 @@
assertEquals("category2", prefs.getCategories().get(1));
assertEquals("author_affiliation", prefs.getAuthorAffiliation());
assertEquals("author_location", prefs.getAuthorLocation());
- assertEquals("author_photo", prefs.getAuthorPhoto());
+ assertEquals(SPEC_URL.resolve(Uri.parse("author_photo")), prefs.getAuthorPhoto());
+ assertEquals(SPEC_URL.resolve(Uri.parse("author_link")), prefs.getAuthorLink());
assertEquals("author_aboutme", prefs.getAuthorAboutme());
assertEquals("author_quote", prefs.getAuthorQuote());
assertEquals(true, prefs.getShowStats());
@@ -109,15 +110,14 @@
assertEquals(1, prefs.getLocales().size());
- assertEquals(URI.create("http://example.org/link"),
- prefs.getLinks().get("link").getHref());
-
+ assertEquals(Uri.parse("http://example.org/link"), prefs.getLinks().get("link").getHref());
+
OAuthService oauth = prefs.getOAuthSpec().getServices().get("serviceOne");
- assertEquals(URI.create("http://www.example.com/request"), oauth.getRequestUrl().url);
+ assertEquals(Uri.parse("http://www.example.com/request"), oauth.getRequestUrl().url);
assertEquals(OAuthService.Method.GET, oauth.getRequestUrl().method);
assertEquals(OAuthService.Method.GET, oauth.getAccessUrl().method);
assertEquals(OAuthService.Location.HEADER, oauth.getAccessUrl().location);
- assertEquals(URI.create("http://www.example.com/authorize"), oauth.getAuthorizationUrl());
+ assertEquals(Uri.parse("http://www.example.com/authorize"), oauth.getAuthorizationUrl());
}
@Test
@@ -154,17 +154,18 @@
public void getLinks() throws Exception {
String link1Rel = "foo";
String link2Rel = "bar";
- URI link1Href = URI.create("http://example.org/foo");
- URI link2Href = URI.create("http://example.org/bar");
+ Uri link1Href = Uri.parse("http://example.org/foo");
+ Uri link2Href = Uri.parse("/bar");
String xml = "<ModulePrefs title='links'>" +
" <Link rel='" + link1Rel + "' href='" + link1Href + "'/>" +
" <Link rel='" + link2Rel + "' href='" + link2Href + "'/>" +
"</ModulePrefs>";
- ModulePrefs prefs = new ModulePrefs(XmlUtil.parse(xml), SPEC_URL);
+ ModulePrefs prefs = new ModulePrefs(XmlUtil.parse(xml), SPEC_URL)
+ .substitute(new Substitutions());
assertEquals(link1Href, prefs.getLinks().get(link1Rel).getHref());
- assertEquals(link2Href, prefs.getLinks().get(link2Rel).getHref());
+ assertEquals(SPEC_URL.resolve(link2Href), prefs.getLinks().get(link2Rel).getHref());
}
@Test
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthServiceTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthServiceTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthServiceTest.java Wed Oct 1 16:54:27 2008
@@ -22,99 +22,99 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
-import java.net.URI;
-
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
+
import org.junit.Before;
import org.junit.Test;
public class OAuthServiceTest {
-
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
private OAuthService service;
@Before
public void setUp() {
service = new OAuthService();
}
-
+
@Test
public void testParseAuthorizeUrl() throws Exception {
String xml = "<Authorization url='http://azn.example.com'/>";
- URI url = service.parseAuthorizationUrl(XmlUtil.parse(xml));
+ Uri url = service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
assertEquals("http://azn.example.com", url.toString());
}
-
+
@Test
public void testParseAuthorizeUrl_nourl() throws Exception {
String xml = "<Authorization/>";
try {
- service.parseAuthorizationUrl(XmlUtil.parse(xml));
+ service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
fail("Should have rejected malformed Authorization element");
} catch (SpecParserException e) {
assertEquals("OAuth/Service/Authorization @url is not valid: ", e.getMessage());
}
}
-
+
@Test
public void testParseAuthorizeUrl_extraAttr() throws Exception {
String xml = "<Authorization url='http://www.example.com' foo='bar'/>";
- URI url = service.parseAuthorizationUrl(XmlUtil.parse(xml));
+ Uri url = service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
assertEquals("http://www.example.com", url.toString());
}
-
+
@Test
public void testParseAuthorizeUrl_notHttp() throws Exception {
OAuthService service = new OAuthService();
String xml = "<Authorization url='ftp://www.example.com'/>";
try {
- service.parseAuthorizationUrl(XmlUtil.parse(xml));
+ service.parseAuthorizationUrl(XmlUtil.parse(xml), SPEC_URL);
fail("Should have rejected malformed Authorization element");
} catch (SpecParserException e) {
assertEquals("OAuth/Service/Authorization @url is not valid: ftp://www.example.com", e.getMessage());
}
}
-
+
@Test
public void testParseEndPoint() throws Exception {
String xml = "<Request url='http://www.example.com'/>";
- OAuthService.EndPoint ep = service.parseEndPoint("Request", XmlUtil.parse(xml));
+ OAuthService.EndPoint ep = service.parseEndPoint("Request", XmlUtil.parse(xml), SPEC_URL);
assertEquals("http://www.example.com", ep.url.toString());
assertEquals(OAuthService.Location.HEADER, ep.location);
assertEquals(OAuthService.Method.GET, ep.method);
}
-
+
@Test
public void testParseEndPoint_badlocation() throws Exception {
try {
String xml = "<Request url='http://www.example.com' method='GET' param_location='body'/>";
- service.parseEndPoint("Request", XmlUtil.parse(xml));
+ service.parseEndPoint("Request", XmlUtil.parse(xml), SPEC_URL);
fail("Should have thrown");
} catch (SpecParserException e) {
assertEquals("Unknown OAuth param_location: body", e.getMessage());
}
}
-
+
@Test
public void testParseEndPoint_nodefaults() throws Exception {
String xml = "<Request url='http://www.example.com' method='GET' param_location='post-body'/>";
- OAuthService.EndPoint ep = service.parseEndPoint("Request", XmlUtil.parse(xml));
+ OAuthService.EndPoint ep = service.parseEndPoint("Request", XmlUtil.parse(xml), SPEC_URL);
assertEquals("http://www.example.com", ep.url.toString());
assertEquals(OAuthService.Location.BODY, ep.location);
- assertEquals(OAuthService.Method.GET, ep.method);
+ assertEquals(OAuthService.Method.GET, ep.method);
}
-
+
@Test(expected=SpecParserException.class)
public void testParseEndPoint_nourl() throws Exception {
String xml = "<Request method='GET' param_location='post-body'/>";
- service.parseEndPoint("Request", XmlUtil.parse(xml));
+ service.parseEndPoint("Request", XmlUtil.parse(xml), SPEC_URL);
}
-
+
@Test(expected=SpecParserException.class)
public void testParseEndPoint_badurl() throws Exception {
String xml = "<Request url='www.example.com' />";
- service.parseEndPoint("Request", XmlUtil.parse(xml));
+ service.parseEndPoint("Request", XmlUtil.parse(xml), SPEC_URL);
}
-
+
@Test
public void testParseService() throws Exception {
String xml = "" +
@@ -123,12 +123,12 @@
" <Access url='http://access.example.com/bar'/>" +
" <Authorization url='http://azn.example.com/quux'/>" +
"</Service>";
- OAuthService s = new OAuthService(XmlUtil.parse(xml));
+ OAuthService s = new OAuthService(XmlUtil.parse(xml), SPEC_URL);
assertEquals("thename", s.getName());
assertEquals(OAuthService.Location.HEADER, s.getAccessUrl().location);
assertEquals("http://azn.example.com/quux", s.getAuthorizationUrl().toString());
}
-
+
@Test
public void testParseService_noname() throws Exception {
String xml = "" +
@@ -137,17 +137,17 @@
" <Access url='http://access.example.com/bar'/>" +
" <Authorization url='http://azn.example.com/quux'/>" +
"</Service>";
- OAuthService s = new OAuthService(XmlUtil.parse(xml));
+ OAuthService s = new OAuthService(XmlUtil.parse(xml), SPEC_URL);
assertEquals("", s.getName());
assertEquals(OAuthService.Location.HEADER, s.getAccessUrl().location);
assertEquals("http://azn.example.com/quux", s.getAuthorizationUrl().toString());
}
-
+
@Test
public void testParseService_nodata() throws Exception {
String xml = "<Service/>";
try {
- new OAuthService(XmlUtil.parse(xml));
+ new OAuthService(XmlUtil.parse(xml), SPEC_URL);
} catch (SpecParserException e) {
assertEquals("/OAuth/Service/Request is required", e.getMessage());
}
@@ -159,7 +159,7 @@
"<Request url='http://www.example.com/request'/>" +
"</Service>";
try {
- new OAuthService(XmlUtil.parse(xml));
+ new OAuthService(XmlUtil.parse(xml), SPEC_URL);
} catch (SpecParserException e) {
assertEquals("/OAuth/Service/Access is required", e.getMessage());
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthSpecTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthSpecTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthSpecTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/OAuthSpecTest.java Wed Oct 1 16:54:27 2008
@@ -19,13 +19,16 @@
import static org.junit.Assert.assertEquals;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
+
import org.junit.Test;
/**
* Tests for OAuthSpec
*/
public class OAuthSpecTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
@Test
public void testOAuthSpec() throws Exception {
@@ -34,14 +37,14 @@
"<Access url='http://www.example.com/access'/>" +
"<Authorization url='http://www.example.com/authorize'/>" +
"</Service></OAuth>";
- OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml));
+ OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml), SPEC_URL);
assertEquals(1, oauth.getServices().size());
}
-
+
@Test
public void testOAuthSpec_noservice() throws Exception {
String xml = "<OAuth/>";
- OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml));
+ OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml), SPEC_URL);
assertEquals(0, oauth.getServices().size());
}
@@ -64,7 +67,7 @@
" <Authorization url='http://three.example.com/authorize'/>" +
"</Service>" +
"</OAuth>";
- OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml));
+ OAuthSpec oauth = new OAuthSpec(XmlUtil.parse(xml), SPEC_URL);
assertEquals("http://req.example.com",
oauth.getServices().get("one").getRequestUrl().url.toString());
assertEquals(OAuthService.Location.URL,
@@ -74,8 +77,8 @@
assertEquals(OAuthService.Method.POST,
oauth.getServices().get("three").getRequestUrl().method);
assertEquals("http://three.example.com/acc",
- oauth.getServices().get("three").getAccessUrl().url.toASCIIString());
+ oauth.getServices().get("three").getAccessUrl().url.toJavaUri().toASCIIString());
assertEquals("http://three.example.com/authorize",
- oauth.getServices().get("three").getAuthorizationUrl().toASCIIString());
+ oauth.getServices().get("three").getAuthorizationUrl().toJavaUri().toASCIIString());
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PreloadTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PreloadTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PreloadTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/PreloadTest.java Wed Oct 1 16:54:27 2008
@@ -21,6 +21,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.AuthType;
import org.apache.shindig.gadgets.variables.Substitutions;
@@ -36,6 +37,7 @@
* Tests for Preload
*/
public class PreloadTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
private final static String HREF = "http://example.org/preload.xml";
private final static Set<String> VIEWS
= new HashSet<String>(Arrays.asList("view0", "view1"));
@@ -44,7 +46,7 @@
public void basicPreload() throws Exception {
String xml = "<Preload href='" + HREF + "'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
assertEquals(HREF, preload.getHref().toString());
assertEquals(AuthType.NONE, preload.getAuthType());
@@ -59,7 +61,7 @@
public void authzSigned() throws Exception {
String xml = "<Preload href='" + HREF + "' authz='signed'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
assertEquals(AuthType.SIGNED, preload.getAuthType());
}
@@ -68,7 +70,7 @@
public void authzOAuth() throws Exception {
String xml = "<Preload href='" + HREF + "' authz='oauth'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
assertEquals(AuthType.OAUTH, preload.getAuthType());
}
@@ -77,7 +79,7 @@
public void authzUnknownTreatedAsNone() throws Exception {
String xml = "<Preload href='foo' authz='bad-bad-bad value!'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
assertEquals(AuthType.NONE, preload.getAuthType());
}
@@ -87,7 +89,7 @@
String xml = "<Preload href='" + HREF + '\'' +
" views='" + StringUtils.join(VIEWS, ',') + "'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
assertEquals(VIEWS, preload.getViews());
}
@@ -96,7 +98,7 @@
public void substitutionsOk() throws Exception {
String xml = "<Preload href='__MSG_preload__'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
Substitutions substituter = new Substitutions();
substituter.addSubstitution(Substitutions.Type.MESSAGE, "preload", HREF);
Preload substituted = preload.substitute(substituter);
@@ -105,10 +107,22 @@
}
@Test
+ public void relativeSubstitutionsOk() throws Exception {
+ String xml = "<Preload href='__MSG_preload__'/>";
+
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
+ Substitutions substituter = new Substitutions();
+ substituter.addSubstitution(Substitutions.Type.MESSAGE, "preload", "relative");
+ Preload substituted = preload.substitute(substituter);
+
+ assertEquals(SPEC_URL.resolve(Uri.parse("relative")), substituted.getHref());
+ }
+
+ @Test
public void arbitraryAttributes() throws Exception {
String xml = "<Preload href='" + HREF + "' foo='bar' yo='momma' sub='__MSG_preload__'/>";
- Preload preload = new Preload(XmlUtil.parse(xml));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
Substitutions substituter = new Substitutions();
substituter.addSubstitution(Substitutions.Type.MESSAGE, "preload", "stuff");
Preload substituted = preload.substitute(substituter);
@@ -125,8 +139,8 @@
" views='" + StringUtils.join(VIEWS, ',') + "'" +
" some_attribute='yes' />";
- Preload preload = new Preload(XmlUtil.parse(xml));
- Preload preload2 = new Preload(XmlUtil.parse(preload.toString()));
+ Preload preload = new Preload(XmlUtil.parse(xml), SPEC_URL);
+ Preload preload2 = new Preload(XmlUtil.parse(preload.toString()), SPEC_URL);
assertEquals(VIEWS, preload2.getViews());
assertEquals(HREF, preload2.getHref().toString());
@@ -137,12 +151,12 @@
@Test(expected = SpecParserException.class)
public void missingHrefThrows() throws Exception {
String xml = "<Preload/>";
- new Preload(XmlUtil.parse(xml));
+ new Preload(XmlUtil.parse(xml), SPEC_URL);
}
@Test(expected = SpecParserException.class)
public void malformedHrefThrows() throws Exception {
String xml = "<Preload href='@$%@$%$%'/>";
- new Preload(XmlUtil.parse(xml));
+ new Preload(XmlUtil.parse(xml), SPEC_URL);
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ViewTest.java Wed Oct 1 16:54:27 2008
@@ -23,6 +23,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.common.xml.XmlUtil;
import org.apache.shindig.gadgets.variables.Substitutions;
import org.apache.shindig.gadgets.variables.Substitutions.Type;
@@ -32,6 +33,7 @@
import java.util.Arrays;
public class ViewTest {
+ private static final Uri SPEC_URL = Uri.parse("http://example.org/g.xml");
@Test
public void testSimpleView() throws Exception {
@@ -45,7 +47,7 @@
content +
"]]></Content>";
- View view = new View(viewName, Arrays.asList(XmlUtil.parse(xml)));
+ View view = new View(viewName, Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
assertEquals(viewName, view.getName());
assertEquals(false, view.getQuirks());
@@ -58,13 +60,13 @@
@Test
public void testConcatenation() throws Exception {
- String body1 = "Hello, ";
- String body2 = "World!";
- String content1 = "<Content type=\"html\">" + body1 + "</Content>";
- String content2 = "<Content type=\"html\">" + body2 + "</Content>";
- View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
- XmlUtil.parse(content2)));
- assertEquals(body1 + body2, view.getContent());
+ String body1 = "Hello, ";
+ String body2 = "World!";
+ String content1 = "<Content type=\"html\">" + body1 + "</Content>";
+ String content2 = "<Content type=\"html\">" + body2 + "</Content>";
+ View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
+ XmlUtil.parse(content2)), SPEC_URL);
+ assertEquals(body1 + body2, view.getContent());
}
@Test
@@ -73,7 +75,7 @@
String xml = "<Content" +
" type=\"" + contentType + '\"' +
" quirks=\"false\"><![CDATA[blah]]></Content>";
- View view = new View("default", Arrays.asList(XmlUtil.parse(xml)));
+ View view = new View("default", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
assertEquals(View.ContentType.HTML, view.getType());
assertEquals(contentType, view.getRawType());
@@ -83,13 +85,13 @@
public void testContentTypeConflict() throws Exception {
String content1 = "<Content type=\"html\"/>";
String content2 = "<Content type=\"url\" href=\"http://example.org/\"/>";
- new View("test", Arrays.asList(XmlUtil.parse(content1), XmlUtil.parse(content2)));
+ new View("test", Arrays.asList(XmlUtil.parse(content1), XmlUtil.parse(content2)), SPEC_URL);
}
@Test(expected = SpecParserException.class)
public void testHrefOnTypeUrl() throws Exception {
String xml = "<Content type=\"url\"/>";
- new View("dummy", Arrays.asList(XmlUtil.parse(xml)));
+ new View("dummy", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
}
@Test(expected = SpecParserException.class)
@@ -97,7 +99,7 @@
// Unfortunately, this actually does URI validation rather than URL, so
// most anything will pass. urn:isbn:0321146530 is valid here.
String xml = "<Content type=\"url\" href=\"fobad@$%!fdf\"/>";
- new View("dummy", Arrays.asList(XmlUtil.parse(xml)));
+ new View("dummy", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
}
@Test
@@ -105,7 +107,7 @@
String content1 = "<Content type=\"html\" quirks=\"true\"/>";
String content2 = "<Content type=\"html\" quirks=\"false\"/>";
View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
- XmlUtil.parse(content2)));
+ XmlUtil.parse(content2)), SPEC_URL);
assertEquals(false, view.getQuirks());
}
@@ -114,7 +116,7 @@
String content1 = "<Content type=\"html\" quirks=\"false\"/>";
String content2 = "<Content type=\"html\" quirks=\"true\"/>";
View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
- XmlUtil.parse(content2)));
+ XmlUtil.parse(content2)), SPEC_URL);
assertEquals(true, view.getQuirks());
}
@@ -123,7 +125,7 @@
String content1 = "<Content type=\"html\" preferred_height=\"100\"/>";
String content2 = "<Content type=\"html\" preferred_height=\"300\"/>";
View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
- XmlUtil.parse(content2)));
+ XmlUtil.parse(content2)), SPEC_URL);
assertEquals(300, view.getPreferredHeight());
}
@@ -132,7 +134,7 @@
String content1 = "<Content type=\"html\" preferred_width=\"300\"/>";
String content2 = "<Content type=\"html\" preferred_width=\"172\"/>";
View view = new View("test", Arrays.asList(XmlUtil.parse(content1),
- XmlUtil.parse(content2)));
+ XmlUtil.parse(content2)), SPEC_URL);
assertEquals(172, view.getPreferredWidth());
}
@@ -142,14 +144,13 @@
= "<Content type=\"html\">Hello, __MSG_world__ __MODULE_ID__</Content>";
Substitutions substituter = new Substitutions();
- substituter.addSubstitution(Type.MESSAGE, "world",
- "foo __UP_planet____BIDI_START_EDGE__");
+ substituter.addSubstitution(Type.MESSAGE, "world", "foo __UP_planet____BIDI_START_EDGE__");
substituter.addSubstitution(Type.USER_PREF, "planet", "Earth");
substituter.addSubstitution(Type.BIDI, "START_EDGE", "right");
substituter.addSubstitution(Type.MODULE, "ID", "3");
View view = new View("test",
- Arrays.asList(XmlUtil.parse(xml))).substitute(substituter);
+ Arrays.asList(XmlUtil.parse(xml)), SPEC_URL).substitute(substituter);
assertEquals("Hello, foo Earthright 3", view.getContent());
}
@@ -159,24 +160,36 @@
String xml = "<Content type=\"url\" href=\"" + href + "\"/>";
Substitutions substituter = new Substitutions();
- substituter.addSubstitution(Type.MESSAGE, "domain",
- "__UP_subDomain__.example.org");
+ substituter.addSubstitution(Type.MESSAGE, "domain", "__UP_subDomain__.example.org");
substituter.addSubstitution(Type.USER_PREF, "subDomain", "up");
substituter.addSubstitution(Type.BIDI, "DIR", "rtl");
substituter.addSubstitution(Type.MODULE, "ID", "123");
View view = new View("test",
- Arrays.asList(XmlUtil.parse(xml))).substitute(substituter);
+ Arrays.asList(XmlUtil.parse(xml)), SPEC_URL).substitute(substituter);
assertEquals("http://up.example.org/123?dir=rtl",
view.getHref().toString());
}
@Test
+ public void testHrefRelativeSubstitution() throws Exception {
+ String href = "__MSG_foo__";
+ String xml = "<Content type=\"url\" href=\"" + href + "\"/>";
+
+ Substitutions substituter = new Substitutions();
+ substituter.addSubstitution(Type.MESSAGE, "foo", "/bar");
+
+ View view = new View("test", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
+ view = view.substitute(substituter);
+ assertEquals(SPEC_URL.resolve(Uri.parse("/bar")), view.getHref());
+ }
+
+ @Test
public void authAttributes() throws Exception {
String xml = "<Content type='html' sign_owner='false' sign_viewer='false' foo='bar' " +
"yo='momma' sub='__MSG_view__'/>";
- View view = new View("test", Arrays.asList(XmlUtil.parse(xml)));
+ View view = new View("test", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
Substitutions substituter = new Substitutions();
substituter.addSubstitution(Substitutions.Type.MESSAGE, "view", "stuff");
View substituted = view.substitute(substituter);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/UserPrefSubstituterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/UserPrefSubstituterTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/UserPrefSubstituterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/UserPrefSubstituterTest.java Wed Oct 1 16:54:27 2008
@@ -19,15 +19,13 @@
package org.apache.shindig.gadgets.variables;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.UserPrefs;
import org.apache.shindig.gadgets.spec.GadgetSpec;
-import org.apache.shindig.gadgets.variables.Substitutions;
-import org.apache.shindig.gadgets.variables.UserPrefSubstituter;
import org.apache.shindig.gadgets.variables.Substitutions.Type;
import junit.framework.TestCase;
-import java.net.URI;
import java.util.HashMap;
import java.util.Map;
@@ -57,7 +55,7 @@
@Override
public void setUp() throws Exception {
super.setUp();
- spec = new GadgetSpec(URI.create(""), DEFAULT_XML);
+ spec = new GadgetSpec(Uri.parse("#"), DEFAULT_XML);
}
public void testSubstitutions() throws Exception {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/VariableSubstituterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/VariableSubstituterTest.java?rev=700975&r1=700974&r2=700975&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/VariableSubstituterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/VariableSubstituterTest.java Wed Oct 1 16:54:27 2008
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
+import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.GadgetContext;
import org.apache.shindig.gadgets.GadgetException;
import org.apache.shindig.gadgets.MessageBundleFactory;
@@ -27,13 +28,11 @@
import org.apache.shindig.gadgets.spec.GadgetSpec;
import org.apache.shindig.gadgets.spec.LocaleSpec;
import org.apache.shindig.gadgets.spec.MessageBundle;
-import org.apache.shindig.gadgets.variables.VariableSubstituter;
import com.google.common.collect.Maps;
import org.junit.Test;
-import java.net.URI;
import java.util.Locale;
public class VariableSubstituterTest {
@@ -41,7 +40,7 @@
private final VariableSubstituter substituter = new VariableSubstituter(messageBundleFactory);
private GadgetSpec substitute(String xml) throws Exception {
- return substituter.substitute(new GadgetContext(), new GadgetSpec(URI.create("#"), xml));
+ return substituter.substitute(new GadgetContext(), new GadgetSpec(Uri.parse("#"), xml));
}
@Test
@@ -83,7 +82,7 @@
"<UserPref name='foo'/>" +
"<Content/>" +
"</Module>";
- GadgetSpec spec = new GadgetSpec(URI.create("#"), xml);
+ GadgetSpec spec = new GadgetSpec(Uri.parse("#"), xml);
GadgetContext context = new GadgetContext() {
@Override
public UserPrefs getUserPrefs() {