001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.schema.testsuite;
021:
022: import junit.framework.TestCase;
023: import org.apache.axiom.om.OMAbstractFactory;
024: import org.apache.axiom.om.OMElement;
025: import org.apache.axiom.om.OMFactory;
026: import org.apache.axiom.om.OMNamespace;
027: import services.echo.types.BookInformation;
028:
029: public class AbstractTest extends TestCase {
030:
031: protected OMElement getOMElement() {
032: OMFactory fac = OMAbstractFactory.getSOAP12Factory();
033: OMNamespace omNamespace = fac.createOMNamespace(
034: "http://test.ws02.com", "ns1");
035: OMElement omElement = fac.createOMElement("TestValue",
036: omNamespace);
037: omElement.addChild(fac.createOMText("testString"));
038: return omElement;
039: }
040:
041: protected boolean isOMElementsEqual(OMElement omElement1,
042: OMElement omElement2) {
043: boolean isEqual = false;
044: if ((omElement1 == null) || (omElement2 == null)) {
045: isEqual = (omElement1 == omElement2);
046: } else {
047: isEqual = omElement1.getLocalName().equals(
048: omElement2.getLocalName());
049: }
050: return isEqual;
051: }
052:
053: public void testMethod() {
054: // dummy test method
055: }
056:
057: protected boolean assertArrayEqual(Object[] objectArray1,
058: Object[] objectArray2) {
059: boolean isEqual = false;
060: if ((objectArray1 == null) || (objectArray2 == null)) {
061: isEqual = (objectArray1 == objectArray2);
062: } else {
063: // i.e both are not null
064: if (objectArray1.length == objectArray2.length) {
065: isEqual = true;
066: for (int i = 0; i < objectArray1.length; i++) {
067: if (!isObjectContains(objectArray2, objectArray1[i])) {
068: isEqual = false;
069: break;
070: }
071: }
072: }
073: }
074: return isEqual;
075: }
076:
077: protected boolean isObjectContains(Object[] objectArray,
078: Object object) {
079: boolean isContain = false;
080: for (int i = 0; i < objectArray.length; i++) {
081: if ((objectArray[i] == null) || (object == null)) {
082: isContain = (objectArray[i] == object);
083: } else {
084: if (object instanceof BookInformation) {
085: isContain = isBookInformationObjectsEquals(
086: (BookInformation) objectArray[i],
087: (BookInformation) object);
088: } else if (object instanceof OMElement) {
089: isContain = isOMElementsEqual(
090: (OMElement) objectArray[i],
091: (OMElement) object);
092: } else {
093: isContain = objectArray[i].equals(object);
094: }
095: }
096: if (isContain) {
097: break;
098: }
099: }
100: return isContain;
101: }
102:
103: protected boolean isBookInformationObjectsEquals(
104: BookInformation bookInformation1,
105: BookInformation bookInformation2) {
106: boolean isEqual;
107: if ((bookInformation1 == null) || (bookInformation2 == null)) {
108: isEqual = (bookInformation1 == bookInformation2);
109: } else {
110: isEqual = bookInformation1.getType().equals(
111: bookInformation2.getType())
112: && bookInformation1.getTitle().equals(
113: bookInformation2.getTitle())
114: && bookInformation1.getIsbn().equals(
115: bookInformation2.getIsbn());
116: }
117: return isEqual;
118: }
119:
120: protected BookInformation getBookInformation() {
121: BookInformation bookInformation = new BookInformation();
122: bookInformation.setType("test");
123: bookInformation.setTitle("test");
124: bookInformation.setIsbn("test");
125: return bookInformation;
126: }
127:
128: }
|