Changeset 6427 in josm
- Timestamp:
- 2013-11-30T22:06:02+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r6415 r6427 5 5 6 6 import java.io.InputStreamReader; 7 import java.lang.reflect.InvocationTargetException;8 import java.lang.reflect.Method;9 7 import java.util.ArrayList; 10 8 import java.util.Arrays; … … 58 56 // fake country/state to not get errors on holidays 59 57 ENGINE.eval("var nominatiomJSON = {address: {state: 'Bayern', country_code: 'de'}};"); 60 ENGINE.eval("var oh = function (value, mode) {return new opening_hours(value, nominatiomJSON, mode);};"); 58 ENGINE.eval("" + 59 "var oh = function (value, mode) {" + 60 " try {" + 61 " var r= new opening_hours(value, nominatiomJSON, mode);" + 62 " r.getErrors = function() {return [];};" + 63 " return r;" + 64 " } catch(err) {" + 65 " return {" + 66 " getWarnings: function() {return [];}," + 67 " getErrors: function() {return [err.toString()]}" + 68 " };" + 69 " }" + 70 "};"); 61 71 } else { 62 72 Main.warn("Unable to initialize OpeningHourTest because no JavaScript engine has been found"); … … 78 88 79 89 @SuppressWarnings("unchecked") 80 protected List<Object> getList(Object obj) {90 protected List<Object> getList(Object obj) throws ScriptException, NoSuchMethodException { 81 91 if (obj == null || "".equals(obj)) { 82 92 return Arrays.asList(); 83 93 } else if (obj instanceof String) { 84 final Object[] strings = ((String) obj).split("\\ n");94 final Object[] strings = ((String) obj).split("\\\\n"); 85 95 return Arrays.asList(strings); 86 96 } else if (obj instanceof List) { 87 97 return (List<Object>) obj; 88 } else if ("sun.org.mozilla.javascript.internal.NativeArray".equals(obj.getClass().getName())) {89 List<Object> list = new ArrayList<Object>();90 try {91 Method getIds = obj.getClass().getMethod("getIds");92 Method get = obj.getClass().getMethod("get", long.class);93 Object[] ids = (Object[]) getIds.invoke(obj);94 for (Object id : ids) {95 list.add(get.invoke(obj, id));96 }97 } catch (NoSuchMethodException e) {98 Main.error("Unable to run OpeningHourTest because of NoSuchMethodException by reflection: "+e.getMessage());99 } catch (IllegalArgumentException e) {100 Main.error("Unable to run OpeningHourTest because of IllegalArgumentException by reflection: "+e.getMessage());101 } catch (IllegalAccessException e) {102 Main.error("Unable to run OpeningHourTest because of IllegalAccessException by reflection: "+e.getMessage());103 } catch (InvocationTargetException e) {104 Main.error("Unable to run OpeningHourTest because of InvocationTargetException by reflection: "+e.getMessage());105 }106 return list;107 98 } else { 108 throw new IllegalArgumentException("Not expecting class " + obj.getClass()); 99 // recursively call getList() with argument converted to newline-separated string 100 return getList(((Invocable) ENGINE).invokeMethod(obj, "join", "\\n")); 109 101 } 110 102 } … … 168 160 Main.debug(e.getMessage()); 169 161 } 162 for (final Object i : getList(((Invocable) ENGINE).invokeMethod(r, "getErrors"))) { 163 errors.add(new OpeningHoursTestError(key + " - " + i.toString().trim(), Severity.ERROR, prettifiedValue)); 164 } 170 165 for (final Object i : getList(((Invocable) ENGINE).invokeMethod(r, "getWarnings"))) { 171 errors.add(new OpeningHoursTestError(i.toString() , Severity.WARNING, prettifiedValue));166 errors.add(new OpeningHoursTestError(i.toString().trim(), Severity.WARNING, prettifiedValue)); 172 167 } 173 168 return errors; 174 } catch (ScriptException ex) {175 final String message = ex.getMessage()176 .replaceAll("[^:]*Exception: ", key+" - ")177 .replaceAll("\\(<Unknown source.*", "")178 .trim();179 return Arrays.asList(new OpeningHoursTestError(message, Severity.ERROR));180 169 } catch (final Exception ex) { 181 170 throw new RuntimeException(ex);
Note:
See TracChangeset
for help on using the changeset viewer.