Author: evan
Date: Wed Sep 17 11:40:51 2008
New Revision: 696394

URL: http://svn.apache.org/viewvc?rev=696394&view=rev
Log:
OpenSocial template tests need to be automated

Patch by Kevin Jin for SHINDIG-585:


Added:
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/compiler_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/container_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/loader_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/os_test.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/testadapter.js
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/util_test.js
Modified:
    
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java

Modified: 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java?rev=696394&r1=696393&r2=696394&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
 (original)
+++ 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
 Wed Sep 17 11:40:51 2008
@@ -97,6 +97,11 @@
     executePageTest("errorTest", "internalError");
   }
 
+  @Test
+  public void testTemplates() throws Exception {
+    executeAllPageTests("opensocial-templates/ost_test");
+  }
+
   @BeforeClass
   public static void setUpOnce() throws Exception {
     server = new EndToEndServer();

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/compiler_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/compiler_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/compiler_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/compiler_test.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ */
+
+/**
+ * Unit test for compiler identifier wrapping.
+ *    "'a'",
+ *    "foo",
+ *    "foo + bar",
+ *    "foo||bar",
+ *    "foo.bar",
+ *    "foo().bar",
+ *    "foo.bar(baz)",
+ *    "foo.bar().baz",
+ *    "foo('a').bar",
+ *    "foo[bar].baz",
+ *    "foo.bar.baz",
+ *    "$my('foo').bar",
+ *    "$cur($context, 'person').ProfileName",
+ *    "foo(bar)[baz]"
+ */
+function testWrapIdentifiers() {
+  assertEquals("$_ir($_ir($context, 'foo'), 'bar')", 
+      os.wrapIdentifiersInExpression("foo.bar"));
+
+  assertEquals("$_ir($_ir($context, 'data'), 'array')()",
+      os.wrapIdentifiersInExpression("data.array()"));
+
+  assertEquals("$_ir($_ir($context, 'data')(), 'array')", 
+      os.wrapIdentifiersInExpression('data().array'));
+
+  // Check that namespaced tags are treated as single identifiers.      
+  assertEquals("$_ir($context, 'os:Item')", 
+      os.wrapIdentifiersInExpression("os:Item"));
+      
+  // Check that a colon surrounded by spaces is not treated as 
+  // part of identifier 
+  assertEquals("$_ir($context, 'foo') ? $_ir($context, 'bar') : " + 
+      "$_ir($context, 'baz')",
+      os.wrapIdentifiersInExpression("foo ? bar : baz"));
+}
+
+function testTransformVariables() {
+  assertEquals("$this.foo", os.transformVariables_('$cur.foo'));
+}
+
+/**
+ * Unit test for JSP operator support.
+ */
+function testOperators() {
+  var data = {A:42, B:101};
+
+  var testData = [
+    { template:"${A lt B}", expected:"true" },
+    { template:"${A gt B}", expected:"false" },
+    { template:"${A eq A}", expected:"true" },
+    { template:"${A neq A}", expected:"false" },
+    { template:"${A lte A}", expected:"true" },
+    { template:"${A lte B}", expected:"true" },
+    { template:"${A gte B}", expected:"false" },
+    { template:"${A gte A}", expected:"true" },
+    { template:"${A eq " + data.A + "}", expected:"true" },
+    { template:"${(A eq A) ? 'PASS' : 'FAIL'}", expected:"PASS" },
+    { template:"${not true}", expected:"false" },
+    { template:"${A eq A and B eq B}", expected:"true" },
+    { template:"${A eq A and false}", expected:"false" },
+    { template:"${false or A eq A}", expected:"true" },
+    { template:"${false or false}", expected:"false" }
+    //TODO: precedence, parenthesis
+  ];
+
+  for (var i = 0; i < testData.length; i++) {
+    var testEntry = testData[i];
+    var template = os.compileTemplateString(testEntry.template);
+    var resultNode = template.render(data);
+    var resultStr = resultNode.firstChild.innerHTML;
+    assertEquals(resultStr, testEntry.expected);
+  }
+}
+
+function testCopyAttributes() {
+  var src = document.createElement('div');
+  var dst = document.createElement('div');
+  src.setAttribute('attr', 'test');
+  src.setAttribute('class', 'foo');
+  os.copyAttributes_(src, dst);
+  assertEquals('test', dst.getAttribute('attr'));
+  assertEquals('foo', dst.getAttribute('className'));
+  assertEquals('foo', dst.className);
+}
+
+/**
+ * Tests TBODY injection.
+ */
+function testTbodyInjection() {
+  var src, check, template, output;
+  
+  // One row.
+  src = "<table><tr><td>foo</td></tr></table>";
+  check = "<table><tbody><tr><td>foo</td></tr></tbody></table>";
+  template = os.compileTemplateString(src);
+  output = template.templateRoot_.innerHTML;
+  output = output.toLowerCase();
+  output = output.replace(/\s/g, '');
+  assertEquals(check, output);
+  
+  // Two rows.
+  src = "<table><tr><td>foo</td></tr><tr><td>bar</td></tr></table>";
+  check = "<table><tbody><tr><td>foo</td></tr>" + 
+      "<tr><td>bar</td></tr></tbody></table>";
+  template = os.compileTemplateString(src);
+  output = template.templateRoot_.innerHTML;
+  output = output.toLowerCase();
+  output = output.replace(/\s/g, '');
+  assertEquals(check, output);  
+}
+
+function testEventHandlers() {
+  var src, template, output;
+  
+  window['testEvent'] = function(value) {
+    window['testValue'] = value;
+  };
+  
+  // Static handler
+  src = "<button onclick=\"testEvent(true)\">Foo</button>";
+  template = os.compileTemplateString(src);
+  output = template.render();
+  // Append to document to enable events
+  document.body.appendChild(output);
+  window['testValue'] = false;
+  output.firstChild.click();
+  document.body.removeChild(output);
+  assertEquals(true, window['testValue']);
+  
+  // Dynamic handler
+  src = "<button onclick=\"testEvent('${title}')\">Foo</button>";
+  template = os.compileTemplateString(src);
+  output = template.render({ title: 'foo' });
+  // Append to document to enable events
+  document.body.appendChild(output);
+  window['testValue'] = false;
+  output.firstChild.click();
+  document.body.removeChild(output);
+  assertEquals('foo', window['testValue']); 
+}
+
+function testNestedIndex() {
+  var src, template, output;
+  
+  src = '<table><tr repeat="list" var="row" index="x">' + 
+      '<td repeat="row" index="y">${x},${y}</td></tr></table>';
+  template = os.compileTemplateString(src);
+  output = template.render({ list: [ ['a', 'b'], ['c', 'd'] ] });
+  //                           table  /  tbody  /   tr    /   td
+  assertEquals('1,1', 
output.lastChild.lastChild.lastChild.lastChild.innerHTML);
+};
+
+function testLoopNullDefaultValue() {
+  var src = '<div repeat="foo">a</div>';
+  var template = os.compileTemplateString(src);
+  var select = template.templateRoot_.firstChild.getAttribute("jsselect");
+  assertEquals("$_ir($context, 'foo', null)", select); 
+}
+
+function testGetFromContext() {
+  // JSON context
+  var context = { foo: 'bar' };
+  assertEquals('bar', os.getFromContext(context, 'foo'));
+  
+  // JsEvalContext  
+  context = os.createContext(context);
+  assertEquals('bar', os.getFromContext(context, 'foo'));
+  
+  // Variable from context
+  context.setVariable('baz', 'bing');
+  assertEquals('bing', os.getFromContext(context, 'baz'));
+  
+  // Non-existent value
+  assertEquals('', os.getFromContext(context, 'title'));
+  
+  // Non-existent value with default
+  assertEquals(null, os.getFromContext(context, 'title', null));
+}

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/container_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/container_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/container_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/container_test.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+function testTemplateType() {
+  assertTrue(os.Container.isTemplateType_('text/template'));
+  assertTrue(os.Container.isTemplateType_('text/os-template'));
+  assertTrue(!os.Container.isTemplateType_('os-template'));
+}
+
+function testRegisterTemplates() {
+  os.Container.registerDocumentTemplates();
+  assertNotNull(os.getTemplate('os:Test'));
+  os.Container.processInlineTemplates();
+  var el = document.getElementById('test');
+  assertNotNull(el);
+  assertEquals('tag template', domutil.getVisibleText(el));
+}

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/data_test.js
 Wed Sep 17 11:40:51 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.
+ */
+
+/**
+ * Returns a namespace object. Creates one if it does not exist.
+ * @param {string} name The namespace name.
+ * @return {Object} The namespace object.
+ */
+function verifyNamespace(name) {
+  var ns = os.getNamespace(name);
+  if (!ns) {
+    ns = os.createNamespace(name);
+  }
+  return ns;
+}
+
+/**
+ * Unit test to check full functionality of a request handler.
+ */
+function testRequestHandler() {
+  verifyNamespace('test');
+  var results = {};
+  os.data.registerRequestHandler('test:request', function(key, tag) {
+    results[key] = tag.getAttribute('data');
+  });
+  var xmlData = '<os:dataSet key="first">' +
+      '  <test:request data="testData"/>' +
+      '</os:dataSet>' +
+      '<os:dataSet key="second">' +
+      '  <test:request data="${foo}"/>' +
+      '</os:dataSet>';
+  os.data.loadRequests(xmlData);
+  assertNotNull(os.data.requests_['test']);
+  assertNotNull(os.data.requests_['test']['first']);
+  assertNotNull(os.data.requests_['test']['second']);
+
+  os.data.DataContext.putDataSet("foo", "bar");
+  os.data.executeRequests();
+
+  assertEquals('testData', results['first']);
+  assertEquals('bar', results['second']);
+}
+
+/**
+ * Unit test to test data result handlers.
+ */
+function testResultHandler() {
+  var key = 'test1';
+  var value = 'foo';
+  var handler = function(callback) {
+    callback(value);
+  };
+  os.data.DataContext.putDataResult(key, handler);
+  assertEquals(value, os.data.DataContext.getDataSet(key));
+}
+
+/**
+ * Unit test to test listener functionality when a data key is put.
+ */
+function testListener() {
+  var fired = false;
+  os.data.DataContext.registerListener('testKey', function() {
+    fired = true;
+  });
+  os.data.DataContext.putDataSet('testKey', {});
+  assertEquals(true, fired);
+}
+

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/loader_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/loader_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/loader_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/loader_test.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,127 @@
+/*
+ * 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.
+ */
+
+/**
+ * Unit test for injecting JavaScript into the global scope with the 
+ * os.Loader.
+ */
+function testInjectJavaScript() {
+  var jsCode = "function testFunction() { return 'foo'; }";
+  os.Loader.injectJavaScript(jsCode);
+  assertTrue(window.testFunction instanceof Function);
+  assertEquals(window.testFunction(), 'foo');
+}
+
+/**
+ * Unit test for injecting CSS through the os.Loader.
+ */
+function testInjectStyle() {
+  var cssCode = '.testCSS { width: 100px; height: 200px; }';
+  os.Loader.injectStyle(cssCode);
+  var rule = getStyleRule('.testCSS');
+  assertNotNull(rule);
+  assertEquals(rule.style.width, '100px');
+  assertEquals(rule.style.height, '200px');
+}
+
+/**
+ * @type {String} Template XML data for testLoadContent.
+ */
+var testContentXML =
+    '<Templates xmlns:test="http://www.google.com/#test";>' +
+    '  <Namespace prefix="test" url="http://www.google.com/#test"/>' +
+    '  <Template tag="test:tag">' +
+    '    <div id="tag"></div>' +
+    '  </Template>' +
+    '  <JavaScript>' +
+    '    function testJavaScript() {' +
+    '      return "testJavaScript";' +
+    '    }' +
+    '  </JavaScript>' +
+    '  <Style>' +
+    '    .testStyle {' +
+    '      width: 24px;' +
+    '    }' +
+    '  </Style>' +
+    '  <TemplateDef tag="test:tagDef">' +
+    '    <Template>' +
+    '      <div id="tagDef"></div>' +
+    '    </Template>' +
+    '    <JavaScript>' +
+    '      function testJavaScriptDef() {' +
+    '        return "testJavaScriptDef";' +
+    '      }' +
+    '    </JavaScript>' +
+    '    <Style>' +
+    '      .testStyleDef {' +
+    '        height: 42px;' +
+    '      }' +
+    '    </Style>' +
+    '  </TemplateDef>' +
+    '</Templates>';
+
+/**
+ * System test for os.loadContent functionality. This tests
+ * all functionality except for XHR.
+ */
+function testLoadContent() {
+  os.Loader.loadContent(testContentXML);
+
+  // Verify registered tags.
+  var ns = os.nsmap_['test'];
+  assertNotNull(ns);
+  assertTrue(ns['tag'] instanceof Function);
+  assertTrue(ns['tagDef'] instanceof Function);
+
+  // Verify JavaScript functions.
+  assertTrue(window['testJavaScript'] instanceof Function);
+  assertEquals(window.testJavaScript(), 'testJavaScript');
+  assertTrue(window['testJavaScriptDef'] instanceof Function);
+  assertEquals(window.testJavaScriptDef(), 'testJavaScriptDef');
+
+  // Verify styles.
+  var rule = getStyleRule('.testStyle');
+  assertNotNull(rule);
+  assertEquals(rule.style.width, '24px');
+  var ruleDef = getStyleRule('.testStyleDef');
+  assertNotNull(ruleDef);
+  assertEquals(ruleDef.style.height, '42px');
+}
+
+/**
+ * Utility function for retrieving a style rule by selector text
+ * if its available.
+ * @param {string} name Selector text name.
+ * @return {Object} CSSRule object.
+ */
+function getStyleRule(name) {
+  var sheets = document.styleSheets;
+  for (var i = 0; i < sheets.length; ++i) {
+    var rules = sheets[i].cssRules || sheets[i].rules;
+    if (rules) {
+      for (var j = 0; j < rules.length; ++j) {
+        if (rules[j].selectorText == name
+            //hack for WebKit Quirks mode
+            || rules[j].selectorText == name.toLowerCase()) {
+          return rules[j];
+        }
+      }
+    }
+  }
+  return null;
+}

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/os_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/os_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/os_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/os_test.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+/**
+ * Unit test for testing the behavior of the OpenSocial identifier resolver.
+ */
+function testResolveOpenSocialIdentifier() {
+  /**
+   * Sample class with a property, property getter, custom getField and a get()
+   * method.
+   */
+  var TestClass = function() {
+    this.foo = 'fooData';
+    this.bar_ = 'barData';
+    this.thumbnailUrl_ = 'thumbnailUrlData';
+    this.responseItem_ = {};
+    this.responseItem_.getData = function() {
+      return 'responseItemData';
+    };
+  };
+  
+  TestClass.prototype.getBar = function() {
+    return this.bar_;
+  };
+  
+  TestClass.prototype.getField = function(field) {
+    if (field == 'THUMBNAIL_URL') {
+      return this.thumbnailUrl_;
+    }
+    return null;
+  };
+  
+  TestClass.prototype.get = function(field) {
+    if (field == 'responseItem') {
+      return this.responseItem_;
+    }
+    return null;
+  };
+  
+  var obj = new TestClass(); 
+  
+  assertEquals('fooData', os.resolveOpenSocialIdentifier(obj, 'foo'));
+  assertEquals('barData', os.resolveOpenSocialIdentifier(obj, 'bar'));
+  assertEquals('thumbnailUrlData',
+      os.resolveOpenSocialIdentifier(obj, 'THUMBNAIL_URL'));
+  assertEquals('responseItemData',
+      os.resolveOpenSocialIdentifier(obj, 'responseItem'));
+}
\ No newline at end of file

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/ost_test.xml
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<Module>
+  <ModulePrefs title="TemplatesEndToEndTest">
+    <Require feature="opensocial-0.8"/>
+    <Require feature="opensocial-templates"/>
+  </ModulePrefs>
+  <Content type="html">
+    <![CDATA[
+    <script type="text/javascript" src="testadapter.js"></script>
+    <!-- the JsUnit tests -->
+    <script type="text/javascript" src="compiler_test.js"></script>
+    <script type="text/javascript" src="data_test.js"></script>
+    <script type="text/javascript" src="container_test.js"></script>
+    <script type="text/javascript" src="loader_test.js"></script>
+    <script type="text/javascript" src="os_test.js"></script>
+    <script type="text/javascript" src="util_test.js"></script>
+
+    <div style="display: none">
+      <div id="domSource">
+        <ul>
+          <li>one</li>
+          <li>two</li>
+        </ul>
+        <b>bold</b>
+      </div>
+      <div id="domTarget">
+      </div>
+    </div>
+    ]]>
+  </Content>
+</Module>

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/testadapter.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/testadapter.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/testadapter.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/testadapter.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+function findTests() {
+  // The following tests fail due to HtmlUnit limitation.
+  // If a name exists in this object, it is excluded from testing.
+  var excludedTests = {
+    testEventHandlers : 1,
+    testInjectStyle : 1,
+    testLoadContent : 1,
+    testInjectJavaScript : 1,
+    testRegisterTemplates : 1
+  };
+
+  var testSource = typeof RuntimeObject != 'undefined' ?
+                   RuntimeObject('test' + '*') : self;
+  var tests = {};
+  for (i in testSource) {
+    if (i.substring(0, 4) == 'test' && typeof(testSource[i]) == 'function'
+      && ! (i in excludedTests)) {
+      tests[i] = testSource[i];
+    }
+  }
+  return tests;
+}
+
+function assertTrue(value) {
+  if (!value) {
+    throw "assertTrue() failed: ";
+  }
+}
+
+function assertFalse(value) {
+  if (value) {
+    throw "assertFalse() failed: ";
+  }
+}
+
+function assertEquals(a, b) {
+  if (a != b) {
+    throw "assertEquals() failed: " +
+          "\nExpected \"" + a + "\", was \"" + b + "\"";
+  }
+}
+
+function assertNotNull(value) {
+  if (value === null) {
+    throw "assertTrue() failed: ";
+  }
+}
+
+function allTests() {
+  var tests = findTests();
+  for (var testMethod in tests) {
+    alert(testMethod);
+    tests[testMethod]();
+    alert("FINISHED");
+  }
+}
+
+gadgets.util.registerOnLoadHandler(allTests);

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/util_test.js
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/util_test.js?rev=696394&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/util_test.js
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/opensocial-templates/util_test.js
 Wed Sep 17 11:40:51 2008
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+
+/**
+ * Unit test for various DOM utils.
+ */
+function testDomUtils() {
+  var sourceNode = document.getElementById('domSource');
+  var targetNode = document.getElementById('domTarget');
+  var html = sourceNode.innerHTML;
+  targetNode.innerHTML = '';
+
+  // test appendChildren
+  os.appendChildren(sourceNode, targetNode);
+  assertEquals(html, targetNode.innerHTML);
+
+  // test removeChildren
+  os.removeChildren(targetNode);
+  assertEquals(0, targetNode.childNodes.length);
+
+  // test replaceNode
+  var child = document.createElement('p');
+  sourceNode.appendChild(child);
+  os.replaceNode(child, document.createElement('div'));
+  assertEquals('DIV', sourceNode.firstChild.tagName);
+}
+
+/**
+ * Unit test for createPropertyGetter
+ */
+function testGetPropertyGetterName() {
+  assertEquals('getFoo', os.getPropertyGetterName('foo'));
+  assertEquals('getFooBar', os.getPropertyGetterName('fooBar'));
+}
+
+/**
+ * Unit test for convertConstantToCamelCase.
+ */
+function testConvertToCamelCase() {
+  assertEquals('foo', os.convertToCamelCase('FOO'));
+  assertEquals('fooBar', os.convertToCamelCase('FOO_BAR'));
+  assertEquals('fooBarBaz', os.convertToCamelCase('FOO_BAR__BAZ'));
+}


Reply via email to