public abstract class KnockoutTCK
extends java.lang.Object
Fn.Presenter
or any other system that understands
JavaScriptBody
annotation. The KnockoutTCK
is an extension over JavaScriptTCK
- the headless test
compatibility kit. Once the headless functionality works fine,
it is time to test the visual aspects - at the end the goal is to run visual
Java applications in browser, right?
The KnockoutTCK
shall be subclassesed and abstract
methods
of the class implemented to provide the necessary environment for execution.
A typical way to obtain all the methods to be tested for each of KnockoutTCK.testClasses()
is:
private static void seekKOTests(Class
<?> c,List
<Object
> res) throwsClassNotFoundException
{Class
<? extendsAnnotation
> koTest = c.getClassLoader().loadClass(KOTest
.class.getName()). asSubclass(Annotation
.class); for (Method
m : c.getMethods()) { if (m.getAnnotation(koTest) != null) { if (skipUnsupported(m)) { continue; } res.add(new KOFx(browserContext, m)); } } }
The visual tests interact with browser environment and perform asynchronous network calls. That has two consequences:
KnockoutTCK.prepareWebResource(java.lang.String, java.lang.String, java.lang.String[])
call -
return URL which the test later connects to
InterruptedException
- wait a while
and call the test method again (while keeping the instance and its internal state)
The typical way to execute the visual tests requires one to perform something like:
@e.g. initialize the test instance, run the test method. If it yields anOverride
public synchronized void run() { boolean notify = true;Closeable
a =Fn
.activate(p); try { if (inst == null) { inst = m.getDeclaringClass().newInstance(); } result = m.invoke(inst); if (result == null) { result = this; } } catch (InvocationTargetException
ex) {Throwable
r = ex.getTargetException(); if (r instanceofInterruptedException
) { if (count++ < 10000) { notify = false; try {Thread
.sleep(100); } catch (Exception
ex1) { // ignore and continue }Platform
.runLater(this); return; } } result = r; } catch (Exception
ex) { result = ex; } finally { if (notify) { notifyAll(); } try { a.close(); } catch (IOException
ex) { throw newIllegalStateException
(ex); } } }
InterruptedException
, run the test again. Should there be no success
in a fixed time, give up and fail the test. Succeed otherwise.
This is more complicated than running headless JavaScriptTCK
tests,
but so is the behavior of typical applications in the browser with access to
network.Modifier | Constructor and Description |
---|---|
protected |
KnockoutTCK() |
Modifier and Type | Method and Description |
---|---|
boolean |
canFailWebSocketTest()
Some implementations cannot fully support web sockets and fail.
|
abstract BrwsrCtx |
createContext()
Implement to create new context for the test.
|
abstract java.lang.Object |
createJSON(java.util.Map<java.lang.String,java.lang.Object> values)
Create a JSON object as seen by the technology
|
abstract java.lang.Object |
executeScript(java.lang.String script,
java.lang.Object[] arguments)
Executes script in the context of current window
|
java.lang.String |
prepareWebResource(java.lang.String content,
java.lang.String mimeType,
java.lang.String[] parameters)
Creates a URL which later returns content with given
mimeType and content . |
boolean |
scheduleLater(int delay,
java.lang.Runnable r)
Schedules the given runnable to run later.
|
protected static java.lang.Class<?>[] |
testClasses()
Gives you list of classes included in the TCK.
|
public abstract BrwsrCtx createContext()
Contexts.Builder
to set context for your technology up.public abstract java.lang.Object createJSON(java.util.Map<java.lang.String,java.lang.Object> values)
values
- mapping from names to values of propertiespublic abstract java.lang.Object executeScript(java.lang.String script, java.lang.Object[] arguments)
script
- the JavaScript code to executearguments
- arguments sent to the script (can be referenced as arguments[0]
)public java.lang.String prepareWebResource(java.lang.String content, java.lang.String mimeType, java.lang.String[] parameters)
mimeType
and content
. The
content may be processed by the provided parameters
.content
- what should be available on the URL. Can contain $0
$1
to reference parameters
by their positionmimeType
- the type of the resourceparameters
- names of parameters as reference by content
protected static java.lang.Class<?>[] testClasses()
KOTest
annotation. The methods are public
instance methods that take no arguments.KOTest
annotationpublic boolean canFailWebSocketTest()
public boolean scheduleLater(int delay, java.lang.Runnable r)
delay
- the delay in millisecondsr
- the runnable to runtrue
if the runnable was really scheduled,
false
otherwiseCopyright © 2021 The Apache Software Foundation. All rights reserved.