Author: doll
Date: Thu Apr 3 04:21:11 2008
New Revision: 644265
URL: http://svn.apache.org/viewvc?rev=644265&view=rev
Log:
SHINDIG-167
Added jsunit infrastructure and some beginning tests for opensocial js code.
Added:
incubator/shindig/trunk/features/opensocial-0.7/batchrequesttest.js
incubator/shindig/trunk/features/opensocial-0.7/jsonactivitytest.js
incubator/shindig/trunk/features/opensocial-reference/activitytest.js
Modified:
incubator/shindig/trunk/java/gadgets/pom.xml
Added: incubator/shindig/trunk/features/opensocial-0.7/batchrequesttest.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-0.7/batchrequesttest.js?rev=644265&view=auto
==============================================================================
--- incubator/shindig/trunk/features/opensocial-0.7/batchrequesttest.js (added)
+++ incubator/shindig/trunk/features/opensocial-0.7/batchrequesttest.js Thu Apr
3 04:21:11 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+var gadgets = gadgets || {};
+var opensocial = opensocial || {};
+
+function BatchRequestTest(name) {
+ TestCase.call(this, name);
+};
+BatchRequestTest.inherits(TestCase);
+
+BatchRequestTest.prototype.setUp = function() {
+ // Prepare for mocks
+ gadgets.io = gadgets.io || {};
+ this.oldEncodeValues = gadgets.io.encodeValues;
+ this.oldMakeNonProxiedRequest = gadgets.io.makeNonProxiedRequest;
+};
+
+BatchRequestTest.prototype.tearDown = function() {
+ // Remove mocks
+ gadgets.io.encodeValues = this.oldEncodeValues;
+ gadgets.io.makeNonProxiedRequest = this.oldMakeNonProxiedRequest;
+};
+
+BatchRequestTest.prototype.testSend = function() {
+ var expectedCallback = function() {};
+ var request = new BatchRequest('path', 'jsonText', expectedCallback,
+ {'extraParam1' : 'extraValue1'});
+
+ // Mock out makeRequest methods
+ gadgets.io.encodeValues = function(params) {
+ return params;
+ }
+
+ var testcase = this;
+ gadgets.io.makeNonProxiedRequest = function(actualPath, actualCallback,
+ actualParams) {
+ testcase.assertEquals('path', actualPath);
+ testcase.assertEquals(expectedCallback, actualCallback);
+
+ testcase.assertEquals('JSON', actualParams['CONTENT_TYPE']);
+ testcase.assertEquals('POST', actualParams['METHOD']);
+ testcase.assertEquals('SIGNED', actualParams['AUTHORIZATION']);
+
+ var postData = actualParams['POST_DATA'];
+ testcase.assertEquals('extraValue1', postData['extraParam1']);
+ testcase.assertEquals('jsonText', postData['request']);
+ }
+
+ request.send();
+};
\ No newline at end of file
Added: incubator/shindig/trunk/features/opensocial-0.7/jsonactivitytest.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-0.7/jsonactivitytest.js?rev=644265&view=auto
==============================================================================
--- incubator/shindig/trunk/features/opensocial-0.7/jsonactivitytest.js (added)
+++ incubator/shindig/trunk/features/opensocial-0.7/jsonactivitytest.js Thu Apr
3 04:21:11 2008
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+var gadgets = gadgets || {};
+var opensocial = opensocial || {};
+
+function JsonActivityTest(name) {
+ TestCase.call(this, name);
+};
+JsonActivityTest.inherits(TestCase);
+
+JsonActivityTest.prototype.setUp = function() {
+ // Prepare for mocks
+ gadgets.util = gadgets.util || {};
+ this.oldEscape = gadgets.util.escape;
+ gadgets.util.escape = function(param) {
+ return param;
+ };
+};
+
+JsonActivityTest.prototype.tearDown = function() {
+ // Remove mocks
+ gadgets.util.escape = this.oldEscape;
+};
+
+JsonActivityTest.prototype.testConstructArrayObject = function() {
+ var map = {'fakeClass' : [{'field1' : 'value1'}, {'field2' : 'value2'}]};
+ FakeClass = function(opt_params) {
+ this.fields = opt_params;
+ }
+
+ JsonActivity.constructArrayObject(map, 'fakeClass', FakeClass);
+
+ var result = map['fakeClass'];
+ this.assertTrue(result instanceof Array);
+ this.assertTrue(result[0] instanceof FakeClass);
+ this.assertTrue(result[1] instanceof FakeClass);
+ this.assertEquals('value1', result[0].fields['field1']);
+ this.assertEquals('value2', result[1].fields['field2']);
+};
+
+JsonActivityTest.prototype.testJsonActivityConstructor = function() {
+ var activity = new JsonActivity({'title' : 'green',
+ 'mediaItems' : [{'mimeType' : 'black', 'url' : 'white',
+ 'type' : 'orange'}]});
+
+ var fields = opensocial.Activity.Field;
+ this.assertEquals('green', activity.getField(fields.TITLE));
+
+ var mediaItems = activity.getField(fields.MEDIA_ITEMS);
+ this.assertTrue(mediaItems instanceof Array);
+ this.assertTrue(mediaItems[0] instanceof JsonMediaItem);
+
+ var mediaItemFields = opensocial.Activity.MediaItem.Field;
+ this.assertEquals('black',
mediaItems[0].getField(mediaItemFields.MIME_TYPE));
+ this.assertEquals('white', mediaItems[0].getField(mediaItemFields.URL));
+ this.assertEquals('orange', mediaItems[0].getField(mediaItemFields.TYPE));
+};
+
+JsonActivityTest.prototype.testJsonActivityMediaItemConstructor = function() {
+ var mediaItem = new JsonMediaItem({'mimeType' : 'black', 'url' : 'white',
+ 'type' : 'orange'});
+
+ var fields = opensocial.Activity.MediaItem.Field;
+ this.assertEquals('black', mediaItem.getField(fields.MIME_TYPE));
+ this.assertEquals('white', mediaItem.getField(fields.URL));
+ this.assertEquals('orange', mediaItem.getField(fields.TYPE));
+};
\ No newline at end of file
Added: incubator/shindig/trunk/features/opensocial-reference/activitytest.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-reference/activitytest.js?rev=644265&view=auto
==============================================================================
--- incubator/shindig/trunk/features/opensocial-reference/activitytest.js
(added)
+++ incubator/shindig/trunk/features/opensocial-reference/activitytest.js Thu
Apr 3 04:21:11 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+var gadgets = gadgets || {};
+var opensocial = opensocial || {};
+
+function ActivityTest(name) {
+ TestCase.call(this, name);
+};
+ActivityTest.inherits(TestCase);
+
+ActivityTest.prototype.setUp = function() {
+ // Prepare for mocks
+ gadgets.util = gadgets.util || {};
+ this.oldEscape = gadgets.util.escape;
+ gadgets.util.escape = function(param) {
+ return param;
+ };
+};
+
+ActivityTest.prototype.tearDown = function() {
+ // Remove mocks
+ gadgets.util.escape = this.oldEscape;
+};
+
+ActivityTest.prototype.testSetField = function() {
+ var activity = new opensocial.Activity({'title' : 'yellow'});
+ this.assertEquals('yellow', activity.getField('title'));
+
+ activity.setField('title', 'purple');
+ this.assertEquals('purple', activity.getField('title'));
+};
\ No newline at end of file
Modified: incubator/shindig/trunk/java/gadgets/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/pom.xml?rev=644265&r1=644264&r2=644265&view=diff
==============================================================================
--- incubator/shindig/trunk/java/gadgets/pom.xml (original)
+++ incubator/shindig/trunk/java/gadgets/pom.xml Thu Apr 3 04:21:11 2008
@@ -146,6 +146,57 @@
</excludes>
</configuration>
</plugin>
+ <plugin>
+ <groupId>de.berlios.jsunit</groupId>
+ <artifactId>jsunit-maven2-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>test</id>
+ <configuration>
+ <sourceDirectory>../../</sourceDirectory>
+ <sources>
+ <source>features/opensocial-reference/opensocial.js</source>
+ <source>features/opensocial-reference/activity.js</source>
+ <source>features/opensocial-reference/address.js</source>
+ <source>features/opensocial-reference/bodytype.js</source>
+ <source>features/opensocial-reference/collection.js</source>
+ <source>features/opensocial-reference/container.js</source>
+ <source>features/opensocial-reference/datarequest.js</source>
+ <source>features/opensocial-reference/dataresponse.js</source>
+ <source>features/opensocial-reference/email.js</source>
+ <source>features/opensocial-reference/enum.js</source>
+ <source>features/opensocial-reference/environment.js</source>
+ <source>features/opensocial-reference/message.js</source>
+ <source>features/opensocial-reference/name.js</source>
+ <source>features/opensocial-reference/organization.js</source>
+ <source>features/opensocial-reference/person.js</source>
+ <source>features/opensocial-reference/phone.js</source>
+ <source>features/opensocial-reference/responseitem.js</source>
+ <source>features/opensocial-reference/url.js</source>
+ <source>features/opensocial-0.7/batchrequest.js</source>
+ <source>features/opensocial-0.7/jsonactivity.js</source>
+ <source>features/opensocial-0.7/jsonperson.js</source>
+ <source>features/opensocial-0.7/jsoncontainer.js</source>
+ </sources>
+ <testSourceDirectory>../../</testSourceDirectory>
+
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
+ <testSuites>
+ <testSuite>
+ <name>OpenSocialJsTests</name>
+ <type>TESTCASES</type>
+ <includes>
+ <include>features/opensocial-reference/*test.js</include>
+ <include>features/opensocial-0.7/*test.js</include>
+ </includes>
+ </testSuite>
+ </testSuites>
+ </configuration>
+ <goals>
+ <goal>jsunit-test</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
<resources>
<resource>