public VResult[] check(VObject object) { XModelObject o = ((VObjectImpl) object).getModelObject(); String paramName = o.getAttributeValue("param-name"); if (paramName == null) return null; XModelObject parent = o.getParent(); if (parent == null || !"WebAppServlet".equals(parent.getModelEntity().getName())) { return null; } if (!paramName.equals("config") && !paramName.startsWith("config/")) return null; String value = o.getAttributeValue("param-value"); if (value == null || value.length() == 0) return null; XModel model = getXModel(object); XModelObject webRoot = model == null ? null : model.getByPath("FileSystems/WEB-ROOT"); if (webRoot == null) return null; StringTokenizer st = new StringTokenizer(value, ","); while (st.hasMoreTokens()) { String path = st.nextToken().trim(); if (path.length() == 0) continue; XModelObject fc = XModelImpl.getByRelativePath(model, path); if (fc == null) { return fire(object, "config.exists", "param-value", path); } String path2 = path.startsWith("/") ? path.substring(1) : path; XModelObject fc2 = webRoot.getChildByPath(path2); if (fc2 == null) { return fire(object, "config.exists", "param-value", path); } if (!fc2.getModelEntity().getName().startsWith("StrutsConfig")) { return fire(object, "config.valid", "param-value", path); } } return null; }
void doAttributeTest(XModel model, String testName) { IFile f = project.getFile(new Path("/testCases.xml")); ArrayList<TestDescription> tests = new TestDescriptionFactory(f).getTestDescriptions(testName); System.out.println(testName + " " + (tests == null ? -1 : tests.size())); StringBuilder sb = new StringBuilder(); int errorCount = 0; if (tests != null) for (int i = 0; i < tests.size(); i++) { TestDescription t = tests.get(i); String path = t.getProperty("path"); XModelObject o = model.getByPath(path); if (o == null) { sb.append("Cannot find object at " + path).append("\n"); errorCount++; continue; } String attribute = t.getProperty("attributeName"); if (attribute == null) { sb.append("Attribute name is required for this test " + path).append("\n"); errorCount++; continue; } if (o.getModelEntity().getAttribute(attribute) == null) { sb.append("Attribute " + attribute + " is not found in object " + path).append("\n"); errorCount++; continue; } String testValue = t.getProperty("attributeValue"); String realValue = o.getAttributeValue(attribute); if (realValue == null || !realValue.equals(testValue)) { sb.append( "Attribute " + attribute + " in object " + path + " has unexpected value '" + realValue + "'") .append("\n"); errorCount++; continue; } } assertTrue(sb.toString(), errorCount == 0); }