01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.testtools;
19:
20: import junit.framework.TestResult;
21: import junit.framework.AssertionFailedError;
22:
23: import org.w3c.dom.Element;
24: import org.ofbiz.entity.GenericDelegator;
25: import org.ofbiz.entity.util.EntityDataAssert;
26: import org.ofbiz.base.util.UtilValidate;
27: import org.ofbiz.base.util.Debug;
28: import org.ofbiz.base.location.FlexibleLocation;
29:
30: import java.util.List;
31: import java.util.ArrayList;
32: import java.util.Iterator;
33: import java.net.URL;
34:
35: public class EntityXmlAssertTest extends TestCaseBase {
36:
37: public static final String module = ServiceTest.class.getName();
38:
39: protected String entityXmlUrlString;
40:
41: /**
42: * @param modelTestSuite
43: */
44: public EntityXmlAssertTest(String caseName,
45: ModelTestSuite modelTestSuite, Element mainElement) {
46: super (caseName, modelTestSuite);
47: this .entityXmlUrlString = mainElement
48: .getAttribute("entity-xml-url");
49: }
50:
51: public int countTestCases() {
52: int testCaseCount = 0;
53: try {
54: URL entityXmlURL = FlexibleLocation
55: .resolveLocation(entityXmlUrlString);
56: List checkValueList = modelTestSuite.getDelegator()
57: .readXmlDocument(entityXmlURL);
58: testCaseCount = checkValueList.size();
59: } catch (Exception e) {
60: Debug.logError(e, "Error getting test case count", module);
61: }
62: return testCaseCount;
63: }
64:
65: public void run(TestResult result) {
66: result.startTest(this );
67:
68: try {
69: URL entityXmlURL = FlexibleLocation
70: .resolveLocation(entityXmlUrlString);
71: GenericDelegator delegator = modelTestSuite.getDelegator();
72: List errorMessages = new ArrayList();
73:
74: EntityDataAssert.assertData(entityXmlURL, delegator,
75: errorMessages);
76:
77: if (UtilValidate.isNotEmpty(errorMessages)) {
78: Iterator failureIterator = errorMessages.iterator();
79: while (failureIterator.hasNext()) {
80: String failureMessage = (String) failureIterator
81: .next();
82: result.addFailure(this , new AssertionFailedError(
83: failureMessage));
84: }
85: }
86: } catch (Exception e) {
87: result.addError(this, e);
88: }
89:
90: result.endTest(this);
91: }
92: }
|