-
Notifications
You must be signed in to change notification settings - Fork 2
Basic Uses
You can create and use JS Object and them pass they to the kona methods
var obj = {
"name": "Ear",
"age":19
};
var str = JSON.stringify(obj); //this is a String.
Diferents ways to create objects, you can use JS Object or Java Object, for example
var test = function() {
var obj = kona.obj();
obj.put("name","obj1");
model.insert(obj);
var obj2 = new Object();
obj2.name = "obj2";
model.insert(obj2);
var obj3 = {
name : "obj3"
};
model.insert(obj3);
};
#Basic Uses
##How to Log
Yo can log all kond of stuff, for example
log("This is a common log");
log.err("Hi this is han error");
log.info("This is han info log");
log.war("This is han warining log");
If you use the "Debug" Button you can see the logs for the test method, and web yous clientes acces to the resources then the logs area stored and you can see them in the Log View
and the result is something like this
//Use log('text') to log
This is a common log
[ERROR] Wed Jun 18 2014 01:22:21 GMT-0300 (UYT)Hi this is han error
[INFO] Wed Jun 18 2014 01:22:21 GMT-0300 (UYT)This is han info log
[WAR] Wed Jun 18 2014 01:22:21 GMT-0300 (UYT)This is han warining log
Cada api debe implementar el metodo test para poder ser utiliada en la test suite. El metodo test es un test unitario del recurso o metodo que se esta programando.
Se considera que un test es exitoso si no contiene error al terminar su ejecucion, alguna funciones de utilidad son:
assert(p, q)
notAssert(p, q)
Ademas se pueden hacer cosas como
if (somethingStrange()){
kona.error("This is bad");
}
Consideramos una buena practica que todos los metodos tengan su test, auque deben tener cuidado de no insertar datos en cada test (queda a criterio del desarrollador)
You can create as ANY WAY object is created in java, for communication between the script and utlize kona.js usually an object of type KonaDO compliant json format with other properties.
The following are valid
var obj = kona.obj();
var obj = new ArrayList<KonaDO>(); //o
var obj = kona.list();
Cada request a un resource viene con la siguiente estructura, por ejemplo
req.header.get("some_header")
req.params.get("some_param")
req.body.get("field");
var get = function(req) {
return req.headers.get("asd");
};
var get = function(req) {
return req.params.get("asd");
};
Para definir librerias y utlizar en cualquier resource/job o otra libreria
Guardar el codigo como Library
Por ejemplo:
var util = function(){
return (new Date()).getTime();
};
var test = function(){
return util();
}
y lo Guardamos por ejemplo con el nombre timeUtil
Luego desde cualquier funcion simplemente lo incluimos al comienzo del script (es importante que sea al principio)
include("timeUtil");
var test = function(){
return timeUtil.util();
};