0

WARNING: id-to-uuid-prefix deprecated

asked 2011-10-10 05:26:05 +0800

digulla gravatar image digulla
502 4

I'm trying to set up unit tests as described here: ZK Developer's Guide/ZK in Depth/Unit Test/Environment Setup

Alas, when I start the project, I get this warning:

Oct 10, 2011 12:14:04 PM org.zkoss.zk.ui.sys.ConfigParser parseDesktopConfig:570
WARNING: id-to-uuid-prefix deprecated

Can you a) tell me how to fix the warning and b) update the documentation, please?

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2011-10-20 05:14:33 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

updated 2011-10-20 05:22:51 +0800

The URL is obsolete (ZK Developer's Guide is for ZK 3.*). Please refer to http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/Testing.

link publish delete flag offensive edit

answered 2011-10-24 10:07:00 +0800

digulla gravatar image digulla
502 4

Thanks, using my own IdGenerator does work.

How do I enable this generator only for tests? I have found no way to use conditional elements in zk.xml.

link publish delete flag offensive edit

answered 2011-10-24 20:12:21 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

It is done by given two configuration files: one for production, and the other for testing. Please refer to ZK Configuration Reference for details.

link publish delete flag offensive edit

answered 2011-10-25 13:54:29 +0800

iantsai gravatar image iantsai
2755 1

I have built a ConsistUuidGenerator for testing purpose, this might ease the pain that you have while doing auto testing:

ZKFiddle-Link

ConsistentIdGenerator.java
package j1pj6m23$v3;

import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicInteger;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.ext.Scope;
import org.zkoss.zk.ui.sys.IdGenerator;
/**
*
* @author Ian Tsai (zanyking)
*
*/
public class ConsistentIdGenerator implements IdGenerator {
private static final AtomicInteger DESKTOP_ID_AINT = new AtomicInteger();
private final IdGenerator innerIdGenerator;
/**
* key="USE_TEST_COMP_UUID_GENERATOR", valueType=boolean
*/
public ConsistentIdGenerator(){
String useTesting = System.getProperty("USE_TEST_COMP_UUID_GENERATOR");
Boolean isUnderTesting = Boolean.FALSE;
if(useTesting!=null){
try{
isUnderTesting = Boolean.parseBoolean(useTesting);
}catch(Exception e){
//ignore, nothing need to do.
}
}
if(isUnderTesting){
innerIdGenerator = new TestingIdGenerator();
}else{
innerIdGenerator = new ProductionIdGenerator();
}
}

public String nextComponentUuid(Desktop arg0, Component arg1) {
return innerIdGenerator.nextComponentUuid(arg0, arg1);
}

public String nextDesktopId(Desktop arg0) {
return innerIdGenerator.nextDesktopId(arg0);
}

public String nextPageUuid(Page arg0) {
return innerIdGenerator.nextPageUuid(arg0);
}

private static final String CHAR = "0123456789abcdefghijklmnopqrstuvwxyz";
private static final char[] CHAR_ARR =CHAR.toCharArray();

private static String encodeRadix36(int in){
StringBuffer sb = new StringBuffer(4);
// almost impossible for a desktop to contain more than 10,000 components.
int inp = in,k,i;
do{
k = inp /CHAR_ARR.length;
i = inp % CHAR_ARR.length;
sb.append(CHAR_ARR[i]);
inp = k;
}
while(k>0);

return sb.reverse().toString();
}

private static int getAndIncrement(Scope scope, String key){
AtomicInteger aInt = (AtomicInteger) scope.getAttribute(key);
if (aInt == null) {
scope.setAttribute(key, aInt = new AtomicInteger());
}
int i = aInt.getAndIncrement();
return i;
}

/**
*
* @author Ian Tsai(ytsai1)
*
*/
static class ProductionIdGenerator implements IdGenerator{
private final static String ID_NUMBER = "zk_id_num";

public String nextComponentUuid(Desktop desktop, Component comp) {
String key = ID_NUMBER + comp.getClass().getSimpleName();
int i = getAndIncrement(desktop, key);
String compId = "zc_" + comp.getClass().getSimpleName() +"_"+ i;
return compId;
}
public String nextDesktopId(Desktop desktop) {
int i = DESKTOP_ID_AINT.getAndIncrement();
String dtid = "Desktop_" + i;
((javax.servlet.http.HttpServletResponse)Executions.getCurrent().getNativeResponse()).setHeader("Desktop", dtid);
return dtid;
}
public String nextPageUuid(Page page) {
return null;
}
}//end of class

/**
*
* @author Ian Tsai(ytsai1)
*
*/
static class TestingIdGenerator implements IdGenerator{
private static final String KEY_GENERIC_SHORT_NAME = "KEY_GENERIC_SHORT_NAME";
private final static String KEY_UUID_ATOMIC_INT = "KEY_UUID_ATOMIC_INT";
/*
* (non-Javadoc)
* @see org.zkoss.zk.ui.sys.IdGenerator#nextComponentUuid(org.zkoss.zk.ui.Desktop, org.zkoss.zk.ui.Component)
*/
public String nextComponentUuid(Desktop desktop, Component comp) {

Page page = comp.getPage();
Scope scope = page==null? desktop : page;
String pageUuid = page==null? "pseudo_page" : page.getUuid();

String prefix = enc(comp.getClass().getSimpleName(),
enc(pageUuid, "zc_", desktop, false), desktop, false);

String uuid = prefix + encodeRadix36(getAndIncrement(scope, KEY_UUID_ATOMIC_INT));

return uuid;
}

/*
* (non-Javadoc)
* @see org.zkoss.zk.ui.sys.IdGenerator#nextDesktopId(org.zkoss.zk.ui.Desktop)
*/
public String nextDesktopId(Desktop desktop) {
int i = DESKTOP_ID_AINT.getAndIncrement();
String dtid = "Desktop_" + i;
((javax.servlet.http.HttpServletResponse)Executions.getCurrent().getNativeResponse()).setHeader("Desktop", dtid);
return dtid;
}
/*
* (non-Javadoc)
* @see org.zkoss.zk.ui.sys.IdGenerator#nextPageUuid(org.zkoss.zk.ui.Page)
*/
public String nextPageUuid(Page page) {
return null;
}
/**
*
* @param name
* @param prefix
* @param scope
* @return
*/
private static String enc(String name, String prefix, Scope scope, boolean disable){
if(disable){
return prefix+name+"_";
}
StatefulIdEncoder idEncoder = (StatefulIdEncoder) scope.getAttribute(KEY_GENERIC_SHORT_NAME);

if (idEncoder == null) {
scope.setAttribute(KEY_GENERIC_SHORT_NAME,
idEncoder = new StatefulIdEncoder());
}
return prefix+idEncoder.encode(name)+"_";
}

/**
* @author ytsai1
*/
private static class StatefulIdEncoder{
final LinkedList<String> store = new LinkedList<String>();
/**
* @param name
* @return
*/
public String encode(String name){
if(name==null || name.isEmpty())
throw new IllegalArgumentException("StatefulIdEncoder can't encode a null or empty String: "+name);
int counter = 0;
int idx = -1;
for(String temp : store){
if(temp.equals(name)){
idx = counter;
break;
}
counter++;
}
if(idx<0){//if not exist
store.add(name);
return encodeRadix36(counter);
}else{// it's exist
return encodeRadix36(idx);
}
}
}
}//end of class...
}



index.zul
<zk>
<window border="normal" title="hello" >

<div>It's impossible to demonstrat the effect in Fiddle, please copy the code to your project and use it.</div>



</window>
</zk>

link publish delete flag offensive edit

answered 2011-10-26 02:59:11 +0800

digulla gravatar image digulla
502 4

Thanks, that code looks exactly like what I've been looking for!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-10-10 05:26:05 +0800

Seen: 563 times

Last updated: Oct 26 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More