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 [1/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...
Author: lindner
Date: Wed Dec 16 22:07:43 2009
New Revision: 891450
URL: http://svn.apache.org/viewvc?rev=891450&view=rev
Log:
SHINDIG-1247 | Upgrade tests to junit 4
Modified:
incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/Functions.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/AuthInfoTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/EasyMockTestCase.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/SoftExpiringCacheTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/BlobCrypterTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/CryptoTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/HttpServletUserAgentProviderTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/UserAgentTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/FutureUtilTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/ImmediateFutureTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/StringEncodingTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/FunctionsTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/ContentTypesTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java
incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/multipart/DefaultMultipartFormParserTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicGadgetBlacklistTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultUrlGeneratorTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/HashLockedDomainServiceTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/features/FeatureRegistryTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/CacheKeyBuilderTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/DefaultInvalidationServiceTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/HttpResponseTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/InvalidationHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/oauth/OAuthRequestTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/AbstractParserAndSerializerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/CompactHtmlSerializerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/HtmlParserTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssLexerParserTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssParserTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/caja/CajaCssSanitizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/NekoParserAndSerializeTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/parse/nekohtml/SocialMarkupHtmlParserTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultRpcServiceLookupTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/render/DefaultServiceFetcherTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/ContentRewriterFeatureTestCaseOS9.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/HTMLContentRewriterTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BMPOptimizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/BaseOptimizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/GIFOptimizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/ImageRewriterTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/JPEGOptimizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/rewrite/image/PNGOptimizerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpGadgetContextTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/HttpRequestHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/JsonRpcGadgetContextTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/MakeRequestServletTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyBaseTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletRequestTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/ProxyServletTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/servlet/RpcServletTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/FeatureTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/GadgetSpecTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/IconTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/ModulePrefsTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/spec/UserPrefTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/templates/tags/FlashTagHandlerTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/BidiSubstituterTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/SubstitutionsTest.java
incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/variables/UserPrefSubstituterTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/SpiTestUtil.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulJsonActivityTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulJsonDataTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulJsonPeopleTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulXmlActivityTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulXmlDataTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/spi/integration/JpaRestfulXmlPeopleTest.java
incubator/shindig/trunk/java/samples/src/test/java/org/apache/shindig/social/opensocial/jpa/test/PersonPopulate.java
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/config/SocialApiGuiceModuleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/AuthenticationProviderHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/core/oauth/OAuthAuthenticationHanderTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/AbstractLargeRestfulTests.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonActivityTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulJsonPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlActivityTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlDataTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/dataservice/integration/RestfulXmlPeopleTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/model/PersonTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ActivityHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/AppDataHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/MessageHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/PersonHandlerTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/ResponseItemTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/service/SocialRequestItemTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/GroupIdTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/spi/UserIdTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamAtomConverterTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/BeanXStreamConverterTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/opensocial/util/XSDValidatorTest.java
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/sample/spi/JsonDbOpensocialServiceTest.java
Modified: incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/Functions.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/Functions.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/Functions.java (original)
+++ incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/expressions/Functions.java Wed Dec 16 22:07:43 2009
@@ -103,7 +103,7 @@
Method priorMethod = prefixMap.put(methodName, m);
if (priorMethod != null) {
throw new IllegalStateException(
- "Method " + prefix + ":" + methodName + " re-defined.");
+ "Method " + prefix + ':' + methodName + " re-defined.");
}
}
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/AuthInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/AuthInfoTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/AuthInfoTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/auth/AuthInfoTest.java Wed Dec 16 22:07:43 2009
@@ -24,12 +24,14 @@
import org.apache.shindig.common.testing.FakeGadgetToken;
import org.apache.shindig.common.testing.FakeHttpServletRequest;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import javax.servlet.http.HttpServletRequest;
-public class AuthInfoTest extends TestCase {
+public class AuthInfoTest extends Assert {
+ @Test
public void testToken() throws Exception {
HttpServletRequest req = new FakeHttpServletRequest();
SecurityToken token = new FakeGadgetToken();
@@ -41,6 +43,7 @@
assertEquals(token, new AuthInfo(req).getSecurityToken());
}
+ @Test
public void testAuthType() throws Exception {
HttpServletRequest req = new FakeHttpServletRequest();
@@ -50,7 +53,8 @@
// This should work when creating a new AuthInfo from the same request
assertEquals("FakeAuth", new AuthInfo(req).getAuthType());
}
-
+
+ @Test
public void testBinding() throws Exception {
HttpServletRequest req = new FakeHttpServletRequest();
SecurityToken token = new FakeGadgetToken();
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/EasyMockTestCase.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/EasyMockTestCase.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/EasyMockTestCase.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/EasyMockTestCase.java Wed Dec 16 22:07:43 2009
@@ -19,26 +19,17 @@
import com.google.common.collect.Lists;
-import junit.framework.TestCase;
-
import org.easymock.classextension.EasyMock;
+import org.junit.Assert;
import java.lang.reflect.Method;
import java.util.List;
-public abstract class EasyMockTestCase extends TestCase {
+public abstract class EasyMockTestCase extends Assert {
/** Tracks all EasyMock objects created for a test. */
private final List<Object> mocks = Lists.newArrayList();
- public EasyMockTestCase() {
- super();
- }
-
- public EasyMockTestCase(String name) {
- super(name);
- }
-
/**
* Creates a strict mock object for the given class, adds it to the internal
* list of all mocks, and returns it.
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/JsonAssert.java Wed Dec 16 22:07:43 2009
@@ -20,6 +20,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -36,7 +37,7 @@
Object leftValue = left.opt(i);
Object rightValue = right.opt(i);
- assertEquals(left.toString() + " != " + right.toString(),
+ assertSame(left.toString() + " != " + right.toString(),
leftValue.getClass(), rightValue.getClass());
if (leftValue instanceof JSONObject) {
@@ -65,8 +66,8 @@
if (leftValue != null) {
assertNotNull(left.toString() + " != " + right.toString(), rightValue);
}
- assertEquals(left.toString() + " != " + right.toString(),
- leftValue.getClass(), rightValue.getClass());
+ assertSame(left.toString() + " != " + right.toString(),
+ leftValue.getClass(), rightValue.getClass());
if (leftValue instanceof JSONObject) {
assertJsonObjectEquals((JSONObject) leftValue, (JSONObject) rightValue);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/SoftExpiringCacheTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/SoftExpiringCacheTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/SoftExpiringCacheTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/SoftExpiringCacheTest.java Wed Dec 16 22:07:43 2009
@@ -20,15 +20,16 @@
import org.apache.shindig.common.util.FakeTimeSource;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class SoftExpiringCacheTest extends TestCase {
+public class SoftExpiringCacheTest extends Assert {
private FakeTimeSource timeSource;
private Cache<String, String> cache;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
timeSource = new FakeTimeSource(0);
cache = new LruCache<String, String>(5);
}
@@ -39,6 +40,7 @@
return expiringCache;
}
+ @Test
public void testGeneralCacheExpiration() {
SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
String key = "key1", val = "val1";
@@ -54,6 +56,7 @@
assertTrue(expiringCache.getElement(key).isExpired);
}
+ @Test
public void testMissingValue() {
SoftExpiringCache<String, String> expiringCache = makeSoftExpiringCache();
assertNull(expiringCache.getElement("not set"));
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/BlobCrypterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/BlobCrypterTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/BlobCrypterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/BlobCrypterTest.java Wed Dec 16 22:07:43 2009
@@ -21,15 +21,8 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import org.apache.shindig.common.crypto.BasicBlobCrypter;
-import org.apache.shindig.common.crypto.BlobCrypter;
-import org.apache.shindig.common.crypto.BlobCrypterException;
-import org.apache.shindig.common.crypto.BlobExpiredException;
-import org.apache.shindig.common.crypto.Crypto;
import org.apache.shindig.common.util.FakeTimeSource;
-import junit.framework.JUnit4TestAdapter;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -39,9 +32,6 @@
import java.util.Map;
public class BlobCrypterTest {
- public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(BlobCrypterTest.class);
- }
private BasicBlobCrypter crypter;
private FakeTimeSource timeSource;
@@ -125,51 +115,36 @@
}
}
- @Test
+ @Test(expected=BlobCrypterException.class)
public void testTamperIV() throws Exception {
- try {
- Map<String, String> in = ImmutableMap.of("a","b");
+ Map<String, String> in = ImmutableMap.of("a","b");
- String blob = crypter.wrap(in);
- byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
- blobBytes[0] ^= 0x01;
- String tampered = new String(Base64.encodeBase64(blobBytes));
- crypter.unwrap(tampered, 30);
- fail("Signature verification should have failed.");
- } catch (BlobCrypterException e) {
- // Good
- }
+ String blob = crypter.wrap(in);
+ byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
+ blobBytes[0] ^= 0x01;
+ String tampered = new String(Base64.encodeBase64(blobBytes));
+ crypter.unwrap(tampered, 30);
}
- @Test
+ @Test(expected=BlobCrypterException.class)
public void testTamperData() throws Exception {
- try {
- Map<String, String> in = ImmutableMap.of("a","b");
- String blob = crypter.wrap(in);
- byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
- blobBytes[30] ^= 0x01;
- String tampered = new String(Base64.encodeBase64(blobBytes));
- crypter.unwrap(tampered, 30);
- fail("Signature verification should have failed.");
- } catch (BlobCrypterException e) {
- // Good
- }
+ Map<String, String> in = ImmutableMap.of("a","b");
+ String blob = crypter.wrap(in);
+ byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
+ blobBytes[30] ^= 0x01;
+ String tampered = new String(Base64.encodeBase64(blobBytes));
+ crypter.unwrap(tampered, 30);
}
- @Test
+ @Test(expected=BlobCrypterException.class)
public void testTamperMac() throws Exception {
- try {
- Map<String, String> in = ImmutableMap.of("a","b");
+ Map<String, String> in = ImmutableMap.of("a","b");
- String blob = crypter.wrap(in);
- byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
- blobBytes[blobBytes.length-1] ^= 0x01;
- String tampered = new String(Base64.encodeBase64(blobBytes));
- crypter.unwrap(tampered, 30);
- fail("Signature verification should have failed.");
- } catch (BlobCrypterException e) {
- // Good
- }
+ String blob = crypter.wrap(in);
+ byte[] blobBytes = Base64.decodeBase64(blob.getBytes());
+ blobBytes[blobBytes.length-1] ^= 0x01;
+ String tampered = new String(Base64.encodeBase64(blobBytes));
+ crypter.unwrap(tampered, 30);
}
@Test
@@ -182,27 +157,17 @@
assertEquals("b", out.get("a"));
}
- @Test
+ @Test(expected=BlobCrypterException.class)
public void testBadKey() throws Exception {
BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes());
Map<String, String> in = ImmutableMap.of("a","b");
String blob = crypter.wrap(in);
- try {
- alt.unwrap(blob, 30);
- fail("Decryption should have failed");
- } catch (BlobCrypterException e) {
- // Good.
- }
+ alt.unwrap(blob, 30);
}
- @Test
+ @Test(expected=IllegalArgumentException.class)
public void testShortKeyFails() throws Exception {
- try {
- new BasicBlobCrypter("0123456789abcde".getBytes());
- fail("Short key should fail");
- } catch (IllegalArgumentException e) {
- // good.
- }
+ new BasicBlobCrypter("0123456789abcde".getBytes());
}
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/CryptoTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/CryptoTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/CryptoTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/crypto/CryptoTest.java Wed Dec 16 22:07:43 2009
@@ -21,24 +21,17 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import org.apache.shindig.common.crypto.BasicBlobCrypter;
-import org.apache.shindig.common.crypto.Crypto;
import org.apache.shindig.common.util.FakeTimeSource;
-import junit.framework.JUnit4TestAdapter;
-
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
import java.security.GeneralSecurityException;
import java.util.regex.Pattern;
public class CryptoTest {
- public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(CryptoTest.class);
- }
-
private BasicBlobCrypter crypter;
public CryptoTest() {
@@ -70,7 +63,7 @@
}
- @Test
+ @Test(expected = GeneralSecurityException.class)
public void testHmacSha1VerifyTampered() throws Exception {
String key = "abcd1234";
String val = "your mother is a hedgehog";
@@ -78,12 +71,7 @@
-21, 2, 47, -101, 9, -40, 18, 43, 76, 117,
-51, 115, -122, -91, 39, 0, -18, 122, 30, 90,
};
- try {
- Crypto.hmacSha1Verify(key.getBytes(), val.getBytes(), expected);
- fail();
- } catch (GeneralSecurityException e) {
- // OK
- }
+ Crypto.hmacSha1Verify(key.getBytes(), val.getBytes(), expected);
}
@Test
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/HttpServletUserAgentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/HttpServletUserAgentProviderTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/HttpServletUserAgentProviderTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/HttpServletUserAgentProviderTest.java Wed Dec 16 22:07:43 2009
@@ -22,8 +22,8 @@
import static org.easymock.EasyMock.expect;
import org.apache.shindig.common.EasyMockTestCase;
-import org.apache.shindig.common.servlet.HttpServletUserAgentProvider;
-import org.apache.shindig.common.servlet.UserAgent;
+
+import org.junit.Test;
import javax.servlet.http.HttpServletRequest;
@@ -32,7 +32,8 @@
*/
public class HttpServletUserAgentProviderTest extends EasyMockTestCase {
private UserAgent.Parser parser = new PassThroughUAParser();
-
+
+ @Test
public void testProviderWorks() {
String agentVersion = "AGENT_VERSION";
HttpServletRequest req = mock(HttpServletRequest.class);
@@ -42,16 +43,18 @@
parser, new HttpServletRequestProvider(req));
UserAgent entry = provider.get();
assertEquals(UserAgent.Browser.OTHER, entry.getBrowser());
- assertEquals(agentVersion, entry.getVersion().toString());
+ assertEquals(agentVersion, entry.getVersion());
verify();
}
-
+
+ @Test
public void testNoRequestGetsNull() {
HttpServletUserAgentProvider provider = new HttpServletUserAgentProvider(
parser, new HttpServletRequestProvider(null));
assertNull(provider.get());
}
-
+
+ @Test
public void testNoUserAgentGetsNull() {
HttpServletRequest req = mock(HttpServletRequest.class);
expect(req.getHeader("User-Agent")).andReturn(null).once();
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/UserAgentTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/UserAgentTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/UserAgentTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/servlet/UserAgentTest.java Wed Dec 16 22:07:43 2009
@@ -18,30 +18,36 @@
*/
package org.apache.shindig.common.servlet;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class UserAgentTest extends TestCase {
+public class UserAgentTest extends Assert {
private UserAgent getUaEntry(String version) {
return new UserAgent(UserAgent.Browser.OTHER, version);
}
-
+
+ @Test
public void testVersionNumberParsingStandard() {
- assertEquals(3D, getUaEntry("3").getVersionNumber());
+ assertEquals(3D, getUaEntry("3").getVersionNumber(), 0);
}
-
+
+ @Test
public void testVersionNumberParsingStandardDecimal() {
- assertEquals(3.1415, getUaEntry("3.1415").getVersionNumber());
+ assertEquals(3.1415, getUaEntry("3.1415").getVersionNumber(), 0);
}
+ @Test
public void testVersionNumberParsingMultiPart() {
- assertEquals(3.1, getUaEntry("3.1.5").getVersionNumber());
+ assertEquals(3.1, getUaEntry("3.1.5").getVersionNumber(), 0);
}
-
+
+ @Test
public void testVersionNumberParsingAlphaSuffix() {
- assertEquals(4.5, getUaEntry("4.5beta2").getVersionNumber());
+ assertEquals(4.5, getUaEntry("4.5beta2").getVersionNumber(), 0);
}
-
+
+ @Test
public void testVersionNumberParsingEmbeddedInTheMiddle() {
- assertEquals(1.5, getUaEntry("beta 1.5 rc 5").getVersionNumber());
+ assertEquals(1.5, getUaEntry("beta 1.5 rc 5").getVersionNumber(), 0);
}
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/FutureUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/FutureUtilTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/FutureUtilTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/FutureUtilTest.java Wed Dec 16 22:07:43 2009
@@ -22,16 +22,18 @@
import java.util.List;
import java.util.concurrent.Future;
-import junit.framework.TestCase;
-
import com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+
/**
* Tests the FutureUtils utility methods
*/
-public class FutureUtilTest extends TestCase {
+public class FutureUtilTest extends Assert {
String firstWord = "hello";
+ @Test
public void testGetFirstOfMany() throws Exception {
List<String> words = Lists.newArrayList(firstWord, "goodbye", "blah");
Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance(
@@ -41,6 +43,7 @@
assertEquals(firstWord, futureWord.get());
}
+ @Test
public void testGetFirstOfSingle() throws Exception {
List<String> words = Lists.newArrayList(firstWord);
Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance(
@@ -50,6 +53,7 @@
assertEquals(firstWord, futureWord.get());
}
+ @Test
public void testGetFirstOfNone() throws Exception {
List<String> words = Lists.newArrayList(new String[]{});
Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance(
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/ImmediateFutureTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/ImmediateFutureTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/ImmediateFutureTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/ImmediateFutureTest.java Wed Dec 16 22:07:43 2009
@@ -17,7 +17,8 @@
*/
package org.apache.shindig.common.util;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -26,19 +27,23 @@
/**
* Tests ImmediateFuture.
*/
-public class ImmediateFutureTest extends TestCase {
+public class ImmediateFutureTest extends Assert {
+ @Test
public void testGet() throws Exception {
assertEquals("foo", ImmediateFuture.newInstance("foo").get());
}
+ @Test
public void testGetNull() throws Exception {
assertNull(ImmediateFuture.newInstance(null).get());
}
+ @Test
public void testGetWithTimeout() throws Exception {
assertEquals("foo", ImmediateFuture.newInstance("foo").get(1L, TimeUnit.MILLISECONDS));
}
+ @Test
public void testCancel() {
Future<String> stringFuture = ImmediateFuture.newInstance("foo");
assertFalse(stringFuture.cancel(true));
@@ -46,10 +51,12 @@
assertFalse(stringFuture.isCancelled());
}
+ @Test
public void testIsDone() {
assertTrue(ImmediateFuture.newInstance("foo").isDone());
}
+ @Test
public void testErrorInstance() throws Exception {
RuntimeException re = new RuntimeException();
Future<String> errorFuture = ImmediateFuture.errorInstance(re);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/JsonConversionUtilTest.java Wed Dec 16 22:07:43 2009
@@ -17,25 +17,24 @@
*/
package org.apache.shindig.common.util;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import java.util.Map;
-
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
+import java.util.Map;
/**
* Test for conversion of a structured key-value set to a JSON object
*/
-public class JsonConversionUtilTest extends TestCase {
-
- public JsonConversionUtilTest() {
- }
+public class JsonConversionUtilTest extends Assert {
+ @Test
public void testSimplePathToJsonParsing()
throws Exception {
JSONObject root = new JSONObject();
@@ -43,6 +42,7 @@
assertJsonEquals(root, new JSONObject("{a:{a:{}}}"));
}
+ @Test
public void testArrayPathToJsonParsing()
throws Exception {
JSONObject root = new JSONObject();
@@ -52,6 +52,7 @@
assertJsonEquals(root, new JSONObject("{a:{a:[{},{},{}]}}"));
}
+ @Test
public void testValueToJsonParsing()
throws Exception {
assertJsonEquals(JsonConversionUtil.convertToJsonValue("abc"), "abc");
@@ -71,6 +72,7 @@
new JSONArray(Lists.newArrayList(true)));
}
+ @Test
public void testParameterMapToJsonParsing()
throws Exception {
assertJsonEquals(JsonConversionUtil.parametersToJsonObject(ImmutableMap.of("a.b.c", "1")),
@@ -96,6 +98,7 @@
new JSONObject("{a:{b:{c:\"hello, true, false, null, 1,2\"}}}"));
}
+ @Test
public void testJSONToParameterMapParsing()
throws Exception {
Map<String, String> resultMap = JsonConversionUtil
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/StringEncodingTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/StringEncodingTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/StringEncodingTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/util/StringEncodingTest.java Wed Dec 16 22:07:43 2009
@@ -24,14 +24,9 @@
import org.apache.shindig.common.crypto.Crypto;
import org.apache.shindig.common.util.StringEncoding;
-import junit.framework.JUnit4TestAdapter;
-
import org.junit.Test;
public class StringEncodingTest {
- public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(StringEncodingTest.class);
- }
@Test
public void testBase32() throws Exception {
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/FunctionsTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/FunctionsTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/FunctionsTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/FunctionsTest.java Wed Dec 16 22:07:43 2009
@@ -28,16 +28,19 @@
import com.google.inject.Guice;
import com.google.inject.Injector;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class FunctionsTest extends TestCase {
+public class FunctionsTest extends Assert {
private Functions functions;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
functions = new Functions(FunctionsTest.class);
}
+ @Test
public void testExpose() throws Exception {
Method hi = functions.resolveFunction("test", "hi");
assertEquals("hi", hi.invoke(null));
@@ -48,11 +51,13 @@
Method bonjour = functions.resolveFunction("other", "bonjour");
assertEquals("French hello", bonjour.invoke(null));
}
-
+
+ @Test
public void testNonStaticNotExposed() {
assertNull(functions.resolveFunction("test", "goodbye"));
}
-
+
+ @Test
public void testDefaultBinding() throws Exception {
Injector injector = Guice.createInjector();
functions = injector.getInstance(Functions.class);
@@ -62,7 +67,8 @@
assertTrue(o instanceof JSONObject);
assertEquals(1, ((JSONObject) o).getInt("a"));
}
-
+
+ @Test
public void testExpressionEvaluation() {
Expressions expressions = new Expressions(functions, null, new ShindigTypeConverter());
ELContext context = expressions.newELContext();
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/expressions/OpensocialFunctionsTest.java Wed Dec 16 22:07:43 2009
@@ -26,32 +26,37 @@
import com.google.common.collect.Maps;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class OpensocialFunctionsTest extends TestCase {
+public class OpensocialFunctionsTest extends Assert {
private Expressions expressions;
private ELContext context;
private Map<String, Object> vars = Maps.newHashMap();
- @Override
- protected void setUp() {
+ @Before
+ public void setUp() {
Functions functions = new Functions(OpensocialFunctions.class);
expressions = new Expressions(functions, null, new ShindigTypeConverter());
context = expressions.newELContext(new RootELResolver(vars));
}
-
+
+ @Test
public void testParseJsonObject() {
ValueExpression testParseJsonObject =
expressions.parse("${osx:parseJson('{a: 1}').a}", Integer.class);
assertEquals(1, testParseJsonObject.getValue(context));
}
+ @Test
public void testParseJsonArray() {
ValueExpression testParseJsonArray =
expressions.parse("${osx:parseJson('[1, 2, 3]')[1]}", Integer.class);
assertEquals(2, testParseJsonArray.getValue(context));
}
-
+
+ @Test
public void testDecodeBase64() throws Exception {
String test = "12345";
String encoded = new String(Base64.encodeBase64(test.getBytes("UTF-8")), "UTF-8");
@@ -62,6 +67,7 @@
assertEquals("12345", testDecodeBase64.getValue(context));
}
+ @Test
public void testUrlEncode() throws Exception {
String test = "He He";
vars.put("test", test);
@@ -71,6 +77,7 @@
assertEquals("He+He", testUrlEncode.getValue(context));
}
+ @Test
public void testUrlDecode() throws Exception {
String test = "He+He";
vars.put("encoded", test);
@@ -80,24 +87,28 @@
assertEquals("He He", testUrlDecode.getValue(context));
}
+ @Test
public void testParseJsonNull() throws Exception {
ValueExpression testUrlEncode =
expressions.parse("${osx:parseJson(null)}", String.class);
assertEquals("", testUrlEncode.getValue(context));
}
+ @Test
public void testDecodeBase64Null() throws Exception {
ValueExpression testUrlEncode =
expressions.parse("${osx:decodeBase64(null)}", String.class);
assertEquals("", testUrlEncode.getValue(context));
}
+ @Test
public void testUrlEncodeNull() throws Exception {
ValueExpression testUrlEncode =
expressions.parse("${osx:urlEncode(null)}", String.class);
assertEquals("", testUrlEncode.getValue(context));
}
+ @Test
public void testUrlDecodeNull() throws Exception {
ValueExpression testUrlDecode =
expressions.parse("${osx:urlDecode(null)}", String.class);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/BaseRequestItemTest.java Wed Dec 16 22:07:43 2009
@@ -27,20 +27,24 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
-import junit.framework.TestCase;
+
import org.json.JSONObject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test BaseRequestItem
*/
-public class BaseRequestItemTest extends TestCase {
+public class BaseRequestItemTest extends Assert {
private static final FakeGadgetToken FAKE_TOKEN = new FakeGadgetToken();
protected BaseRequestItem request;
protected BeanJsonConverter converter;
- @Override protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
FAKE_TOKEN.setAppId("12345");
FAKE_TOKEN.setOwnerId("someowner");
FAKE_TOKEN.setViewerId("someowner");
@@ -50,12 +54,13 @@
FAKE_TOKEN, converter, converter);
}
-
+ @Test
public void testParseCommaSeparatedList() throws Exception {
request.setParameter("fields", "huey,dewey,louie");
assertEquals(Lists.newArrayList("huey", "dewey", "louie"), request.getListParameter("fields"));
}
+ @Test
public void testGetAppId() throws Exception {
request.setParameter("appId", "100");
assertEquals("100", request.getAppId());
@@ -64,6 +69,7 @@
assertEquals(FAKE_TOKEN.getAppId(), request.getAppId());
}
+ @Test
public void testStartIndex() throws Exception {
request.setParameter("startIndex", null);
assertEquals(RequestItem.DEFAULT_START_INDEX, request.getStartIndex());
@@ -72,6 +78,7 @@
assertEquals(5, request.getStartIndex());
}
+ @Test
public void testCount() throws Exception {
request.setParameter("count", null);
assertEquals(RequestItem.DEFAULT_COUNT, request.getCount());
@@ -80,6 +87,7 @@
assertEquals(5, request.getCount());
}
+ @Test
public void testSortOrder() throws Exception {
request.setParameter("sortOrder", null);
assertEquals(SortOrder.ascending, request.getSortOrder());
@@ -88,6 +96,7 @@
assertEquals(SortOrder.descending, request.getSortOrder());
}
+ @Test
public void testFields() throws Exception {
request.setParameter("fields", "");
assertEquals(Sets.<String>newHashSet(), request.getFields());
@@ -96,13 +105,15 @@
assertEquals(Sets.newHashSet("happy", "sad", "grumpy"), request.getFields());
}
+ @Test
public void testGetTypedParameter() throws Exception {
request.setParameter("anykey", "{name: 'Bob', id: '1234'}");
InputData input = request.getTypedParameter("anykey", InputData.class);
assertEquals("Bob", input.name);
assertEquals(1234, input.id);
}
-
+
+ @Test
public void testGetInvalidJsonTypedParameter() throws Exception {
request.setParameter("anykey", "{name: 'Bob");
int code = 0;
@@ -114,19 +125,21 @@
assertEquals(HttpServletResponse.SC_BAD_REQUEST, code);
}
+ @Test
public void testJSONConstructor() throws Exception {
- request = new BaseRequestItem(new JSONObject("{" +
+ request = new BaseRequestItem(new JSONObject('{' +
"userId:john.doe," +
"groupId:@self," +
"fields:[huey,dewey,louie]" +
- "}"), null, FAKE_TOKEN, converter, converter);
+ '}'), null, FAKE_TOKEN, converter, converter);
assertEquals(Lists.newArrayList("huey", "dewey", "louie"), request.getListParameter("fields"));
}
+ @Test
public void testAttributes() throws Exception {
assertNull(request.getAttribute("undefined"));
request.setAttribute("test", "value");
- assertEquals((String)request.getAttribute("test"), "value");
+ assertEquals("value", request.getAttribute("test"));
request.setAttribute("test", null);
assertNull(request.getAttribute("undefined"));
}
@@ -143,5 +156,4 @@
this.id = id;
}
}
-}
-
+}
\ No newline at end of file
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/ContentTypesTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/ContentTypesTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/ContentTypesTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/ContentTypesTest.java Wed Dec 16 22:07:43 2009
@@ -18,42 +18,45 @@
*/
package org.apache.shindig.protocol;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Test content type checks
*/
-public class ContentTypesTest extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- }
+public class ContentTypesTest extends Assert {
+ @Test
public void testAllowJson() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES,
ContentTypes.OUTPUT_JSON_CONTENT_TYPE, true);
}
+ @Test
public void testAllowJsonRpc() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES,
"application/json-rpc", true);
}
+ @Test
public void testAllowAtom() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_ATOM_CONTENT_TYPES,
ContentTypes.OUTPUT_ATOM_CONTENT_TYPE, true);
}
+ @Test
public void testAllowXml() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_XML_CONTENT_TYPES,
ContentTypes.OUTPUT_XML_CONTENT_TYPE, true);
}
+ @Test
public void testAllowMultipart() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_MULTIPART_CONTENT_TYPES,
ContentTypes.MULTIPART_FORM_CONTENT_TYPE, true);
}
+ @Test
public void testForbidden() throws Exception {
try {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES,
@@ -63,6 +66,7 @@
}
}
+ @Test
public void testStrictDisallowUnknown() throws Exception {
try {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES,
@@ -72,11 +76,13 @@
}
}
+ @Test
public void testNonStrictAllowUnknown() throws Exception {
ContentTypes.checkContentTypes(ContentTypes.ALLOWED_JSON_CONTENT_TYPES,
"text/plain", false);
}
+ @Test
public void textExtractMimePart() throws Exception {
assertEquals("text/xml", ContentTypes.extractMimePart("Text/Xml ; charset = ISO-8859-1;x=y"));
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataCollectionTest.java Wed Dec 16 22:07:43 2009
@@ -18,12 +18,15 @@
package org.apache.shindig.protocol;
import com.google.common.collect.Maps;
-import junit.framework.TestCase;
+
+import org.junit.Assert;
+import org.junit.Test;
import java.util.Map;
-public class DataCollectionTest extends TestCase {
+public class DataCollectionTest extends Assert {
+ @Test
public void testBasicMethods() throws Exception {
Map<String, Map<String, String>> entry = Maps.newHashMap();
DataCollection collection = new DataCollection(entry);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DataServiceServletTest.java Wed Dec 16 22:07:43 2009
@@ -37,7 +37,11 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
-public class DataServiceServletTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DataServiceServletTest extends Assert {
private static final FakeGadgetToken FAKE_GADGET_TOKEN = new FakeGadgetToken()
.setOwnerId("john.doe").setViewerId("john.doe");
@@ -52,7 +56,8 @@
private IMocksControl mockControl = EasyMock.createNiceControl();
- @Override protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
servlet = new DataServiceServlet();
req = mockControl.createMock(HttpServletRequest.class);
res = mockControl.createMock(HttpServletResponse.class);
@@ -76,6 +81,7 @@
servlet.setBeanConverters(jsonConverter, xmlConverter, atomConverter);
}
+ @Test
public void testUriRecognition() throws Exception {
verifyHandlerWasFoundForPathInfo("/test/5/@self");
}
@@ -109,11 +115,13 @@
mockControl.reset();
}
+ @Test
public void testOverridePostWithGet() throws Exception {
String route = "/test";
verifyHandlerWasFoundForPathInfo(route, "POST", "GET");
}
+ @Test
public void testOverrideGetWithPost() throws Exception {
String route = "/test";
verifyHandlerWasFoundForPathInfo(route, "GET", "POST");
@@ -122,6 +130,7 @@
/**
* Tests a data handler that returns a failed Future
*/
+ @Test
public void testFailedRequest() throws Exception {
String route = "/test";
setupRequest(route, "DELETE", null);
@@ -152,6 +161,7 @@
req = fakeReq;
}
+ @Test
public void testGetConverterForRequest() throws Exception {
assertConverter(atomConverter, "atom");
assertConverter(xmlConverter, "xml");
@@ -160,6 +170,7 @@
assertConverter(jsonConverter, "ahhhh!");
}
+ @Test
public void testGetConverterForRequestContentType() throws Exception {
assertConverterForContentType(atomConverter, ContentTypes.OUTPUT_ATOM_CONTENT_TYPE);
assertConverterForContentType(xmlConverter, ContentTypes.OUTPUT_XML_CONTENT_TYPE);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/DefaultHandlerRegistryTest.java Wed Dec 16 22:07:43 2009
@@ -27,11 +27,10 @@
import com.google.common.collect.ImmutableSortedSet;
import com.google.inject.Guice;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
import org.json.JSONObject;
-import static org.junit.Assert.assertArrayEquals;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.Iterator;
import java.util.Set;
@@ -43,45 +42,50 @@
/**
* Tests BasicHandleRregistry
*/
-public class DefaultHandlerRegistryTest extends TestCase {
+public class DefaultHandlerRegistryTest extends Assert {
private DefaultHandlerRegistry registry;
private BeanJsonConverter converter;
- @Override
- @SuppressWarnings("unchecked")
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
converter = new BeanJsonConverter(Guice.createInjector());
registry = new DefaultHandlerRegistry(null, converter,
new HandlerExecutionListener.NoOpHandler());
registry.addHandlers(Sets.<Object>newHashSet(new TestHandler()));
}
+ @Test
public void testGetHandlerRPC() throws Exception {
assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.get}")));
}
+ @Test
public void testGetHandlerRest() throws Exception {
assertNotNull(registry.getRestHandler("/test/", "GET"));
}
+ @Test
public void testOverrideHandlerRPC() throws Exception {
assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.overidden}")));
}
+ @Test
public void testOverrideHandlerRPCName() throws Exception {
assertNotNull(registry.getRpcHandler(new JSONObject("{method : test.override.rpcname}")));
}
+ @Test
public void testOverrideHandlerRest() throws Exception {
assertNotNull(registry.getRestHandler("/test/overidden/method/", "GET"));
}
+ @Test
public void testGetForAliasHandler() {
assertNotNull(registry.getRestHandler("/test", "GET"));
}
+ @Test
public void testRpcHandler_serviceDoesntExist() throws Exception {
JSONObject rpc = new JSONObject("{method : makebelieve.get}");
RpcHandler rpcHandler = registry.getRpcHandler(rpc);
@@ -91,12 +95,13 @@
fail("Expect exception for missing method");
} catch (ExecutionException t) {
assertSame(t.getCause().getClass(), ProtocolException.class);
- Assert.assertEquals(((ProtocolException) t.getCause()).getCode(), HttpServletResponse.SC_NOT_IMPLEMENTED);
+ Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode());
} catch (Throwable t) {
fail("Unexpected exception " + t.toString());
}
}
+ @Test
public void testRestHandler_serviceDoesntExist() {
RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET");
try {
@@ -105,33 +110,37 @@
fail("Expect exception for missing method");
} catch (ExecutionException t) {
assertSame(t.getCause().getClass(), ProtocolException.class);
- Assert.assertEquals(((ProtocolException) t.getCause()).getCode(), HttpServletResponse.SC_NOT_IMPLEMENTED);
+ Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode());
} catch (Throwable t) {
fail("Unexpected exception " + t.toString());
}
}
+ @Test
public void testNonFutureDispatch() throws Exception {
// Test calling a handler method which does not return a future
RestHandler handler = registry.getRestHandler("/test", "GET");
Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null);
- assertEquals(future.get(), TestHandler.GET_RESPONSE);
+ assertEquals(TestHandler.GET_RESPONSE, future.get());
}
+ @Test
public void testFutureDispatch() throws Exception {
// Test calling a handler method which does not return a future
RestHandler handler = registry.getRestHandler("/test", "POST");
Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null);
- assertEquals(future.get(), TestHandler.CREATE_RESPONSE);
+ assertEquals(TestHandler.CREATE_RESPONSE, future.get());
}
+ @Test
public void testRpcWithInputClassThatIsntRequestItem() throws Exception {
JSONObject rpc = new JSONObject("{ method : test.echo, params: {value: 'Bob' }}");
RpcHandler handler = registry.getRpcHandler(rpc);
Future<?> future = handler.execute(null, null, converter);
assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob");
}
-
+
+ @Test
public void testRestWithInputClassThatIsntRequestItem() throws Exception {
RestHandler handler = registry.getRestHandler("/test/echo", "GET");
String[] value = {"Bob"};
@@ -139,13 +148,15 @@
assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob");
}
+ @Test
public void testNoArgumentClass() throws Exception {
JSONObject rpc = new JSONObject("{ method : test.noArg }");
RpcHandler handler = registry.getRpcHandler(rpc);
Future<?> future = handler.execute(null, null, converter);
- assertEquals(future.get(), TestHandler.NO_ARG_RESPONSE);
+ assertEquals(TestHandler.NO_ARG_RESPONSE, future.get());
}
+ @Test
public void testNonFutureException() throws Exception {
// Test calling a handler method which does not return a future
JSONObject rpc = new JSONObject("{ method : test.exception }");
@@ -159,6 +170,7 @@
}
}
+ @Test
public void testFutureException() throws Exception {
// Test calling a handler method which does not return a future
JSONObject rpc = new JSONObject("{ method : test.futureException }");
@@ -172,12 +184,14 @@
}
}
+ @Test
public void testSupportedRpcServices() throws Exception {
assertEquals(registry.getSupportedRpcServices(),
Sets.newHashSet("test.create", "test.get", "test.overridden", "test.exception",
"test.futureException", "test.override.rpcname", "test.echo", "test.noArg"));
}
+ @Test
public void testSupportedRestServices() throws Exception {
assertEquals(registry.getSupportedRestServices(),
Sets.newHashSet("GET /test/{someParam}/{someOtherParam}",
@@ -188,15 +202,12 @@
"GET /test/echo"));
}
+ @Test(expected = IllegalStateException.class)
public void testAddNonService() {
- try {
- registry.addHandlers(Sets.newHashSet(new Object()));
- fail("Adding an invalid service object succeded");
- } catch (IllegalStateException ise) {
-
- }
+ registry.addHandlers(Sets.newHashSet(new Object()));
}
+ @Test
public void testRestPath() {
DefaultHandlerRegistry.RestPath restPath =
new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null);
@@ -213,6 +224,7 @@
assertNull(restPath.accept("service/constmiss/{p1}/{p2}+/const2".split("/")));
}
+ @Test
public void testRestPathOrdering() {
DefaultHandlerRegistry.RestPath restPath1 =
new DefaultHandlerRegistry.RestPath("/service/const1/{p1}/{p2}+/const2/{p3}", null);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/JsonRpcServletTest.java Wed Dec 16 22:07:43 2009
@@ -42,16 +42,17 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import junit.framework.TestCase;
-
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.inject.Guice;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
/**
*
*/
-public class JsonRpcServletTest extends TestCase {
+public class JsonRpcServletTest extends Assert {
private static final FakeGadgetToken FAKE_GADGET_TOKEN = new FakeGadgetToken()
.setOwnerId("john.doe").setViewerId("john.doe");
@@ -72,7 +73,8 @@
private final PrintWriter writer = new PrintWriter(stream);
private final TestHandler handler = new TestHandler();
- @Override protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
servlet = new JsonRpcServlet();
req = mockControl.createMock(HttpServletRequest.class);
res = mockControl.createMock(HttpServletResponse.class);
@@ -102,6 +104,7 @@
return stream.toString("UTF-8");
}
+ @Test
public void testMethodRecognition() throws Exception {
setupRequest("{method:test.get,id:id,params:{userId:5,groupId:@self}}");
@@ -115,6 +118,7 @@
JsonAssert.assertJsonEquals("{id: 'id', data: {foo:'bar'}}", getOutput());
}
+ @Test
public void testPostMultipartFormData() throws Exception {
reset(multipartFormParser);
@@ -157,6 +161,7 @@
* Test that it passes even when content-type is not set for "request" parameter. This would
* be the case where the request is published via webform.
*/
+ @Test
public void testPostMultipartFormDataWithRequestFieldHavingNoContentType() throws Exception {
reset(multipartFormParser);
@@ -198,6 +203,7 @@
/**
* Test that any form-data other than "request" does not undergo any content type check.
*/
+ @Test
public void testPostMultipartFormDataOnlyRequestFieldHasContentTypeChecked()
throws Exception {
reset(multipartFormParser);
@@ -244,6 +250,7 @@
* Test that "request" field undergoes contentType check, and error is thrown if wrong content
* type is present.
*/
+ @Test
public void testPostMultipartFormDataRequestFieldIsSubjectedToContentTypeCheck()
throws Exception {
reset(multipartFormParser);
@@ -283,6 +290,7 @@
assertTrue(-1 != output.indexOf("Unsupported Content-Type application/octet-stream"));
}
+ @Test
public void testInvalidService() throws Exception {
setupRequest("{method:junk.get,id:id,params:{userId:5,groupId:@self}}");
@@ -303,6 +311,7 @@
* Tests a data handler that returns a failed Future.
* @throws Exception on failure
*/
+ @Test
public void testFailedRequest() throws Exception {
setupRequest("{id:id,method:test.futureException}");
@@ -317,6 +326,7 @@
"{id:id,error:{message:'badRequest: FAILURE_MESSAGE',code:400}}", getOutput());
}
+ @Test
public void testBasicBatch() throws Exception {
setupRequest("[{method:test.get,id:'1'},{method:test.get,id:'2'}]");
@@ -331,6 +341,7 @@
getOutput());
}
+ @Test
public void testGetExecution() throws Exception {
expect(req.getParameterMap()).andStubReturn(
ImmutableMap.of("method", new String[]{"test.get"}, "id", new String[]{"1"}));
@@ -349,18 +360,21 @@
JsonAssert.assertJsonEquals("{id:'1',data:{foo:'bar'}}", getOutput());
}
+ @Test
public void testGetJsonResponseWithKey() throws Exception {
ResponseItem responseItem = new ResponseItem("Name");
Object result = servlet.getJSONResponse("my-key", responseItem);
JsonAssert.assertObjectEquals("{id: 'my-key', data: 'Name'}", result);
}
+ @Test
public void testGetJsonResponseWithoutKey() throws Exception {
ResponseItem responseItem = new ResponseItem("Name");
Object result = servlet.getJSONResponse(null, responseItem);
JsonAssert.assertObjectEquals("{data: 'Name'}", result);
}
+ @Test
public void testGetJsonResponseErrorWithData() throws Exception {
ResponseItem responseItem = new ResponseItem(401, "Error Message", "Optional Data");
Object result = servlet.getJSONResponse(null, responseItem);
@@ -369,6 +383,7 @@
result);
}
+ @Test
public void testGetJsonResponseErrorWithoutData() throws Exception {
ResponseItem responseItem = new ResponseItem(401, "Error Message");
Object result = servlet.getJSONResponse(null, responseItem);
@@ -408,5 +423,4 @@
expect(formDataItem.getInputStream()).andStubReturn(in);
return formDataItem;
}
-
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/RestfulCollectionTest.java Wed Dec 16 22:07:43 2009
@@ -19,12 +19,13 @@
import com.google.common.collect.Lists;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import java.util.List;
-public class RestfulCollectionTest extends TestCase {
-
+public class RestfulCollectionTest extends Assert {
+ @Test
public void testBasicMethods() throws Exception {
RestfulCollection<String> collection
= new RestfulCollection<String>(Lists.<String>newArrayList());
@@ -42,6 +43,7 @@
assertEquals(totalResults, collection.getTotalResults());
}
+ @Test
public void testConstructors() throws Exception {
List<String> entry = Lists.newArrayList("banana", "who");
RestfulCollection<String> collection = new RestfulCollection<String>(entry);
@@ -61,5 +63,4 @@
assertEquals(totalResults, collection.getTotalResults());
assertEquals(resultsPerPage, collection.getItemsPerPage());
}
-
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterInjectedClassTest.java Wed Dec 16 22:07:43 2009
@@ -17,25 +17,23 @@
*/
package org.apache.shindig.protocol.conversion;
-import junit.framework.TestCase;
-
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
/**
* The Class BeanJsonConverterInjectedClassTest.
*/
-public class BeanJsonConverterInjectedClassTest extends TestCase {
+public class BeanJsonConverterInjectedClassTest extends Assert {
/** The bean json converter. */
private BeanJsonConverter beanJsonConverter;
- /* (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
this.beanJsonConverter = new BeanJsonConverter(Guice.createInjector(new TestModule()));
}
@@ -44,6 +42,7 @@
*
* @throws Exception the exception
*/
+ @Test
public void testJsonToObject() throws Exception {
String json = "{x:'xValue',y:'yValue'}";
TestObject object = (TestObject) beanJsonConverter.convertToObject(json, TestInterface.class);
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanJsonConverterTest.java Wed Dec 16 22:07:43 2009
@@ -25,7 +25,9 @@
import com.google.inject.Guice;
import com.google.inject.TypeLiteral;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
@@ -33,12 +35,11 @@
import java.util.Map;
import java.util.Map.Entry;
-public class BeanJsonConverterTest extends TestCase {
+public class BeanJsonConverterTest extends Assert {
private BeanJsonConverter beanJsonConverter;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
beanJsonConverter = new BeanJsonConverter(Guice.createInjector());
}
@@ -74,8 +75,9 @@
}
}
+ @Test
public void testJsonToObject() throws Exception {
- String json = "{" +
+ String json = '{' +
"hello:'world'," +
"count:10," +
"someStatic:'foo'," +
@@ -94,6 +96,7 @@
assertEquals(TestObject.TestEnum.bar, object.testEnum);
}
+ @Test
public void testJsonToPrimitives() throws Exception {
String simpleJson = "{hello:'world',count:10}";
@@ -105,6 +108,7 @@
assertEquals(10, map.get("count"));
}
+ @Test
public void testJsonToCar() throws Exception {
String carJson = "{engine:[{value:DIESEL},{value:TURBO}],parkingTickets:{SF:$137,NY:'$301'}," +
"passengers:[{gender:female,name:'Mum'}, {gender:male,name:'Dad'}]}";
@@ -118,17 +122,17 @@
assertEquals(car.getParkingTickets(), ImmutableMap.of("SF", "$137", "NY", "$301"));
TestModel.Passenger mum = car.getPassengers().get(0);
- assertEquals(mum.getGender(), TestModel.Gender.female);
- assertEquals(mum.getName(), "Mum");
+ assertEquals(TestModel.Gender.female, mum.getGender());
+ assertEquals("Mum", mum.getName());
TestModel.Passenger dad = car.getPassengers().get(1);
- assertEquals(dad.getGender(), TestModel.Gender.male);
- assertEquals(dad.getName(), "Dad");
+ assertEquals(TestModel.Gender.male, dad.getGender());
+ assertEquals("Dad", dad.getName());
}
+ @Test
public void testJsonToMap() throws Exception {
String jsonActivity = "{count : 0, favoriteColor : 'yellow'}";
- Map<String, Object> data = Maps.newHashMap();
- data = beanJsonConverter.convertToObject(jsonActivity,
+ Map<String, Object> data = beanJsonConverter.convertToObject(jsonActivity,
new TypeLiteral<Map<String, Object>>(){}.getType());
assertEquals(2, data.size());
@@ -144,6 +148,7 @@
}
}
+ @Test
public void testJsonToMapWithConversion() throws Exception {
String jsonActivity = "{count : 0, favoriteColor : 'yellow'}";
Map<String, String> data = Maps.newHashMap();
@@ -163,10 +168,10 @@
}
}
+ @Test
public void testJsonToNestedGeneric() throws Exception {
String jsonActivity = "{key0:[0,1,2],key1:[3,4,5]}";
- Map<String, List<Integer>> data = Maps.newHashMap();
- data = beanJsonConverter.convertToObject(jsonActivity,
+ Map<String, List<Integer>> data = beanJsonConverter.convertToObject(jsonActivity,
new TypeLiteral<Map<String, List<Integer>>>(){}.getType());
assertEquals(2, data.size());
@@ -175,10 +180,11 @@
assertEquals(Arrays.asList(3, 4, 5), data.get("key1"));
}
+ @Test
public void testEmptyJsonMap() throws Exception {
String emptyMap = "{}";
Map<String, String> data = beanJsonConverter.convertToObject(emptyMap,
new TypeLiteral<Map<String,String>>(){}.getType());
- assertTrue(data.size() == 0);
+ assertTrue(data.isEmpty());
}
}
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/conversion/BeanXmlConverterTest.java Wed Dec 16 22:07:43 2009
@@ -27,24 +27,27 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
import java.util.Map;
/**
* Basic test for betwixt based XML conversion
*/
-public class BeanXmlConverterTest extends TestCase {
+public class BeanXmlConverterTest extends Assert {
private TestModel.Car car;
private BeanXmlConverter beanXmlConverter;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
car = new TestModel.Car();
beanXmlConverter = new BeanXmlConverter();
}
+ @Test
public void testCarToXml() throws Exception {
String xml = beanXmlConverter.convertToXml(car);
XMLUnit.setIgnoreWhitespace(true);
@@ -54,6 +57,8 @@
XMLAssert.assertXMLEqual(diff, true);
}
+ @Test
+ @Ignore("unknown why this is disabled")
public void xxxtestMapsToXml() throws Exception {
// This is the structure our app data currently takes
Map<String, Map<String, String>> map = Maps.newTreeMap();
Modified: incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/multipart/DefaultMultipartFormParserTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/multipart/DefaultMultipartFormParserTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/multipart/DefaultMultipartFormParserTest.java (original)
+++ incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/protocol/multipart/DefaultMultipartFormParserTest.java Wed Dec 16 22:07:43 2009
@@ -24,11 +24,13 @@
import javax.servlet.http.HttpServletRequest;
-import junit.framework.TestCase;
-
import com.google.common.collect.Lists;
-public class DefaultMultipartFormParserTest extends TestCase {
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DefaultMultipartFormParserTest extends Assert {
private static final String REQUEST_FIELDNAME = "request";
private static final String REQUEST_DATA = "{name: 'HelloWorld'}";
@@ -46,7 +48,8 @@
private MultipartFormParser multipartFormParser;
private HttpServletRequest request;
- @Override protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
multipartFormParser = new DefaultMultipartFormParser();
}
@@ -54,6 +57,7 @@
* Test that requests must be both POST and have a multipart
* content type.
*/
+ @Test
public void testIsMultipartContent() {
FakeHttpServletRequest request = new FakeHttpServletRequest();
@@ -102,7 +106,7 @@
writeBoundary();
write("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" +
- fileName + "\"");
+ fileName + '\"');
write("\r\n");
write("Content-Type: " + contentType);
write("\r\n\r\n");
@@ -117,7 +121,7 @@
public void addFormField(String fieldName, String content, String contentType) {
writeBoundary();
- write("Content-Disposition: form-data; name=\"" + fieldName + "\"");
+ write("Content-Disposition: form-data; name=\"" + fieldName + '\"');
if (contentType != null) {
write("\r\n");
write("Content-Type: " + contentType);
@@ -145,6 +149,7 @@
request = fakeReq;
}
+ @Test
public void testSingleFileItem() throws Exception {
MultipartFormBuilder builder = new MultipartFormBuilder();
builder.addFileItem(ALBUM_IMAGE_FIELDNAME, ALBUM_IMAGE_FILENAME, ALBUM_IMAGE_DATA,
@@ -162,7 +167,8 @@
assertEquals(ALBUM_IMAGE_TYPE, formItem.getContentType());
assertEquals(ALBUM_IMAGE_DATA, new String(formItem.get()));
}
-
+
+ @Test
public void testSingleRequest() throws Exception {
MultipartFormBuilder builder = new MultipartFormBuilder();
builder.addFormField(REQUEST_FIELDNAME, REQUEST_DATA);
@@ -178,6 +184,7 @@
assertEquals(REQUEST_DATA, new String(formItem.get()));
}
+ @Test
public void testSingleFileItemAndRequest() throws Exception {
MultipartFormBuilder builder = new MultipartFormBuilder();
builder.addFileItem(ALBUM_IMAGE_FIELDNAME, ALBUM_IMAGE_FILENAME, ALBUM_IMAGE_DATA,
@@ -202,6 +209,7 @@
assertEquals(REQUEST_DATA, new String(formItem.get()));
}
+ @Test
public void testMultipleFileItemAndRequest() throws Exception {
MultipartFormBuilder builder = new MultipartFormBuilder();
builder.addFileItem(ALBUM_IMAGE_FIELDNAME, ALBUM_IMAGE_FILENAME, ALBUM_IMAGE_DATA,
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicGadgetBlacklistTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicGadgetBlacklistTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicGadgetBlacklistTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/BasicGadgetBlacklistTest.java Wed Dec 16 22:07:43 2009
@@ -20,7 +20,9 @@
import org.apache.shindig.common.uri.Uri;
-import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import java.io.BufferedWriter;
import java.io.File;
@@ -28,13 +30,12 @@
import java.io.IOException;
import java.util.regex.PatternSyntaxException;
-public class BasicGadgetBlacklistTest extends TestCase {
+public class BasicGadgetBlacklistTest extends Assert {
private Uri someUri;
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
someUri = Uri.parse("http://bla.com/foo.xml");
}
@@ -47,17 +48,20 @@
return new BasicGadgetBlacklist(temp);
}
+ @Test
public void testEmptyBlacklist() throws Exception {
GadgetBlacklist bl = createBlacklist("");
assertFalse(bl.isBlacklisted(someUri));
}
+ @Test
public void testExactMatches() throws Exception {
GadgetBlacklist bl = createBlacklist(someUri + "\nhttp://baz.com/foo.xml");
assertFalse(bl.isBlacklisted(Uri.parse("http://random.com/uri.xml")));
assertTrue(bl.isBlacklisted(someUri));
}
+ @Test
public void testExactMatchesWithCaseMixture() throws Exception {
GadgetBlacklist bl = createBlacklist(someUri + "\nhttp://BAZ.com/foo.xml");
assertTrue(bl.isBlacklisted(someUri));
@@ -65,12 +69,14 @@
assertTrue(bl.isBlacklisted(Uri.parse("http://baz.com/foo.xml")));
}
+ @Test
public void testIgnoredCommentsAndWhitespace() throws Exception {
GadgetBlacklist bl = createBlacklist(
"# comment\n \t" + someUri + " \n # comment\n\n");
assertTrue(bl.isBlacklisted(someUri));
}
+ @Test
public void testRegexpMatches() throws Exception {
GadgetBlacklist bl = createBlacklist("REGEXP http://bla.com/.*");
assertTrue(bl.isBlacklisted(someUri));
@@ -78,13 +84,8 @@
assertFalse(bl.isBlacklisted(Uri.parse("http://blo.com/bar.xml")));
}
+ @Test(expected=PatternSyntaxException.class)
public void testInvalidRegularExpression() throws Exception {
- try {
- createBlacklist("REGEXP +http://bla.com/.*");
- fail();
- } catch (PatternSyntaxException ex) {
- // success
- }
+ createBlacklist("REGEXP +http://bla.com/.*");
}
-
}
Modified: incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java?rev=891450&r1=891449&r2=891450&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java (original)
+++ incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/DefaultGadgetSpecFactoryTest.java Wed Dec 16 22:07:43 2009
@@ -270,12 +270,6 @@
expect(pipeline.execute(request)).andReturn(new HttpResponse("malformed junk")).once();
replay(pipeline);
- try {
- specFactory.getGadgetSpec(createContext(SPEC_URL, false));
- fail("No exception thrown on bad parse");
- } catch (GadgetException e) {
- // Expected.
- }
specFactory.getGadgetSpec(createContext(SPEC_URL, false));
}
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=891450&r1=891449&r2=891450&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 Dec 16 22:07:43 2009
@@ -37,6 +37,8 @@
import org.apache.commons.lang.StringEscapeUtils;
import junitx.framework.StringAssert;
+import org.junit.Before;
+import org.junit.Test;
import java.net.URI;
import java.util.Arrays;
@@ -71,9 +73,8 @@
private final FakeContainerConfig config = new FakeContainerConfig();
private UrlGenerator urlGenerator;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
expect(context.getContainer()).andReturn(CONTAINER).anyTimes();
expect(context.getUrl()).andReturn(Uri.parse(SPEC_URL)).anyTimes();
Map<String, String> prefMap = Maps.newHashMap();
@@ -97,6 +98,7 @@
reset(registry);
}
+ @Test
public void testGetBundledJsParamWithGoodFeatureName() throws Exception {
List<String> features = ImmutableList.of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
@@ -113,6 +115,7 @@
CONTAINER + "&debug=1"));
}
+ @Test
public void testGetBundledJsParamWithBadFeatureName() throws Exception {
List<String> features = Lists.newArrayList();
features.add("foo!");
@@ -125,6 +128,7 @@
assertTrue(jsParam.matches("bar\\.js\\?v=[0-9a-zA-Z]*&container=" + CONTAINER + "&debug=1"));
}
+ @Test
public void testGetBundledJsParamWithNoFeatures() throws Exception {
List<String> features = Lists.newArrayList();
expect(context.getDebug()).andReturn(false);
@@ -135,6 +139,7 @@
assertTrue(jsParam.matches("core\\.js\\?v=[0-9a-zA-Z]*&container=" + CONTAINER + "&debug=0"));
}
+ @Test
public void testGetBundledJsUrl() throws Exception {
List<String> features = Arrays.asList("foo", "bar");
expect(context.getDebug()).andReturn(false);
@@ -152,6 +157,7 @@
assertEquals("0", uri.getQueryParameter("debug"));
}
+ @Test
public void testGetIframeUrlTypeHtml() throws Exception {
String xml
= "<Module>" +
@@ -176,6 +182,7 @@
assertEquals(VIEW, iframeUrl.getQueryParameter("view"));
}
+ @Test
public void testGetIframeUrlTypeHtmlWithLockedDomain() throws Exception {
String xml
= "<Module>" +
@@ -204,6 +211,7 @@
assertEquals(VIEW, iframeUrl.getQueryParameter("view"));
}
+ @Test
public void testGetIframeUrlTypeUrl() throws Exception {
String xml
= "<Module>" +
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=891450&r1=891449&r2=891450&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 Dec 16 22:07:43 2009
@@ -31,6 +31,8 @@
import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.gadgets.features.FeatureRegistry;
import org.apache.shindig.gadgets.spec.GadgetSpec;
+import org.junit.Before;
+import org.junit.Test;
import java.util.Arrays;
import java.util.List;
@@ -74,9 +76,8 @@
return new Gadget().setSpec(spec).setGadgetFeatureRegistry(registry);
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() throws Exception {
expect(requiredConfig.getString(ContainerConfig.DEFAULT_CONTAINER,
LOCKED_DOMAIN_SUFFIX_KEY)).andReturn("-a.example.com:8080").anyTimes();
expect(requiredConfig.getBool(ContainerConfig.DEFAULT_CONTAINER,
@@ -96,6 +97,7 @@
}
+ @Test
public void testDisabledGlobally() {
replay();
@@ -116,6 +118,7 @@
assertTrue(lockedDomainService.gadgetCanRender("embed.com", wantsBoth, "default"));
}
+ @Test
public void testEnabledForGadget() {
replay();
@@ -151,6 +154,7 @@
assertEquals("h2nlf2a2dqou2lul3n50jb4v7e8t34kc-a.example.com:8080", target);
}
+ @Test
public void testNotEnabledForGadget() {
replay();
@@ -168,6 +172,7 @@
assertNull(lockedDomainService.getLockedDomainForGadget(notLocked, "default"));
}
+ @Test
public void testRequiredForContainer() {
replay();
@@ -196,6 +201,7 @@
}
+ @Test
public void testMissingConfig() throws Exception {
ContainerConfig containerMissingConfig = mock(ContainerConfig.class);
expect(containerMissingConfig.getContainers())
@@ -207,6 +213,7 @@
assertTrue(lockedDomainService.gadgetCanRender("www.example.com", notLocked, "default"));
}
+ @Test
public void testMultiContainer() throws Exception {
ContainerConfig inheritsConfig = mock(ContainerConfig.class);
expect(inheritsConfig.getContainers())