You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by li...@apache.org on 2009/12/16 23:07:46 UTC
svn commit: r891450 [2/4] - in /incubator/shindig/trunk/java:
common/src/main/java/org/apache/shindig/expressions/
common/src/test/java/org/apache/shindig/auth/
common/src/test/java/org/apache/shindig/common/
common/src/test/java/org/apache/shindig/com...
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java Wed Dec 16 22:07:43 2009
@@ -182,7 +182,7 @@
Uri feature2Uri = expectResource(xml(BOTTOM_TPL, "gadget", null, content2));
// .txt file to join the two
- Uri txtFile = expectResource(feature1Uri.toString() + "\n" + feature2Uri.toString(), ".txt");
+ Uri txtFile = expectResource(feature1Uri.toString() + '\n' + feature2Uri.toString(), ".txt");
// Load resources from the text file and do basic validation they're good.
registry.register(txtFile.toString());
@@ -467,7 +467,7 @@
setupFullRegistry("gadget", null);
GadgetContext ctx = getCtx(RenderingContext.GADGET, null);
List<String> needed = Lists.newArrayList("top", "bottom");
- List<String> unsupported = Lists.<String>newLinkedList();
+ List<String> unsupported = Lists.newLinkedList();
List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported, false);
// Should return in order requested.
assertEquals(2, resources.size());
@@ -518,7 +518,7 @@
Uri loopAUri = expectResource(xml(LOOP_A_TPL, type, null, "loop_a"));
Uri loopBUri = expectResource(xml(LOOP_B_TPL, type, null, "loop_b"));
Uri loopCUri = expectResource(xml(LOOP_C_TPL, type, null, "loop_c"));
- Uri txtFile = expectResource(loopAUri.toString() + "\n" + loopBUri.toString() + "\n" +
+ Uri txtFile = expectResource(loopAUri.toString() + '\n' + loopBUri.toString() + '\n' +
loopCUri.toString(), ".txt");
try {
registry.register(txtFile.toString());
@@ -630,8 +630,8 @@
Uri midAUri = expectResource(xml(MID_A_TPL, type, null, "mid_a", attribs));
Uri midBUri = expectResource(xml(MID_B_TPL, type, null, "mid_b", attribs));
Uri bottomUri = expectResource(xml(BOTTOM_TPL, type, null, "bottom", attribs));
- Uri txtFile = expectResource(nodepUri.toString() + "\n" + topUri.toString() + "\n" +
- midAUri.toString() + "\n" + midBUri.toString() + "\n" + bottomUri.toString(), ".txt");
+ Uri txtFile = expectResource(nodepUri.toString() + '\n' + topUri.toString() + '\n' +
+ midAUri.toString() + '\n' + midBUri.toString() + '\n' + bottomUri.toString(), ".txt");
registry.register(txtFile.toString());
}
@@ -667,7 +667,7 @@
sb.append(entry.getKey()).append("=\"").append(entry.getValue()).append("\" ");
}
return tpl.replaceAll("%type%", type)
- .replaceAll("%uri%", uri != null ? "src=\"" + uri + "\"" : "")
+ .replaceAll("%uri%", uri != null ? "src=\"" + uri + '\"' : "")
.replaceAll("%content%", content != null ? content : "")
.replaceAll("%type_attribs%", sb.toString());
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/CacheKeyBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/CacheKeyBuilderTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/CacheKeyBuilderTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/CacheKeyBuilderTest.java Wed Dec 16 22:07:43 2009
@@ -17,10 +17,11 @@
*/
package org.apache.shindig.gadgets.http;
-import junit.framework.TestCase;
-
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.AuthType;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for the {@link CacheKeyBuilder}.
@@ -32,67 +33,76 @@
* changing the caching scheme across runs would generate lots of traffic due to artificial
* cache misses.
*/
-public class CacheKeyBuilderTest extends TestCase {
+public class CacheKeyBuilderTest extends Assert {
private CacheKeyBuilder builder;
- @Override
+ @Before
public void setUp() {
builder = new CacheKeyBuilder()
.setLegacyParam(0, Uri.parse("http://example.com"))
.setLegacyParam(1, AuthType.SIGNED);
}
+ @Test
public void testBuilder() {
assertEquals("http://example.com:signed:0:0:0:0:0:0:0", builder.build());
}
+ @Test
public void testOwner() {
builder.setLegacyParam(2, "owner");
assertEquals("http://example.com:signed:owner:0:0:0:0:0:0", builder.build());
}
+ @Test
public void testViewer() {
builder.setLegacyParam(3, "viewer");
assertEquals("http://example.com:signed:0:viewer:0:0:0:0:0", builder.build());
}
+ @Test
public void testTokenOwner() {
builder.setLegacyParam(4, "token");
assertEquals("http://example.com:signed:0:0:token:0:0:0:0", builder.build());
}
+ @Test
public void testAppUrl() {
builder.setLegacyParam(5, "appurl");
assertEquals("http://example.com:signed:0:0:0:appurl:0:0:0", builder.build());
}
+ @Test
public void testInstanceId() {
builder.setLegacyParam(6, "id");
assertEquals("http://example.com:signed:0:0:0:0:id:0:0", builder.build());
}
+ @Test
public void testServiceName() {
builder.setLegacyParam(7, "srv");
assertEquals("http://example.com:signed:0:0:0:0:0:srv:0", builder.build());
}
+ @Test
public void testTokenName() {
builder.setLegacyParam(8, "token");
assertEquals("http://example.com:signed:0:0:0:0:0:0:token", builder.build());
}
// The additional parameters, proxy image dimensions
-
+ @Test
public void testParam() {
builder.setParam("rh", 1);
assertEquals("http://example.com:signed:0:0:0:0:0:0:0:rh=1", builder.build());
}
+ @Test
public void testResizeParams() {
builder.setParam("rh", 1);
builder.setParam("rq", 2);
builder.setParam("rw", 3);
assertEquals("http://example.com:signed:0:0:0:0:0:0:0:rh=1:rq=2:rw=3", builder.build());
}
-}
+}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java Wed Dec 16 22:07:43 2009
@@ -17,7 +17,6 @@
*/
package org.apache.shindig.gadgets.http;
-import org.apache.shindig.common.cache.Cache;
import org.apache.shindig.common.cache.LruCacheProvider;
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.common.uri.Uri;
@@ -27,15 +26,16 @@
import com.google.common.collect.ImmutableSet;
-import junit.framework.TestCase;
-
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.concurrent.atomic.AtomicLong;
-public class DefaultInvalidationServiceTest extends TestCase {
+public class DefaultInvalidationServiceTest extends Assert {
private static final Uri URI = Uri.parse("http://www.example.org/spec.xml");
private static final HttpResponse CACHEABLE = new HttpResponseBuilder()
@@ -55,7 +55,7 @@
HttpRequest signedRequest;
- @Override
+ @Before
public void setUp() {
cacheProvider = new LruCacheProvider(100);
cache = new DefaultHttpCache(cacheProvider);
@@ -85,21 +85,23 @@
service);
}
+ @Test
public void testInvalidateUrl() throws Exception {
cache.addResponse(new HttpRequest(URI), CACHEABLE);
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
service.invalidateApplicationResources(
ImmutableSet.of(URI),
appxToken);
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 0);
+ assertEquals(0, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
}
+ @Test
public void testInvalidateUsers() throws Exception {
service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"),
appxToken);
service.invalidateUserResources(ImmutableSet.of("example.org:1", "example.org:2"),
appyToken);
- assertEquals(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME).getSize(), 4);
+ assertEquals(4, cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME).getSize());
assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME)
.getElement("INV_TOK:AppX:1"));
assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME)
@@ -108,14 +110,15 @@
.getElement("INV_TOK:AppY:1"));
assertNotNull(cacheProvider.createCache(DefaultInvalidationService.CACHE_NAME)
.getElement("INV_TOK:AppY:2"));
-
}
+ @Test
public void testFetchWithInvalidationEnabled() throws Exception {
cache.addResponse(new HttpRequest(URI), CACHEABLE);
- assertEquals(requestPipeline.execute(new HttpRequest(URI)), CACHEABLE);
+ assertEquals(CACHEABLE, requestPipeline.execute(new HttpRequest(URI)));
}
+ @Test
public void testFetchInvalidatedContent() throws Exception {
// Prime the cache
cache.addResponse(new HttpRequest(URI), CACHEABLE);
@@ -130,13 +133,14 @@
assertEquals(requestPipeline.execute(new HttpRequest(URI)), fetcher.response);
}
+ @Test
public void testFetchContentWithMarker() throws Exception {
oauth.httpResponse = CACHEABLE;
// First entry added to cache is unmarked
HttpResponse httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse, CACHEABLE);
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals(CACHEABLE, httpResponse);
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
// Invalidate content for OwnerX. Next entry will have owner mark
service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken);
@@ -144,27 +148,28 @@
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse.getResponseAsString(), "NEWCONTENT1");
- assertEquals(httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER), "o=1;");
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals("NEWCONTENT1", httpResponse.getResponseAsString());
+ assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER));
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
// Invalidate content for ViewerX. Next entry will have both owner and viewer mark
service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken);
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse.getResponseAsString(), "NEWCONTENT2");
- assertEquals(httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER),
- "o=1;v=2;");
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals("NEWCONTENT2", httpResponse.getResponseAsString());
+ assertEquals("o=1;v=2;",
+ httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER));
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
}
+ @Test
public void testFetchContentSignedOwner() throws Exception {
oauth.httpResponse = CACHEABLE;
signedRequest.getOAuthArguments().setSignViewer(false);
HttpResponse httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse, CACHEABLE);
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals(CACHEABLE, httpResponse);
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
// Invalidate by owner only
service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken);
@@ -172,44 +177,46 @@
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse.getResponseAsString(), "NEWCONTENT1");
- assertEquals(httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER), "o=1;");
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals("NEWCONTENT1", httpResponse.getResponseAsString());
+ assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER));
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
// Invalidating viewer has no effect
service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken);
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse.getResponseAsString(), "NEWCONTENT1");
- assertEquals(httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER), "o=1;");
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals("NEWCONTENT1", httpResponse.getResponseAsString());
+ assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER));
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
}
+ @Test
public void testFetchContentSignedViewer() throws Exception {
oauth.httpResponse = CACHEABLE;
signedRequest.getOAuthArguments().setSignOwner(false);
HttpResponse httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse, CACHEABLE);
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals(CACHEABLE, httpResponse);
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
// Invalidate by owner has no effect
service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken);
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse, CACHEABLE);
+ assertEquals(CACHEABLE, httpResponse);
// Invalidate the viewer
service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken);
oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").
create();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse.getResponseAsString(), "NEWCONTENT2");
- assertEquals(httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER), "v=2;");
- assertEquals(cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize(), 1);
+ assertEquals("NEWCONTENT2", httpResponse.getResponseAsString());
+ assertEquals("v=2;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER));
+ assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize());
}
+ @Test
public void testServeInvalidatedContentWithFetcherError() throws Exception {
oauth.httpResponse = CACHEABLE;
HttpResponse httpResponse = requestPipeline.execute(signedRequest);
@@ -220,6 +227,6 @@
// Next request returns error
oauth.httpResponse = HttpResponse.error();
httpResponse = requestPipeline.execute(signedRequest);
- assertEquals(httpResponse, CACHEABLE);
+ assertEquals(CACHEABLE, httpResponse);
}
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java Wed Dec 16 22:07:43 2009
@@ -19,11 +19,8 @@
import org.apache.shindig.common.util.DateUtil;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.Assert.assertNull;
-import static junit.framework.Assert.assertNotNull;
-
import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
import org.junit.Test;
import java.io.ByteArrayInputStream;
@@ -31,12 +28,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
-import java.util.Date;
-
-import static junitx.framework.Assert.assertEquals;
-import static junitx.framework.Assert.assertFalse;
-public class HttpResponseTest {
+public class HttpResponseTest extends Assert {
private static final byte[] UTF8_DATA = {
(byte)0xEF, (byte)0xBB, (byte)0xBF, 'h', 'e', 'l', 'l', 'o'
};
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/InvalidationHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/InvalidationHandlerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/InvalidationHandlerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/InvalidationHandlerTest.java Wed Dec 16 22:07:43 2009
@@ -35,6 +35,8 @@
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expectLastCall;
+
+import org.junit.Before;
import org.junit.Test;
import java.util.Map;
@@ -58,9 +60,8 @@
protected HandlerRegistry registry;
protected ContainerConfig containerConfig;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
token = new FakeGadgetToken();
token.setAppId("appId");
token.setViewerId("userX");
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java Wed Dec 16 22:07:43 2009
@@ -1053,7 +1053,7 @@
assertEquals("some vague error", response.getResponseAsString());
Map<String, String> metadata = response.getMetadata();
assertNotNull(metadata);
- assertEquals(null, metadata.get("oauthError"));
+ assertNull(metadata.get("oauthError"));
checkStringContains("oauthErrorText missing request entry", metadata.get("oauthErrorText"),
"GET /data?cachebust=2\n");
checkStringContains("oauthErrorText missing request entry", metadata.get("oauthErrorText"),
@@ -1979,7 +1979,7 @@
return;
}
}
- fail("List did not contain " + key + "=" + value + "; instead was " + params);
+ fail("List did not contain " + key + '=' + value + "; instead was " + params);
}
private String getLogText() {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/AbstractParserAndSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/AbstractParserAndSerializerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/AbstractParserAndSerializerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/AbstractParserAndSerializerTest.java Wed Dec 16 22:07:43 2009
@@ -22,7 +22,7 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
-import junit.framework.TestCase;
+import org.junit.Assert;
import org.w3c.dom.Document;
import java.io.IOException;
@@ -30,7 +30,7 @@
/**
* Base test fixture for HTML parsing and serialization.
*/
-public abstract class AbstractParserAndSerializerTest extends TestCase {
+public abstract class AbstractParserAndSerializerTest extends Assert {
/** The vm line separator */
private static final String EOL = System.getProperty("line.separator");
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/CompactHtmlSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/CompactHtmlSerializerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/CompactHtmlSerializerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/CompactHtmlSerializerTest.java Wed Dec 16 22:07:43 2009
@@ -21,6 +21,8 @@
import org.apache.shindig.gadgets.parse.nekohtml.NekoSimplifiedHtmlParser;
import com.google.inject.Provider;
+import org.junit.Before;
+import org.junit.Test;
import java.io.IOException;
import java.io.StringWriter;
@@ -33,7 +35,7 @@
private GadgetHtmlParser full = new NekoSimplifiedHtmlParser(
new ParseModule.DOMImplementationProvider().get());
- @Override
+ @Before
public void setUp() throws Exception {
full.setSerializerProvider(new Provider<HtmlSerializer>() {
public HtmlSerializer get() {
@@ -42,6 +44,7 @@
});
}
+ @Test
public void testWhitespaceNotCollapsedInSpecialTags() throws Exception {
String content = loadFile(
"org/apache/shindig/gadgets/parse/nekohtml/test-with-specialtags.html");
@@ -49,7 +52,8 @@
"org/apache/shindig/gadgets/parse/nekohtml/test-with-specialtags-expected.html");
parseAndCompareBalanced(content, expected, full);
}
-
+
+ @Test
public void testIeConditionalCommentNotRemoved() throws Exception {
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-with-iecond-comments.html");
String expected = loadFile(
@@ -57,6 +61,7 @@
parseAndCompareBalanced(content, expected, full);
}
+ @Test
public void testSpecialTagsAreRecognized() {
assertSpecialTag("textArea");
assertSpecialTag("scrIpt");
@@ -73,6 +78,7 @@
CompactHtmlSerializer.isSpecialTag(tagName.toLowerCase()));
}
+ @Test
public void testCollapseHtmlWhitespace() throws IOException {
assertCollapsed("abc", "abc");
assertCollapsed("abc ", "abc");
@@ -90,4 +96,4 @@
CompactHtmlSerializer.collapseWhitespace(input, output);
assertEquals(expected, output.toString());
}
-}
+}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/HtmlParserTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/HtmlParserTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/HtmlParserTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/HtmlParserTest.java Wed Dec 16 22:07:43 2009
@@ -20,18 +20,20 @@
import org.apache.shindig.gadgets.parse.nekohtml.NekoSimplifiedHtmlParser;
import org.apache.shindig.gadgets.rewrite.XPathWrapper;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.w3c.dom.Document;
/**
* Note these tests are of marginal use. Consider removing. More useful tests would exercise
* the capability of the parser to handle strange HTML.
*/
-public class HtmlParserTest extends TestCase {
+public class HtmlParserTest extends Assert {
private final GadgetHtmlParser nekoParser = new NekoSimplifiedHtmlParser(
new ParseModule.DOMImplementationProvider().get());
+ @Test
public void testParseSimpleString() throws Exception {
parseSimpleString(nekoParser);
}
@@ -42,6 +44,7 @@
assertEquals("content", wrapper.getValue("/html/body"));
}
+ @Test
public void testParseTagWithStringContents() throws Exception {
parseTagWithStringContents(nekoParser);
}
@@ -52,6 +55,7 @@
assertEquals("content", wrapper.getValue("/html/body/span"));
}
+ @Test
public void testParseTagWithAttributes() throws Exception {
parseTagWithAttributes(nekoParser);
}
@@ -63,6 +67,7 @@
assertEquals("foo", wrapper.getValue("/html/body/div/@id"));
}
+ @Test
public void testParseNestedContentWithNoCloseForBrAndHr() throws Exception {
parseNestedContentWithNoCloseForBrAndHr(nekoParser);
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssLexerParserTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssLexerParserTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssLexerParserTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssLexerParserTest.java Wed Dec 16 22:07:43 2009
@@ -19,14 +19,16 @@
import org.apache.shindig.common.cache.LruCacheProvider;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.List;
/**
* Basic test of CSS lexer
*/
-public class CajaCssLexerParserTest extends TestCase {
+public class CajaCssLexerParserTest extends Assert {
private CajaCssLexerParser cajaCssParser;
@@ -34,18 +36,19 @@
".xyz { background-image : url(http://www.example.org/someimage.gif); }\n" +
"A { color : #7f7f7f }\n";
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
cajaCssParser = new CajaCssLexerParser();
}
+ @Test
public void testBasicCssParse() throws Exception {
String css = ".xyz { font : bold; } A { color : #7f7f7f }";
List<Object> styleSheet = cajaCssParser.parse(css);
assertEquals(cajaCssParser.serialize(styleSheet), css);
}
+ @Test
public void testClone() throws Exception {
// Set the cache so we force cloning
cajaCssParser.setCacheProvider(new LruCacheProvider(100));
@@ -56,6 +59,7 @@
assertEquals(cajaCssParser.serialize(styleSheet), cajaCssParser.serialize(styleSheet2));
}
+ @Test
public void testCache() throws Exception {
cajaCssParser.setCacheProvider(new LruCacheProvider(100));
// Ensure that we return cloned instances and not the original out of the cache. Cloned
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssParserTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssParserTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssParserTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssParserTest.java Wed Dec 16 22:07:43 2009
@@ -19,26 +19,27 @@
import com.google.caja.parser.css.CssTree;
-import junit.framework.TestCase;
-
import org.apache.shindig.common.cache.LruCacheProvider;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.List;
/**
* Basic CSS parse tests
*/
-public class CajaCssParserTest extends TestCase {
+public class CajaCssParserTest extends Assert {
private CajaCssParser cajaCssParser;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
cajaCssParser = new CajaCssParser();
cajaCssParser.setCacheProvider(new LruCacheProvider(10));
}
+ @Test
public void testBasicCssParse() throws Exception {
String css = ".xyz { font : bold; } A { color : #7f7f7f }";
CssTree.StyleSheet styleSheet = cajaCssParser.parseDom(css);
@@ -52,12 +53,13 @@
* These tests test Caja's parsing of "funky" CSS which are not legal
* but accepted by commonly used browsers
*/
+ @Test
public void testCajaParseColonInRValue() throws Exception {
String original = " A {\n"
+ " -moz-opacity: 0.80;\n"
+ " filter: alpha(opacity=40);\n"
+ " filter: progid:DXImageTransform.Microsoft.Alpha(opacity=80);\n"
- + "}";
+ + '}';
CssTree.StyleSheet styleSheet = cajaCssParser.parseDom(original);
List<CssTree.SimpleSelector> selectorList = CajaCssUtils.descendants(
styleSheet, CssTree.SimpleSelector.class);
@@ -65,10 +67,11 @@
assertSame(CssTree.SimpleSelector.class, selectorList.get(0).getClass());
}
+ @Test
public void testCajaParseNoLValue() throws Exception {
String original = "body, input, td {\n"
+ " Arial, sans-serif;\n"
- + "}";
+ + '}';
cajaCssParser.parseDom(original);
CssTree.StyleSheet styleSheet = cajaCssParser.parseDom(original);
List<CssTree.SimpleSelector> selectorList = CajaCssUtils.descendants(
@@ -77,6 +80,7 @@
assertSame(CssTree.SimpleSelector.class, selectorList.get(0).getClass());
}
+ @Test
public void testCajaParseNoScheme() throws Exception {
String original = "span { background-image:url('//www.example.org/image.gif'); }";
cajaCssParser.parseDom(original);
@@ -91,6 +95,7 @@
assertSame(CssTree.SimpleSelector.class, selectorList.get(0).getClass());
}
+ @Test
public void testCajaParseCommentInContent() throws Exception {
String original = "body { font : bold; } \n//A comment\n A { font : bold; }";
cajaCssParser.parseDom(original);
@@ -101,6 +106,7 @@
assertSame(CssTree.SimpleSelector.class, selectorList.get(0).getClass());
}
+ @Test
public void testCajaParseDotInIdent() throws Exception {
String original = "li{list-style:none;.padding-bottom:4px;}";
cajaCssParser.parseDom(original);
@@ -111,6 +117,7 @@
assertSame(CssTree.SimpleSelector.class, selectorList.get(0).getClass());
}
+ @Test
public void testCajaParseDotInFunction() throws Exception {
String original = ".iepngfix {behavior: expression(IEPNGFIX.fix(this)); }";
cajaCssParser.parseDom(original);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssSanitizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssSanitizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssSanitizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssSanitizerTest.java Wed Dec 16 22:07:43 2009
@@ -23,6 +23,8 @@
import org.apache.shindig.gadgets.servlet.ProxyBase;
import com.google.caja.parser.css.CssTree;
+import org.junit.Before;
+import org.junit.Test;
/**
*
@@ -35,23 +37,23 @@
private LinkRewriter importRewriter;
private LinkRewriter imageRewriter;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
parser = new CajaCssParser();
sanitizer = new CajaCssSanitizer(parser);
importRewriter = new LinkRewriter() {
public String rewrite(String link, Uri context) {
- return link + "&" + ProxyBase.SANITIZE_CONTENT_PARAM + "=1&rewriteMime=text/css";
+ return link + '&' + ProxyBase.SANITIZE_CONTENT_PARAM + "=1&rewriteMime=text/css";
}
};
imageRewriter = new LinkRewriter() {
public String rewrite(String link, Uri context) {
- return link + "&" + ProxyBase.SANITIZE_CONTENT_PARAM + "=1&rewriteMime=image/*";
+ return link + '&' + ProxyBase.SANITIZE_CONTENT_PARAM + "=1&rewriteMime=image/*";
}
};
}
+ @Test
public void testPreserveSafe() throws Exception {
String css = ".xyz { font: bold;} A { color: #7f7f7f}";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
@@ -59,6 +61,7 @@
assertStyleEquals(css, styleSheet);
}
+ @Test
public void testSanitizeFunctionCall() throws Exception {
String css = ".xyz { font : iamevil(bold); }";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
@@ -66,6 +69,7 @@
assertStyleEquals(".xyz {}", styleSheet);
}
+ @Test
public void testSanitizeUnsafeProperties() throws Exception {
String css = ".xyz { behavior: url('xyz.htc'); -moz-binding:url(\"http://ha.ckers.org/xssmoz.xml#xss\") }";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
@@ -73,6 +77,7 @@
assertStyleEquals(".xyz {}", styleSheet);
}
+ @Test
public void testSanitizeScriptUrls() throws Exception {
String css = ".xyz { background: url('javascript:doevill'); background : url(vbscript:moreevil); }";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
@@ -80,6 +85,7 @@
assertStyleEquals(".xyz {}", styleSheet);
}
+ @Test
public void testProxyUrls() throws Exception {
String css = ".xyz { background: url('http://www.example.org/img.gif');}";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
@@ -88,12 +94,13 @@
".xyz { background: url('http://www.example.org/img.gif&sanitize=1&rewriteMime=image/*');}", styleSheet);
}
+ @Test
public void testUrlEscaping() throws Exception {
String css = ".xyz { background: url('http://www.example.org/img.gif');}";
CssTree.StyleSheet styleSheet = parser.parseDom(css);
sanitizer.sanitize(styleSheet, DUMMY, importRewriter, imageRewriter);
- assertEquals(parser.serialize(styleSheet).replaceAll("\\s", ""),
- ".xyz{background:url('http://www.example.org/img.gif%26sanitize%3D1%26rewriteMime%3Dimage/%2A');}");
+ assertEquals(".xyz{background:url('http://www.example.org/img.gif%26sanitize%3D1%26rewriteMime%3Dimage/%2A');}",
+ parser.serialize(styleSheet).replaceAll("\\s", ""));
}
public void assertStyleEquals(String expected, CssTree.StyleSheet styleSheet) throws Exception {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/NekoParserAndSerializeTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/NekoParserAndSerializeTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/NekoParserAndSerializeTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/NekoParserAndSerializeTest.java Wed Dec 16 22:07:43 2009
@@ -19,6 +19,7 @@
import org.apache.shindig.gadgets.parse.AbstractParserAndSerializerTest;
import org.apache.shindig.gadgets.parse.ParseModule;
+import org.junit.Test;
/**
* Test behavior of neko based parser and serializers
@@ -28,6 +29,7 @@
private NekoSimplifiedHtmlParser simple = new NekoSimplifiedHtmlParser(
new ParseModule.DOMImplementationProvider().get());
+ @Test
public void testDocWithDoctype() throws Exception {
// Note that doctype is properly retained
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test.html");
@@ -35,12 +37,14 @@
parseAndCompareBalanced(content, expected, simple);
}
+ @Test
public void testDocNoDoctype() throws Exception {
// Note that no doctype is properly created when none specified
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-fulldocnodoctype.html");
assertNull(simple.parseDom(content).getDoctype());
}
+ @Test
public void testNotADocument() throws Exception {
// Note that no doctype is injected for fragments
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-fragment.html");
@@ -48,6 +52,7 @@
parseAndCompareBalanced(content, expected, simple);
}
+ @Test
public void testNotADocument2() throws Exception {
// Note that no doctype is injected for fragments
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-fragment2.html");
@@ -55,6 +60,7 @@
parseAndCompareBalanced(content, expected, simple);
}
+ @Test
public void testNoBody() throws Exception {
// Note that no doctype is injected for fragments
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-headnobody.html");
@@ -62,17 +68,18 @@
parseAndCompareBalanced(content, expected, simple);
}
+ @Test
public void testAmpersand() throws Exception {
// Note that no doctype is injected for fragments
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-with-ampersands.html");
String expected = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-with-ampersands-expected.html");
parseAndCompareBalanced(content, expected, simple);
}
-
+
+ @Test
public void testScriptPushedToBody() throws Exception {
String content = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-leadingscript.html");
String expected = loadFile("org/apache/shindig/gadgets/parse/nekohtml/test-leadingscript-expected.html");
parseAndCompareBalanced(content, expected, simple);
}
-
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/SocialMarkupHtmlParserTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/SocialMarkupHtmlParserTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/SocialMarkupHtmlParserTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/SocialMarkupHtmlParserTest.java Wed Dec 16 22:07:43 2009
@@ -28,6 +28,8 @@
import com.google.common.collect.Lists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.DOMException;
@@ -130,7 +132,7 @@
String content = "<html><div id=\"div_super\" class=\"div_super\" valign:\"middle\"></div></html>";
try {
parser.parseDom(content);
- assertTrue("No exception caught", false);
+ fail("No exception caught");
} catch (DOMException e) {
assertTrue(e.getMessage().contains("INVALID_CHARACTER_ERR"));
assertTrue(e.getMessage().contains(
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultRpcServiceLookupTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultRpcServiceLookupTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultRpcServiceLookupTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultRpcServiceLookupTest.java Wed Dec 16 22:07:43 2009
@@ -20,8 +20,6 @@
import java.util.Set;
-import junit.framework.TestCase;
-
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
@@ -29,26 +27,31 @@
import org.apache.shindig.gadgets.http.BasicHttpFetcher;
-public class DefaultRpcServiceLookupTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DefaultRpcServiceLookupTest extends Assert {
private DefaultRpcServiceLookup svcLookup;
private String socialEndpoint;
private String host;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
svcLookup = new DefaultRpcServiceLookup(new DefaultServiceFetcher(null, new BasicHttpFetcher()), 60l);
socialEndpoint = "http://localhost:8080/social/rpc";
host = "localhost:8080";
}
+ @Test
public void testGetServicesForContainer_Empty() throws Exception {
String container = "ig";
Multimap<String, String> services = svcLookup.getServicesFor(container, host);
assertEquals(0, services.size());
}
-
+
+ @Test
public void testGetServicesForContainer_Null() throws Exception {
String container = null;
try {
@@ -59,6 +62,7 @@
}
}
+ @Test
public void testGetServicesForContainer_OneContainerOneService() throws Exception {
ImmutableSet<String> expectedServiceMethods = ImmutableSet.of("system.listMethods");
LinkedHashMultimap<String, String> expectedServices = LinkedHashMultimap.create();
@@ -73,6 +77,7 @@
assertEquals(expectedServiceMethods, actualServiceMethods);
}
+ @Test
public void testGetServicesForContainer_OneContainerTwoServices() throws Exception {
Set<String> expectedServiceMethods = Sets.newHashSet("system.listMethods", "people.get",
"people.update", "people.create", "people.delete");
@@ -86,6 +91,7 @@
assertServiceHasCorrectConfig(socialEndpoint, expectedServiceMethods, container, 1);
}
+ @Test
public void testGetServiceForContainer_TwoContainersOneEndpoint() throws Exception {
String socialEndpoint2 = "http://localhost:8080/api/rpc";
Set<String> expectedServiceMethods = Sets.newHashSet("system.listMethods", "people.get",
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java Wed Dec 16 22:07:43 2009
@@ -32,6 +32,8 @@
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
+import org.junit.Before;
+import org.junit.Test;
import java.util.List;
@@ -46,9 +48,8 @@
protected static final String endPoint2 = "http://%host%/social/api/rpc";
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
JSONObject config = createConfig();
JsonContainerConfig containerConfig =
@@ -83,6 +84,7 @@
return config;
}
+ @Test
public void testReadConfigNoEndpoints() throws Exception {
JSONObject config = createConfig();
config.getJSONObject("default").
@@ -101,6 +103,7 @@
assertEquals(configuredServices, services);
}
+ @Test
public void testReadConfigEndpointsDown() throws Exception {
EasyMock.expect(mockFetcher.fetch(EasyMock.isA(HttpRequest.class))).andReturn(
new HttpResponse("")).anyTimes();
@@ -110,6 +113,7 @@
assertEquals(configuredServices, services);
}
+ @Test
public void testReadConfigWithValidEndpoints() throws Exception {
List<String> endPoint1Services = ImmutableList.of("do.something", "delete.someting");
JSONObject service1 = new JSONObject();
@@ -133,6 +137,7 @@
assertEquals(mergedServices, LinkedHashMultimap.create(services));
}
+ @Test
public void testReadConfigBadContainer() throws Exception {
Multimap<String, String> multimap = fetcher.getServicesForContainer("badcontainer", "dontcare");
assertEquals(0, multimap.size());
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ContentRewriterFeatureTestCaseOS9.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ContentRewriterFeatureTestCaseOS9.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ContentRewriterFeatureTestCaseOS9.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ContentRewriterFeatureTestCaseOS9.java Wed Dec 16 22:07:43 2009
@@ -241,8 +241,8 @@
@Test
public void testSpecExcludeDisallowOverrideTagsSubset() throws Exception {
defaultRewriterFeature = new ContentRewriterFeature(createSpecWithRewrite(
- "test\\.com", "testx", "0", Sets.newHashSet(new String[] { "img" })),
- "", "", "0", Sets.newHashSet(new String[] { "img", "script" }), true);
+ "test\\.com", "testx", "0", Sets.newHashSet("img")),
+ "", "", "0", Sets.newHashSet("img", "script"), true);
assertFalse(defaultRewriterFeature.shouldRewriteTag("IFRAME"));
assertTrue(defaultRewriterFeature.shouldRewriteTag("img"));
assertFalse(defaultRewriterFeature.shouldRewriteTag("ScripT"));
@@ -251,8 +251,8 @@
@Test
public void testSpecExcludeDisallowOverrideTagsSuperset() throws Exception {
defaultRewriterFeature = new ContentRewriterFeature(createSpecWithRewrite(
- "test\\.com", "testx", "0", Sets.newHashSet(new String[] { "img", "script", "link" })),
- "", "", "0", Sets.newHashSet(new String[] { "img", "script" }), true);
+ "test\\.com", "testx", "0", Sets.newHashSet("img", "script", "link")),
+ "", "", "0", Sets.newHashSet("img", "script"), true);
assertFalse(defaultRewriterFeature.shouldRewriteTag("IFRAME"));
assertTrue(defaultRewriterFeature.shouldRewriteTag("img"));
assertTrue(defaultRewriterFeature.shouldRewriteTag("ScripT"));
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/HTMLContentRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/HTMLContentRewriterTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/HTMLContentRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/HTMLContentRewriterTest.java Wed Dec 16 22:07:43 2009
@@ -82,8 +82,8 @@
assertEquals(12, wrapper.getNodeList("/html/body/script").getLength());
int scriptIx = 1;
- assertEquals("headScript1", wrapper.getValue("/html/body/script[" + (scriptIx++) + "]"));
- assertEquals("bodyScript1", wrapper.getValue("/html/body/script[" + (scriptIx++) + "]"));
+ assertEquals("headScript1", wrapper.getValue("/html/body/script[" + (scriptIx++) + ']'));
+ assertEquals("bodyScript1", wrapper.getValue("/html/body/script[" + (scriptIx++) + ']'));
// Second script should contain two concatenated urls
assertEquals(wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"),
@@ -93,7 +93,7 @@
"&1=http%3A%2F%2Fwww.example.org%2F1.js" +
"&2=http%3A%2F%2Fwww.example.org%2F2.js");
- assertEquals("bodyScript2", wrapper.getValue("/html/body/script[" + (scriptIx++) + "]"));
+ assertEquals("bodyScript2", wrapper.getValue("/html/body/script[" + (scriptIx++) + ']'));
// Fourth script should contain one concatenated url
assertEquals(wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"),
@@ -105,7 +105,7 @@
// Fifth script should contain a retained comment
assertEquals("<!-- retain-comment -->",
- wrapper.getValue("/html/body/script[" + (scriptIx++) + "]"));
+ wrapper.getValue("/html/body/script[" + (scriptIx++) + ']'));
// An excluded URL between contiguous tags prevents them being concatentated
assertEquals(wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"),
@@ -145,8 +145,8 @@
"&4=http%3A%2F%2Fwww.example.org%2F23.js%260123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
// Handle long requests
- assertEquals(wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"),
- "http://www.example.org/23-long.js&0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
+ assertEquals("http://www.example.org/23-long.js&0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456
789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789",
+ wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"));
// Resume concating
assertEquals(wrapper.getValue("/html/body/script[" + (scriptIx++) + "]/@src"),
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BMPOptimizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BMPOptimizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BMPOptimizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BMPOptimizerTest.java Wed Dec 16 22:07:43 2009
@@ -21,6 +21,7 @@
import org.apache.sanselan.Sanselan;
import org.apache.shindig.gadgets.http.HttpResponse;
import org.junit.Ignore;
+import org.junit.Test;
import java.io.IOException;
import java.util.logging.Level;
@@ -33,14 +34,16 @@
Logger log = Logger.getLogger(BMPOptimizerTest.class.getName());
+ @Test
public void testSimpleImage() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/simple.bmp", "image/bmp");
HttpResponse rewritten = rewrite(resp);
assertTrue(rewritten.getContentLength() < resp.getContentLength());
- assertEquals(rewritten.getHeader("Content-Type"), "image/png");
+ assertEquals("image/png", rewritten.getHeader("Content-Type"));
}
+ @Test
@Ignore("Kills some VMs")
public void testEvilImages() throws Exception {
try {
@@ -53,6 +56,7 @@
}
}
+ @Test
public void testEvilImage2() throws Exception {
try {
HttpResponse resp =
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BaseOptimizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BaseOptimizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BaseOptimizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BaseOptimizerTest.java Wed Dec 16 22:07:43 2009
@@ -17,18 +17,17 @@
*/
package org.apache.shindig.gadgets.rewrite.image;
-import junit.framework.TestCase;
-
import org.apache.commons.io.IOUtils;
import org.apache.shindig.gadgets.http.HttpResponse;
import org.apache.shindig.gadgets.http.HttpResponseBuilder;
+import org.junit.Assert;
import java.io.IOException;
/**
* Test BasicOptimizer
*/
-public abstract class BaseOptimizerTest extends TestCase {
+public abstract class BaseOptimizerTest extends Assert {
protected HttpResponse createResponse(String resource, String mimeType) throws IOException {
byte[] bytes = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream(resource));
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/GIFOptimizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/GIFOptimizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/GIFOptimizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/GIFOptimizerTest.java Wed Dec 16 22:07:43 2009
@@ -20,6 +20,7 @@
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.Sanselan;
import org.apache.shindig.gadgets.http.HttpResponse;
+import org.junit.Test;
import java.io.IOException;
@@ -28,6 +29,7 @@
*/
public class GIFOptimizerTest extends BaseOptimizerTest {
+ @Test
public void testEfficientGIF() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/unanimated.gif", "image/gif");
@@ -40,12 +42,13 @@
* that has not pixels that map to them so it is Opaque.
* @throws Exception
*/
+ @Test
public void testBadPaletteGIFToPNG() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/large.gif", "image/gif");
HttpResponse httpResponse = rewrite(resp);
assertTrue(httpResponse.getContentLength() <= resp.getContentLength());
- assertEquals(httpResponse.getHeader("Content-Type"), "image/png");
+ assertEquals("image/png", httpResponse.getHeader("Content-Type"));
}
/**
@@ -53,12 +56,13 @@
* tranparency
* @throws Exception
*/
+ @Test
public void testDirectColorModelGif() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/directcolor.gif", "image/gif");
HttpResponse httpResponse = rewrite(resp);
assertTrue(httpResponse.getContentLength() <= resp.getContentLength());
- assertEquals(httpResponse.getHeader("Content-Type"), "image/gif");
+ assertEquals("image/gif", httpResponse.getHeader("Content-Type"));
}
protected HttpResponse rewrite(HttpResponse original)
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/ImageRewriterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/ImageRewriterTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/ImageRewriterTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/ImageRewriterTest.java Wed Dec 16 22:07:43 2009
@@ -28,8 +28,6 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createControl;
-import junit.framework.TestCase;
-
import org.apache.commons.io.IOUtils;
import org.apache.shindig.common.uri.Uri;
import org.apache.shindig.gadgets.http.HttpRequest;
@@ -37,6 +35,10 @@
import org.apache.shindig.gadgets.http.HttpResponseBuilder;
import org.easymock.IMocksControl;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Arrays;
@@ -46,7 +48,7 @@
/**
* Tests for the {@link ImageRewriter} class.
*/
-public class ImageRewriterTest extends TestCase {
+public class ImageRewriterTest extends Assert {
/** The image used for the scaling tests, a head-shot of a white dog, 500pix x 500pix */
private static final String SCALE_IMAGE = "org/apache/shindig/gadgets/rewrite/image/dog.gif";
@@ -72,7 +74,7 @@
private IMocksControl mockControl;
- @Override
+ @Before
public void setUp() throws Exception {
rewriter = new BasicImageRewriter(new OptimizerConfig());
mockControl = createControl();
@@ -80,12 +82,11 @@
/** Makes a new {@link HttpResponse} with an image content. */
private HttpResponse getImageResponse(String contentType, byte[] imageBytes) {
- HttpResponse originalResponse = new HttpResponseBuilder()
+ return new HttpResponseBuilder()
.setHeader(CONTENT_TYPE_HEADER, contentType)
.setHttpStatusCode(HttpResponse.SC_OK)
.setResponse(imageBytes)
.create();
- return originalResponse;
}
/** Extracts an image by its resource name and converts it into a byte array. */
@@ -128,15 +129,17 @@
return request;
}
+ @Test
public void testRewriteValidImageWithValidMimeAndExtn() throws Exception {
byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png");
HttpResponse original = getImageResponse(CONTENT_TYPE_PNG, bytes);
HttpResponse rewritten = rewriter.rewrite(new HttpRequest(Uri.parse("some.png")), original);
- assertEquals(rewritten.getHttpStatusCode(), HttpResponse.SC_OK);
+ assertEquals(HttpResponse.SC_OK, rewritten.getHttpStatusCode());
assertTrue(rewritten.getContentLength() < original.getContentLength());
}
+ @Test
public void testRewriteValidImageWithInvalidMimeAndFileExtn() throws Exception {
byte[] bytes = getImageBytes("org/apache/shindig/gadgets/rewrite/image/inefficient.png");
HttpResponse original = getImageResponse(CONTENT_TYPE_BOGUS, bytes);
@@ -146,6 +149,7 @@
assertEquals(rewritten.getContentLength(), original.getContentLength());
}
+ @Test
public void testRewriteInvalidImageContentWithValidMime() throws Exception {
HttpResponse original = getImageResponse(CONTENT_TYPE_PNG, "This is not a PNG".getBytes());
HttpResponse rewritten = rewriter.rewrite(new HttpRequest(Uri.parse("some.junk")), original);
@@ -154,6 +158,7 @@
assertEquals(CONTENT_TYPE_AND_MIME_MISMATCH, rewritten.getResponseAsString());
}
+ @Test
public void testRewriteInvalidImageContentWithValidFileExtn() throws Exception {
HttpResponse original = getImageResponse(CONTENT_TYPE_BOGUS, "This is not an image".getBytes());
HttpResponse rewritten = rewriter.rewrite(new HttpRequest(Uri.parse("some.png")), original);
@@ -163,12 +168,14 @@
rewritten.getResponseAsString());
}
+ @Test
public void testNoRewriteAnimatedGIF() throws Exception {
HttpResponse original = getImageResponse(CONTENT_TYPE_GIF,
getImageBytes("org/apache/shindig/gadgets/rewrite/image/animated.gif"));
assertSame(rewriter.rewrite(new HttpRequest(Uri.parse("animated.gif")), original), original);
}
+ @Test
public void testRewriteUnAnimatedGIF() throws Exception {
HttpResponse original = getImageResponse(CONTENT_TYPE_GIF,
getImageBytes("org/apache/shindig/gadgets/rewrite/image/large.gif"));
@@ -182,6 +189,7 @@
// Checks at least the basic image parameters. It is rather nontrivial to check for the actual
// image content, as the ImageIO implementations vary across JVMs, so we have to skip it.
+ @Test
public void testResize_width() throws Exception {
BufferedImage image = getResizedHttpResponseContent(CONTENT_TYPE_GIF, CONTENT_TYPE_JPG,
SCALE_IMAGE, 100 /* width */, null /* height */, null /* quality */);
@@ -189,6 +197,7 @@
assertEquals(100, image.getHeight());
}
+ @Test
public void testResize_height() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, SCALE_IMAGE, null, 100, null);
@@ -196,6 +205,7 @@
assertEquals(100, image.getHeight());
}
+ @Test
public void testResize_both() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, SCALE_IMAGE, 100, 100, null);
@@ -203,6 +213,7 @@
assertEquals(100, image.getHeight());
}
+ @Test
public void testResize_all() throws Exception {
// The quality hint apparently has no effect on the result here
BufferedImage image = getResizedHttpResponseContent(
@@ -211,6 +222,7 @@
assertEquals(100, image.getHeight());
}
+ @Test
public void testResize_wideImage() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, SCALE_IMAGE, 100, 50, null);
@@ -218,6 +230,7 @@
assertEquals(50, image.getHeight());
}
+ @Test
public void testResize_tallImage() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, SCALE_IMAGE, 50, 100, null);
@@ -225,6 +238,7 @@
assertEquals(100, image.getHeight());
}
+ @Test
public void testResize_skipResizeHugeOutputImage() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, SCALE_IMAGE, 10000, 10000, null);
@@ -232,6 +246,7 @@
assertEquals(500, image.getHeight());
}
+ @Test
public void testResize_brokenParameter() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_GIF, SCALE_IMAGE, -1, null, null);
@@ -239,13 +254,15 @@
assertEquals(500, image.getHeight());
}
+ @Test
public void testResize_expandImage() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_JPG, EXPAND_IMAGE, 120, 60, null);
assertEquals(120, image.getWidth());
assertEquals(60, image.getHeight());
}
-
+
+ @Test
public void testResize_noExpandImage() throws Exception {
BufferedImage image = getResizedHttpResponseContent(
CONTENT_TYPE_GIF, CONTENT_TYPE_PNG /* still optimized */,
@@ -254,6 +271,7 @@
assertEquals(30, image.getHeight());
}
+ @Test
public void testResize_refuseHugeInputImages() throws Exception {
HttpResponse originalResponse = getImageResponse(CONTENT_TYPE_GIF, getImageBytes(HUGE_IMAGE));
HttpRequest request = getMockRequest(120, 60, null, false);
@@ -263,6 +281,7 @@
assertEquals(HttpResponse.SC_FORBIDDEN, rewrittenResponse.getHttpStatusCode());
}
+ @Test
public void testResize_acceptServeHugeImages() throws Exception {
byte[] imageBytes = getImageBytes(HUGE_IMAGE);
HttpResponse originalResponse = getImageResponse(CONTENT_TYPE_GIF, imageBytes);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/JPEGOptimizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/JPEGOptimizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/JPEGOptimizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/JPEGOptimizerTest.java Wed Dec 16 22:07:43 2009
@@ -19,6 +19,8 @@
import org.apache.sanselan.ImageReadException;
import org.apache.shindig.gadgets.http.HttpResponse;
+import org.junit.Ignore;
+import org.junit.Test;
import java.io.IOException;
@@ -26,24 +28,26 @@
* Test JPEG rewiting.
*/
public class JPEGOptimizerTest extends BaseOptimizerTest {
-
+ @Test
public void testSmallJPEGToPNG() throws Exception {
// Should be significantly smaller
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/small.jpg", "image/jpeg");
HttpResponse rewritten = rewrite(resp);
- assertEquals(rewritten.getHeader("Content-Type"), "image/png");
+ assertEquals("image/png", rewritten.getHeader("Content-Type"));
assertTrue(rewritten.getContentLength() * 100 / resp.getContentLength() < 70);
}
+ @Test
public void testLargeJPEG() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/large.jpg", "image/jpeg");
HttpResponse rewritten = rewrite(resp);
- assertEquals(resp.getHeader("Content-Type"), "image/jpeg");
+ assertEquals("image/jpeg", resp.getHeader("Content-Type"));
assertTrue(rewritten.getContentLength() <= resp.getContentLength());
}
+ @Test
public void testBadImage() throws Exception {
// Not a JPEG
try {
@@ -57,6 +61,8 @@
}
+ @Test
+ @Ignore
public void xtestBadICC1() throws Exception {
// ICC section too long
HttpResponse resp =
@@ -64,6 +70,7 @@
rewrite(resp);
}
+ @Test
public void testBadICC2() throws Exception {
// ICC section too long
try {
@@ -76,6 +83,7 @@
}
}
+ @Test
public void testBadICC3() throws Exception {
// ICC length lies
try {
@@ -88,6 +96,7 @@
}
}
+ @Test
public void testBadICC4() throws Exception {
// ICC count too large
HttpResponse resp =
@@ -102,6 +111,7 @@
}
}
+ @Test
public void testBadICC5() throws Exception {
// ICC length too large. Should be readable by most VMs
HttpResponse resp =
@@ -114,4 +124,4 @@
return new JPEGOptimizer(new OptimizerConfig(), original).rewrite(
JPEGOptimizer.readJpeg(original.getResponse()));
}
-}
+}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/PNGOptimizerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/PNGOptimizerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/PNGOptimizerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/PNGOptimizerTest.java Wed Dec 16 22:07:43 2009
@@ -20,6 +20,7 @@
import org.apache.sanselan.ImageReadException;
import org.apache.sanselan.Sanselan;
import org.apache.shindig.gadgets.http.HttpResponse;
+import org.junit.Test;
import java.io.IOException;
@@ -27,25 +28,27 @@
* Test PNG handling
*/
public class PNGOptimizerTest extends BaseOptimizerTest {
-
+ @Test
public void testRewriteInefficientPNG() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/inefficient.png", "image/png");
HttpResponse httpResponse = rewrite(resp);
assertTrue(httpResponse.getContentLength() <= resp.getContentLength());
- assertEquals(httpResponse.getHeader("Content-Type"), "image/png");
+ assertEquals("image/png", httpResponse.getHeader("Content-Type"));
}
// Strip the alpha component from an image that was stored in RGBA form but
// which is entirely opaque
+ @Test
public void testStripAlpha() throws Exception {
HttpResponse resp =
createResponse("org/apache/shindig/gadgets/rewrite/image/rgbawithnoalpha.png", "image/png");
HttpResponse httpResponse = rewrite(resp);
assertTrue(httpResponse.getContentLength() <= resp.getContentLength());
- assertEquals(httpResponse.getHeader("Content-Type"), "image/png");
+ assertEquals("image/png", httpResponse.getHeader("Content-Type"));
}
+ @Test
public void testEvil() throws Exception {
// Metadata length is too long causes OutOfMemory
try {
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java Wed Dec 16 22:07:43 2009
@@ -23,10 +23,12 @@
import org.apache.shindig.auth.AuthInfo;
import org.apache.shindig.auth.SecurityToken;
import org.apache.shindig.gadgets.GadgetContext;
+import org.junit.Test;
import java.util.Locale;
public class HttpGadgetContextTest extends ServletTestFixture {
+ @Test
public void testIgnoreCacheParam() {
expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE));
replay();
@@ -34,6 +36,7 @@
assertTrue(context.getIgnoreCache());
}
+ @Test
public void testLocale() {
expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage());
expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry());
@@ -42,6 +45,7 @@
assertEquals(Locale.CHINA, context.getLocale());
}
+ @Test
public void testDebug() {
expect(request.getParameter("debug")).andReturn("1");
replay();
@@ -49,6 +53,7 @@
assertTrue(context.getDebug());
}
+ @Test
public void testGetParameter() {
expect(request.getParameter("foo")).andReturn("bar");
replay();
@@ -56,6 +61,7 @@
assertEquals("bar", context.getParameter("foo"));
}
+ @Test
public void testGetHost() {
expect(request.getHeader("Host")).andReturn("foo.org");
replay();
@@ -63,6 +69,7 @@
assertEquals("foo.org", context.getHost());
}
+ @Test
public void testGetUserIp() {
expect(request.getRemoteAddr()).andReturn("2.3.4.5");
replay();
@@ -70,6 +77,7 @@
assertEquals("2.3.4.5", context.getUserIp());
}
+ @Test
public void testGetSecurityToken() throws Exception {
SecurityToken expected = new AnonymousSecurityToken();
expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId())).andReturn(expected);
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpRequestHandlerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpRequestHandlerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpRequestHandlerTest.java Wed Dec 16 22:07:43 2009
@@ -47,6 +47,7 @@
import org.easymock.IArgumentMatcher;
import org.json.JSONArray;
import org.json.JSONObject;
+import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
@@ -82,9 +83,8 @@
private Map<String,FormDataItem> emptyFormItems;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
token = new FakeGadgetToken();
token.setAppUrl("http://www.example.com/gadget.xml");
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java Wed Dec 16 22:07:43 2009
@@ -22,14 +22,14 @@
import org.apache.shindig.gadgets.GadgetContext;
-import junit.framework.TestCase;
-
import org.json.JSONObject;
+import org.junit.Assert;
+import org.junit.Test;
import java.util.Locale;
import java.util.Map;
-public class JsonRpcGadgetContextTest extends TestCase {
+public class JsonRpcGadgetContextTest extends Assert {
final static String SPEC_URL = "http://example.org/gadget.xml";
final static int SPEC_ID = 1234;
final static String[] PREF_KEYS = {"hello", "foo"};
@@ -41,6 +41,7 @@
}
}
+ @Test
public void testCorrectExtraction() throws Exception {
JSONObject gadget = new JSONObject()
.put("url", SPEC_URL)
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java Wed Dec 16 22:07:43 2009
@@ -38,6 +38,7 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import org.junit.Before;
import org.junit.Test;
import java.util.Collections;
@@ -90,13 +91,14 @@
return new JSONObject(body).getJSONObject(REQUEST_URL.toString());
}
- @Override
+ @Before
public void setUp() {
expect(request.getMethod()).andReturn("POST").anyTimes();
expect(request.getParameter(ProxyBase.URL_PARAM))
.andReturn(REQUEST_URL.toString()).anyTimes();
}
+ @Test
public void testGetRequest() throws Exception {
expectGetAndReturnBody(RESPONSE_BODY);
replay();
@@ -109,6 +111,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testGetRequestWithUncommonStatusCode() throws Exception {
HttpRequest req = new HttpRequest(REQUEST_URL);
HttpResponse response = new HttpResponseBuilder()
@@ -126,6 +129,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testGetRequestWithRefresh() throws Exception {
expect(request.getParameter(ProxyBase.REFRESH_PARAM)).andReturn("120").anyTimes();
@@ -141,6 +145,7 @@
assertEquals(120, httpRequest.getCacheTtl());
}
+ @Test
public void testExplicitHeaders() throws Exception {
String headerString = "X-Foo=bar&X-Bar=baz%20foo";
@@ -160,6 +165,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testPostRequest() throws Exception {
expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("POST");
expectPostAndReturnBody(REQUEST_BODY, RESPONSE_BODY);
@@ -206,6 +212,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testFetchFeedWithParameters() throws Exception {
String entryTitle = "Feed title";
String entryLink = "http://example.org/entry/0/1";
@@ -253,6 +260,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testFetchEmptyDocument() throws Exception {
expectGetAndReturnBody("");
replay();
@@ -275,6 +283,7 @@
});
}
+ @Test
public void testSignedGetRequest() throws Exception {
expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId()))
@@ -295,6 +304,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testSignedPostRequest() throws Exception {
// Doesn't actually sign since it returns the standard fetcher.
// Signing tests are in SigningFetcherTest
@@ -316,6 +326,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testChangeSecurityToken() throws Exception {
// Doesn't actually sign since it returns the standard fetcher.
// Signing tests are in SigningFetcherTest
@@ -336,6 +347,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testDoOAuthRequest() throws Exception {
// Doesn't actually do oauth dance since it returns the standard fetcher.
// OAuth tests are in OAuthRequestTest
@@ -358,6 +370,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testInvalidSigningTypeTreatedAsNone() throws Exception {
expectGetAndReturnBody(RESPONSE_BODY);
expect(request.getParameter(MakeRequestHandler.AUTHZ_PARAM)).andReturn("garbage");
@@ -371,6 +384,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testBadHttpResponseIsPropagated() throws Exception {
HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.error());
@@ -383,6 +397,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testBadSecurityTokenThrows() throws Exception {
expect(request.getAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId()))
.andReturn(null).atLeastOnce();
@@ -398,6 +413,7 @@
}
}
+ @Test
public void testMetadataCopied() throws Exception {
HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
HttpResponse response = new HttpResponseBuilder()
@@ -415,6 +431,7 @@
assertTrue(rewriter.responseWasRewritten());
}
+ @Test
public void testSetCookiesReturned() throws Exception {
HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
HttpResponse response = new HttpResponseBuilder()
@@ -437,6 +454,7 @@
assertEquals("name=value", cookies.get(1));
}
+ @Test
public void testLocationReturned() throws Exception {
HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
HttpResponse response = new HttpResponseBuilder()
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestServletTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestServletTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestServletTest.java Wed Dec 16 22:07:43 2009
@@ -29,6 +29,8 @@
import org.json.JSONException;
import org.json.JSONObject;
+import org.junit.Before;
+import org.junit.Test;
import java.util.Collections;
import java.util.Enumeration;
@@ -53,9 +55,8 @@
private final HttpRequest internalRequest = new HttpRequest(REQUEST_URL);
private final HttpResponse internalResponse = new HttpResponse(RESPONSE_BODY);
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
servlet.setMakeRequestHandler(handler);
expect(request.getHeaderNames()).andReturn(EMPTY_ENUM).anyTimes();
expect(request.getParameter(MakeRequestHandler.METHOD_PARAM))
@@ -96,6 +97,7 @@
assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY);
}
+ @Test
public void testDoGetHttpError() throws Exception {
setupGet();
expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound());
@@ -106,6 +108,7 @@
assertResponseOk(HttpResponse.SC_NOT_FOUND, "");
}
+ @Test
public void testDoGetException() throws Exception {
setupGet();
expect(pipeline.execute(internalRequest)).andThrow(
@@ -118,6 +121,7 @@
assertContains(ERROR_MESSAGE, recorder.getResponseAsString());
}
+ @Test
public void testDoPostNormal() throws Exception {
setupPost();
expect(pipeline.execute(internalRequest)).andReturn(internalResponse);
@@ -128,6 +132,7 @@
assertResponseOk(HttpResponse.SC_OK, RESPONSE_BODY);
}
+ @Test
public void testDoPostHttpError() throws Exception {
setupPost();
expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound());
@@ -138,6 +143,7 @@
assertResponseOk(HttpResponse.SC_NOT_FOUND, "");
}
+ @Test
public void testDoPostException() throws Exception {
setupPost();
expect(pipeline.execute(internalRequest)).andThrow(