1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/json-tck/src/main/java/org/netbeans/html/json/tck/KnockoutTCK.java Tue Aug 26 18:13:30 2014 +0200
1.3 @@ -0,0 +1,141 @@
1.4 +/**
1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 + *
1.7 + * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
1.8 + *
1.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
1.10 + * Other names may be trademarks of their respective owners.
1.11 + *
1.12 + * The contents of this file are subject to the terms of either the GNU
1.13 + * General Public License Version 2 only ("GPL") or the Common
1.14 + * Development and Distribution License("CDDL") (collectively, the
1.15 + * "License"). You may not use this file except in compliance with the
1.16 + * License. You can obtain a copy of the License at
1.17 + * http://www.netbeans.org/cddl-gplv2.html
1.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
1.19 + * specific language governing permissions and limitations under the
1.20 + * License. When distributing the software, include this License Header
1.21 + * Notice in each file and include the License file at
1.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
1.23 + * particular file as subject to the "Classpath" exception as provided
1.24 + * by Oracle in the GPL Version 2 section of the License file that
1.25 + * accompanied this code. If applicable, add the following below the
1.26 + * License Header, with the fields enclosed by brackets [] replaced by
1.27 + * your own identifying information:
1.28 + * "Portions Copyrighted [year] [name of copyright owner]"
1.29 + *
1.30 + * Contributor(s):
1.31 + *
1.32 + * The Original Software is NetBeans. The Initial Developer of the Original
1.33 + * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
1.34 + *
1.35 + * If you wish your version of this file to be governed by only the CDDL
1.36 + * or only the GPL Version 2, indicate your decision by adding
1.37 + * "[Contributor] elects to include this software in this distribution
1.38 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
1.39 + * single choice of license, a recipient has the option to distribute
1.40 + * your version of this file under either the CDDL, the GPL Version 2 or
1.41 + * to extend the choice of license to its licensees as provided above.
1.42 + * However, if you add GPL Version 2 code and therefore, elected the GPL
1.43 + * Version 2 license, then the option applies only if the new code is
1.44 + * made subject to such option by the copyright holder.
1.45 + */
1.46 +package org.netbeans.html.json.tck;
1.47 +
1.48 +import java.net.URI;
1.49 +import java.util.Map;
1.50 +import net.java.html.BrwsrCtx;
1.51 +import net.java.html.json.tests.ConvertTypesTest;
1.52 +import net.java.html.json.tests.JSONTest;
1.53 +import net.java.html.json.tests.KnockoutTest;
1.54 +import net.java.html.json.tests.MinesTest;
1.55 +import net.java.html.json.tests.OperationsTest;
1.56 +import net.java.html.json.tests.Utils;
1.57 +import net.java.html.json.tests.WebSocketTest;
1.58 +import org.netbeans.html.context.spi.Contexts.Builder;
1.59 +import org.openide.util.lookup.ServiceProvider;
1.60 +
1.61 +/** Entry point for providers of different HTML binding technologies (like
1.62 + * Knockout.js in JavaFX's WebView). Sample usage:
1.63 + *
1.64 +<pre>
1.65 +{@link ServiceProvider @ServiceProvider}(service = KnockoutTCK.class)
1.66 +public final class MyKnockoutBindingTest extends KnockoutTCK {
1.67 + {@link Override @Override}
1.68 + protected BrwsrCtx createContext() {
1.69 + // use {@link Builder}.{@link Builder#build() build}();
1.70 + }
1.71 +
1.72 + {@code @}{@link org.testng.annotations.Factory} public static Object[] create() {
1.73 + return VMTest.newTests().withClasses({@link KnockoutTCK#testClasses}()).build();
1.74 + }
1.75 +}
1.76 + * </pre>
1.77 + *
1.78 + * @author Jaroslav Tulach
1.79 + */
1.80 +public abstract class KnockoutTCK {
1.81 + protected KnockoutTCK() {
1.82 + Utils.registerTCK(this);
1.83 + }
1.84 +
1.85 + /** Implement to create new context for the test.
1.86 + * Use {@link Builder} to set context for your technology up.
1.87 + * @return the final context for the test
1.88 + */
1.89 + public abstract BrwsrCtx createContext();
1.90 +
1.91 + /** Create a JSON object as seen by the technology
1.92 + * @param values mapping from names to values of properties
1.93 + * @return the JSON object with filled in values
1.94 + */
1.95 + public abstract Object createJSON(Map<String,Object> values);
1.96 +
1.97 + /** Executes script in the context of current window
1.98 + *
1.99 + * @param script the JavaScript code to execute
1.100 + * @param arguments arguments sent to the script (can be referenced as <code>arguments[0]</code>)
1.101 + * @return the output of the execution
1.102 + */
1.103 + public abstract Object executeScript(String script, Object[] arguments);
1.104 +
1.105 + /** Creates a URL which later returns content with given
1.106 + * <code>mimeType</code> and <code>content</code>. The
1.107 + * content may be processed by the provided <code>parameters</code>.
1.108 + *
1.109 + * @param content what should be available on the URL. Can contain <code>$0</code>
1.110 + * <code>$1</code> to reference <code>parameters</code> by their position
1.111 + * @param mimeType the type of the resource
1.112 + * @param parameters names of parameters as reference by <code>content</code>
1.113 + * @return URI the test can connect to to obtain the (processed) content
1.114 + */
1.115 + public abstract URI prepareURL(String content, String mimeType, String[] parameters);
1.116 +
1.117 + /** Gives you list of classes included in the TCK. Their test methods
1.118 + * are annotated by {@link KOTest} annotation. The methods are public
1.119 + * instance methods that take no arguments.
1.120 + *
1.121 + * @return classes with methods annotated by {@link KOTest} annotation
1.122 + */
1.123 + protected static Class<?>[] testClasses() {
1.124 + return new Class[] {
1.125 + ConvertTypesTest.class,
1.126 + JSONTest.class,
1.127 + KnockoutTest.class,
1.128 + MinesTest.class,
1.129 + OperationsTest.class,
1.130 + WebSocketTest.class
1.131 + };
1.132 + }
1.133 +
1.134 + /** Some implementations cannot fully support web sockets and fail.
1.135 + *
1.136 + * @return true, if UnsupportedOperationException reported from a web
1.137 + * socket open operation is acceptable reply
1.138 + */
1.139 + public boolean canFailWebSocketTest() {
1.140 + return false;
1.141 + }
1.142 +
1.143 +
1.144 +}