public void testPaths() { IModelNature n = EclipseResourceUtil.getModelNature(project); String testName = "JSFModelTest:testPaths"; 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 = n.getModel().getByPath(path); if (o == null) { sb.append(path).append("\n"); errorCount++; } } assertTrue( "Cannot find objects at " + errorCount + " paths\n" + sb.toString(), errorCount == 0); testName = "JSFModelTest:testPaths:attribute"; doAttributeTest(n.getModel(), testName); }
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); }