google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

Constants with map are wrong translated #32

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using gwt-test-utils-0.27

// Message class
import java.util.Map;
import com.google.gwt.i18n.client.Constants;
public interface MessageWithMap extends Constants{
    @DefaultStringMapValue( { "aa","bb","ss","dd" })
    Map<String,String> map();
}
// Optional properties file MessageWithMap.properties, it override annotation, 
should work without it too.
aa=bb
ss=tt
map=aa,ss
// Test case 
import org.junit.Test;
import com.google.gwt.core.client.GWT;
import com.octo.gwt.test.GwtTest;

public class MessageJunit extends GwtTest{
    @Test
    public void testConstant(){
        MessageWithMap message = GWT.create(MessageWithMap.class);
        message.map();
    }
}

What is the expected output? What do you see instead?
Caused by: java.lang.NoSuchMethodException: MessageWithMap.aa()
    at java.lang.Class.getMethod(Class.java:1605)
    at com.octo.gwt.test.internal.utils.i18n.ConstantsInvocationHandler.extractDefaultValue(ConstantsInvocationHandler.java:69)
    at com.octo.gwt.test.internal.utils.i18n.LocalizableResourcesInvocationHandler.invoke(LocalizableResourcesInvocationHandler.java:42)
    ... 27 more

What version of the product are you using? On what operating system?
gwt-test-utils-0.27
slackware linux

Please provide any additional information below.

Current implementation does not support map without method. If method is not 
found (aa or bb) string map should be used:
aa=bb
ss=tt

Original issue reported on code.google.com by Andrzej....@gmail.com on 5 Apr 2011 at 11:03

GoogleCodeExporter commented 9 years ago
Possible solution.
Source code which I use is:
http://code.google.com/p/gwt-test-utils/source/browse/src/framework/trunk/gwt-te
st-utils/src/main/java/com/octo/gwt/test/internal/patcher/tools/i18n/ConstantsIn
vocationHandler.java?spec=svn482&r=482
Possible solution (but better is to check first properties.get(methodName) 
before calling clazz.getMethod(methodName)):

for (int i = 0; i < v.length; i++) {
                                String methodName = v[i];
try{
                                Method correspondingKeyMethod = clazz.getMethod(methodName);
                                if (correspondingKeyMethod == null) {
                                        throw new RuntimeException("Cannot find method '" + methodName + "' in class [" + clazz.getName() + "]");
                                }

                                result.put(methodName, invoke(null, correspondingKeyMethod, null));
}catch(NoSuchMethodException exp){
result.put(methodName, properties.get(methodName));
}
}

Original comment by Andrzej....@gmail.com on 5 Apr 2011 at 11:20

GoogleCodeExporter commented 9 years ago
I really don't know what I've smoked when implementing the 
@DefaultStringMapValue behaviour.

Thank you for this report, I'm fixing it by following the behaviour explained 
here  : 
http://code.google.com/intl/fr-FR/webtoolkit/doc/latest/DevGuideI18nConstants.ht
ml

Original comment by gael.laz...@gmail.com on 5 Apr 2011 at 4:20

GoogleCodeExporter commented 9 years ago
This is now fixed on trunk :-)

Be carefull, a lot of modification have been done for the coming release. If 
you checkout the trunk, be aware you will need to :

1) provide a META-INF/gwt-test-utils.properties file with at least a 
'module-file' configured (for example in gwt-test-utils : 
com/octo/gwt/test/GwtTestUtils.gwt.xml = module-file)

2) implement the GwtTest.getModuleName() method, just like in GWTTestCase.

It will be documented soon in the official wiki pages.

Could you give it a try to validate the issue has been fix with my 
modifications ?

Original comment by gael.laz...@gmail.com on 5 Apr 2011 at 4:26

GoogleCodeExporter commented 9 years ago
Hello,

I tested with current code and it works. Many thanks.

/ajozwik

Original comment by Andrzej....@gmail.com on 6 Apr 2011 at 10:30

GoogleCodeExporter commented 9 years ago

Original comment by gael.laz...@gmail.com on 9 Jun 2011 at 3:30