org.apache.juddi.v3.tck.TckValidator Maven / Gradle / Ivy
/*
* Copyright 2001-2009 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.v3.tck;
/**
* @author Jeff Faath
* @author Kurt T Stam
* @author Tom Cunningham
*/
import java.util.Arrays;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBElement;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.XMLUnit;
import org.uddi.api_v3.BindingTemplate;
import org.uddi.api_v3.BindingTemplates;
import org.uddi.api_v3.CategoryBag;
import org.uddi.api_v3.Contact;
import org.uddi.api_v3.Contacts;
import org.uddi.api_v3.Description;
import org.uddi.api_v3.DiscoveryURL;
import org.uddi.api_v3.DiscoveryURLs;
import org.uddi.api_v3.HostingRedirector;
import org.uddi.api_v3.InstanceDetails;
import org.uddi.api_v3.KeyedReference;
import org.uddi.api_v3.Name;
import org.uddi.api_v3.OverviewDoc;
import org.uddi.api_v3.OverviewURL;
import org.uddi.api_v3.PersonName;
import org.uddi.api_v3.TModelInstanceDetails;
import org.uddi.api_v3.TModelInstanceInfo;
import org.w3._2000._09.xmldsig_.CanonicalizationMethodType;
import org.w3._2000._09.xmldsig_.DigestMethodType;
import org.w3._2000._09.xmldsig_.KeyInfoType;
import org.w3._2000._09.xmldsig_.ObjectType;
import org.w3._2000._09.xmldsig_.ReferenceType;
import org.w3._2000._09.xmldsig_.SignatureMethodType;
import org.w3._2000._09.xmldsig_.SignatureType;
import org.w3._2000._09.xmldsig_.SignatureValueType;
import org.w3._2000._09.xmldsig_.SignedInfoType;
import org.w3._2000._09.xmldsig_.TransformType;
import org.w3._2000._09.xmldsig_.TransformsType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class TckValidator {
public static void checkNames(List names1, List names2) {
if (names1 == null || names2 == null) {
assertEquals(names1, names2);
return;
}
assertEquals(names1.size(), names2.size());
Iterator names1Itr = names1.iterator();
Iterator names2Itr = names2.iterator();
while (names1Itr.hasNext()) {
Name name1 = names1Itr.next();
Name name2 = names2Itr.next();
assertEquals(name1.getLang(), name2.getLang());
assertEquals(name1.getValue(), name2.getValue());
}
}
public static void checkDescriptions(List descriptions1, List descriptions2) {
if (descriptions1 == null || descriptions2 == null) {
assertEquals(descriptions1, descriptions2);
return;
}
assertEquals(descriptions1.size(), descriptions2.size());
Iterator descriptions1Itr = descriptions1.iterator();
Iterator descriptions2Itr = descriptions2.iterator();
while (descriptions1Itr.hasNext()) {
Description description1 = descriptions1Itr.next();
Description description2 = descriptions2Itr.next();
assertEquals(description1.getLang(), description2.getLang());
assertEquals(description1.getValue(), description2.getValue());
}
}
public static void checkDiscoveryUrls(DiscoveryURLs discs1, DiscoveryURLs discs2) {
if (discs1 == null || discs2 == null) {
assertEquals(discs1, discs2);
return;
}
List discList1 = discs1.getDiscoveryURL();
List discList2 = discs2.getDiscoveryURL();
if (discList1 == null || discList2 == null) {
assertEquals(discList1, discList2);
return;
}
assertEquals(discList1.size(), discList2.size());
Iterator discList1Itr = discList1.iterator();
Iterator discList2Itr = discList2.iterator();
while (discList1Itr.hasNext()) {
DiscoveryURL disc1 = discList1Itr.next();
DiscoveryURL disc2 = discList2Itr.next();
assertEquals(disc1.getUseType(), disc2.getUseType());
assertEquals(disc1.getValue(), disc2.getValue());
}
}
public static void checkSignatures(List sigs1, List sigs2) {
if (sigs1 == null || sigs2 == null) {
assertEquals(sigs1, sigs2);
return;
}
assertEquals(sigs1.size(), sigs2.size());
Iterator sigsList1Itr = sigs1.iterator();
Iterator sigsList2Itr = sigs2.iterator();
while (sigsList1Itr.hasNext()) {
SignatureType sig1 = sigsList1Itr.next();
SignatureType sig2 = sigsList2Itr.next();
assertEquals(sig1.getId(), sig2.getId());
checkKeyInfo(sig1.getKeyInfo(), sig2.getKeyInfo());
checkObjectType(sig1.getObject(), sig2.getObject());
checkSignatureValue(sig1.getSignatureValue(), sig2.getSignatureValue());
checkSignedInfo(sig1.getSignedInfo(), sig2.getSignedInfo());
}
}
public static void checkKeyInfo(KeyInfoType kit1, KeyInfoType kit2) {
if (kit1 == null || kit2 == null) {
assertEquals(kit1, kit2);
return;
}
assertEquals(kit1.getId(), kit2.getId());
DOMResult domResult1 = new DOMResult();
DOMResult domResult2 = new DOMResult();
JAXB.marshal(kit1, domResult1);
JAXB.marshal(kit2, domResult2);
Document doc1 = (Document)domResult1.getNode();
DOMSource domSource1 = new DOMSource(doc1.getDocumentElement());
Document doc2 = (Document)domResult2.getNode();
DOMSource domSource2 = new DOMSource(doc2.getDocumentElement());
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreWhitespace(true);
Diff diff = new Diff(domSource1, domSource2);
assertTrue("Key info elements should match", diff.similar());
}
public static void checkObjectType(List obj1List, List obj2List) {
if (obj1List == null || obj2List == null) {
assertEquals(obj1List, obj2List);
return;
}
assertEquals(obj1List.size(), obj2List.size());
Iterator objList1Itr = obj1List.iterator();
Iterator objList2Itr = obj2List.iterator();
while (objList1Itr.hasNext()) {
ObjectType obj1 = objList1Itr.next();
ObjectType obj2 = objList2Itr.next();
assertEquals(obj1.getEncoding(), obj2.getEncoding());
assertEquals(obj1.getId(), obj2.getId());
assertEquals(obj1.getMimeType(), obj2.getMimeType());
}
}
public static void checkSignatureValue(SignatureValueType sv1, SignatureValueType sv2) {
if (sv1 == null || sv2 == null) {
assertEquals(sv1, sv2);
return;
}
assertEquals(sv1.getId(), sv2.getId());
assertTrue(Arrays.equals(sv1.getValue(), sv2.getValue()));
}
public static void checkSignedInfo(SignedInfoType si1, SignedInfoType si2) {
if (si1 == null || si2 == null) {
assertEquals(si1, si2);
return;
}
assertEquals(si1.getId(), si2.getId());
checkCanonicalizationMethod(si1.getCanonicalizationMethod(), si2.getCanonicalizationMethod());
checkReference(si1.getReference(), si2.getReference());
checkSignatureMethod(si1.getSignatureMethod(), si2.getSignatureMethod());
}
public static void checkCanonicalizationMethod(CanonicalizationMethodType cm1, CanonicalizationMethodType cm2) {
if (cm1 == null || cm2 == null) {
assertEquals(cm1, cm2);
return;
}
assertEquals(cm1.getAlgorithm(), cm2.getAlgorithm());
}
public static void checkReference(List r1List, List r2List) {
if (r1List == null || r2List == null) {
assertEquals(r1List, r2List);
return;
}
assertEquals(r1List.size(), r2List.size());
Iterator rList1Itr = r1List.iterator();
Iterator rList2Itr = r2List.iterator();
while (rList1Itr.hasNext()) {
ReferenceType r1 = rList1Itr.next();
ReferenceType r2 = rList2Itr.next();
checkReference(r1, r2);
}
}
public static void checkReference(ReferenceType r1, ReferenceType r2) {
assertTrue(Arrays.equals(r1.getDigestValue(), r2.getDigestValue()));
assertEquals(r1.getId(), r2.getId());
assertEquals(r1.getType(), r2.getType());
assertEquals(r1.getURI(), r2.getURI());
checkDigestMethod(r1.getDigestMethod(), r2.getDigestMethod());
checkTransforms(r1.getTransforms(), r2.getTransforms());
}
public static void checkDigestMethod(DigestMethodType dm1, DigestMethodType dm2) {
if (dm1 == null || dm2 == null) {
assertEquals(dm1, dm2);
return;
}
assertEquals(dm1.getAlgorithm(), dm2.getAlgorithm());
}
public static void checkTransforms(TransformsType tTypes1, TransformsType tTypes2) {
if (tTypes1 == null || tTypes2 == null) {
assertEquals(tTypes1, tTypes2);
return;
}
List tt1List = tTypes1.getTransform();
List tt2List = tTypes2.getTransform();
if (tt1List == null || tt2List == null) {
assertEquals(tt1List, tt2List);
return;
}
assertEquals(tt1List.size(), tt2List.size());
Iterator ttList1Itr = tt1List.iterator();
Iterator ttList2Itr = tt2List.iterator();
while (ttList1Itr.hasNext()) {
TransformType tx1 = ttList1Itr.next();
TransformType tx2 = ttList2Itr.next();
assertEquals(tx1.getAlgorithm(), tx2.getAlgorithm());
checkTransformContentList(tx1.getContent(), tx2.getContent());
}
}
public static void checkTransformContentList(List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy