From 6b582e4e2d94ef4e3901d0b4782f4feabe45f622 Mon Sep 17 00:00:00 2001 From: keshavarzi Date: Wed, 21 Aug 2013 17:42:04 +0200 Subject: [PATCH] Bug fix in DiffGenerator with cycling schema types. --- .../main/groovy/com/predic8/schema/All.groovy | 6 +- .../main/groovy/com/predic8/schema/Any.groovy | 7 +- .../com/predic8/schema/Attribute.groovy | 8 ++- .../predic8/schema/BuiltInSchemaType.groovy | 6 +- .../groovy/com/predic8/schema/Choice.groovy | 6 +- .../com/predic8/schema/ComplexContent.groovy | 9 ++- .../com/predic8/schema/ComplexType.groovy | 7 +- .../groovy/com/predic8/schema/Element.groovy | 6 +- .../groovy/com/predic8/schema/GroupRef.groovy | 8 ++- .../groovy/com/predic8/schema/Sequence.groovy | 6 +- .../com/predic8/schema/SimpleContent.groovy | 8 ++- .../com/predic8/schema/SimpleType.groovy | 8 ++- .../BuiltInSchemaTypeDiffGenerator.groovy | 9 ++- .../diff/ComplexContentDiffGenerator.groovy | 2 +- .../diff/ComplexTypeDiffGenerator.groovy | 4 +- .../schema/diff/ElementDiffGenerator.groovy | 14 ++-- .../schema/diff/SchemaDiffGenerator.groovy | 53 ++++++++------- .../schema/diff/SequenceDiffGenerator.groovy | 2 +- .../diff/SimpleContentDiffGenerator.groovy | 4 +- .../schema/diff/UnitDiffGenerator.groovy | 11 ++- .../schema/restriction/BaseRestriction.groovy | 6 +- .../soamodel/AbstractDiffGenerator.groovy | 8 +-- .../soamodel/DiffGeneratorContext.groovy | 22 ++++++ .../wsdl/diff/WsdlDiffGenerator.groovy | 3 +- .../predic8/schema/SimpleContentTest.groovy | 2 +- .../NSConflictInRequestCreatorTest.groovy | 68 +++++++++++++++++++ .../prefix-conflict-test/NSConflictTest.wsdl | 35 ++++++++++ .../Test4NamespaceConfilict.xsd | 22 ++++++ .../Test4NamespaceConfilict2.xsd | 10 +++ 29 files changed, 283 insertions(+), 77 deletions(-) create mode 100644 core/src/main/groovy/com/predic8/soamodel/DiffGeneratorContext.groovy create mode 100644 core/src/test/groovy/com/predic8/wstool/creator/NSConflictInRequestCreatorTest.groovy create mode 100644 core/src/test/resources/prefix-conflict-test/NSConflictTest.wsdl create mode 100644 core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict.xsd create mode 100644 core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict2.xsd diff --git a/core/src/main/groovy/com/predic8/schema/All.groovy b/core/src/main/groovy/com/predic8/schema/All.groovy index 435529f3..f6eee0dd 100644 --- a/core/src/main/groovy/com/predic8/schema/All.groovy +++ b/core/src/main/groovy/com/predic8/schema/All.groovy @@ -14,7 +14,9 @@ package com.predic8.schema; +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.wstool.creator.* class All extends ModelGroup { @@ -30,8 +32,8 @@ class All extends ModelGroup { creator.createAll(this, ctx.clone()) } - def compare(generator, other){ - generator.compareAll(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareAll(this, other, ctx) } String toString(){ diff --git a/core/src/main/groovy/com/predic8/schema/Any.groovy b/core/src/main/groovy/com/predic8/schema/Any.groovy index 9092403b..cb7a29b5 100644 --- a/core/src/main/groovy/com/predic8/schema/Any.groovy +++ b/core/src/main/groovy/com/predic8/schema/Any.groovy @@ -14,8 +14,11 @@ package com.predic8.schema; +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.wstool.creator.* + import javax.xml.namespace.QName as JQName class Any extends SchemaComponent { @@ -48,8 +51,8 @@ class Any extends SchemaComponent { creator.createAny(this, ctx.clone()) } - def compare(generator, other){ - generator.compareAny(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareAny(this, other, ctx) } String toString(){ diff --git a/core/src/main/groovy/com/predic8/schema/Attribute.groovy b/core/src/main/groovy/com/predic8/schema/Attribute.groovy index 9f9751fa..57891eaf 100644 --- a/core/src/main/groovy/com/predic8/schema/Attribute.groovy +++ b/core/src/main/groovy/com/predic8/schema/Attribute.groovy @@ -14,8 +14,12 @@ package com.predic8.schema; +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; + import groovy.xml.* + import javax.xml.namespace.QName as JQName class Attribute extends Declaration { @@ -72,8 +76,8 @@ class Attribute extends Declaration { creator.createAttribute(this, ctx) } - def compare(generator, other){ - generator.compareAttribute(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareAttribute(this, other, ctx) } def getElementName(){ diff --git a/core/src/main/groovy/com/predic8/schema/BuiltInSchemaType.groovy b/core/src/main/groovy/com/predic8/schema/BuiltInSchemaType.groovy index 8a232198..82aea388 100644 --- a/core/src/main/groovy/com/predic8/schema/BuiltInSchemaType.groovy +++ b/core/src/main/groovy/com/predic8/schema/BuiltInSchemaType.groovy @@ -16,7 +16,9 @@ package com.predic8.schema +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext; +import com.predic8.soamodel.DiffGeneratorContext; import groovy.xml.QName @@ -38,7 +40,7 @@ class BuiltInSchemaType extends TypeDefinition { throw new RuntimeException('BuiltInSchemaType have to be created by the given creator itself.') } - def compare(generator, other){ - generator.compareBuiltInSchemaType(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareBuiltInSchemaType(this, other, ctx) } } diff --git a/core/src/main/groovy/com/predic8/schema/Choice.groovy b/core/src/main/groovy/com/predic8/schema/Choice.groovy index 6201f847..6c2753c2 100644 --- a/core/src/main/groovy/com/predic8/schema/Choice.groovy +++ b/core/src/main/groovy/com/predic8/schema/Choice.groovy @@ -14,7 +14,9 @@ package com.predic8.schema +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.wstool.creator.* @@ -29,8 +31,8 @@ class Choice extends ModelGroup{ creator.createChoice(this, ctx.clone()) } - def compare(generator, other){ - generator.compareChoice(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareChoice(this, other, ctx) } String toString(){ diff --git a/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy b/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy index bbe38d60..d0bf6a7d 100644 --- a/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy +++ b/core/src/main/groovy/com/predic8/schema/ComplexContent.groovy @@ -13,10 +13,13 @@ limitations under the License. */ package com.predic8.schema +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext - +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.schema.restriction.* + import javax.xml.namespace.QName as JQName + import static com.predic8.soamodel.Consts.SCHEMA_NS class ComplexContent extends SchemaComponent { @@ -55,8 +58,8 @@ class ComplexContent extends SchemaComponent { creator.createComplexContent(this, ctx) } - def compare(generator, other){ - generator.compareComplexContent(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareComplexContent(this, other, ctx) } diff --git a/core/src/main/groovy/com/predic8/schema/ComplexType.groovy b/core/src/main/groovy/com/predic8/schema/ComplexType.groovy index e5e05b18..1d840355 100644 --- a/core/src/main/groovy/com/predic8/schema/ComplexType.groovy +++ b/core/src/main/groovy/com/predic8/schema/ComplexType.groovy @@ -15,12 +15,15 @@ package com.predic8.schema; import groovy.xml.* + import javax.xml.namespace.QName as JQName; import sun.org.mozilla.classfile.internal.SuperBlock; import com.predic8.wstool.creator.* +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext; +import com.predic8.soamodel.DiffGeneratorContext; class ComplexType extends TypeDefinition { @@ -91,8 +94,8 @@ class ComplexType extends TypeDefinition { creator.createComplexType(this, ctx.clone()) } - def compare(generator, other){ - generator.compareComplexType(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareComplexType(this, other, ctx) } Sequence getSequence(){ diff --git a/core/src/main/groovy/com/predic8/schema/Element.groovy b/core/src/main/groovy/com/predic8/schema/Element.groovy index 5fac331d..820df64d 100644 --- a/core/src/main/groovy/com/predic8/schema/Element.groovy +++ b/core/src/main/groovy/com/predic8/schema/Element.groovy @@ -22,7 +22,9 @@ import org.apache.commons.logging.* import com.predic8.wstool.creator.* import com.predic8.schema.creator.*; +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.xml.util.* class Element extends Declaration { @@ -81,8 +83,8 @@ class Element extends Declaration { creator.createElement(this, ctx.clone()) } - def compare(generator, other){ - generator.compareElement(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareElement(this, other, ctx) } String getRequest(formParams){ diff --git a/core/src/main/groovy/com/predic8/schema/GroupRef.groovy b/core/src/main/groovy/com/predic8/schema/GroupRef.groovy index b8ffa472..7731aa38 100644 --- a/core/src/main/groovy/com/predic8/schema/GroupRef.groovy +++ b/core/src/main/groovy/com/predic8/schema/GroupRef.groovy @@ -15,8 +15,12 @@ package com.predic8.schema; import groovy.xml.* + +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.wstool.creator.* + import javax.xml.stream.* class GroupRef extends SchemaComponent{ @@ -27,8 +31,8 @@ class GroupRef extends SchemaComponent{ creator.createGroupRef(this, ctx) } - def compare( generator, other ) { - generator.compareGroupRef( this, other ) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareGroupRef( this, other, ctx) } public boolean equals(obj) { diff --git a/core/src/main/groovy/com/predic8/schema/Sequence.groovy b/core/src/main/groovy/com/predic8/schema/Sequence.groovy index 16eb6d72..1ecf4183 100644 --- a/core/src/main/groovy/com/predic8/schema/Sequence.groovy +++ b/core/src/main/groovy/com/predic8/schema/Sequence.groovy @@ -15,7 +15,9 @@ package com.predic8.schema; import com.predic8.wstool.creator.* +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; class Sequence extends ModelGroup{ @@ -28,8 +30,8 @@ class Sequence extends ModelGroup{ creator.createSequence(this, ctx.clone()) } - def compare(generator, other){ - generator.compareSequence(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareSequence(this, other, ctx) } String toString(){ diff --git a/core/src/main/groovy/com/predic8/schema/SimpleContent.groovy b/core/src/main/groovy/com/predic8/schema/SimpleContent.groovy index ce276bc7..6fbd2f0b 100644 --- a/core/src/main/groovy/com/predic8/schema/SimpleContent.groovy +++ b/core/src/main/groovy/com/predic8/schema/SimpleContent.groovy @@ -12,10 +12,14 @@ package com.predic8.schema import java.util.List + import javax.xml.namespace.QName as JQName +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.schema.restriction.* + import static com.predic8.soamodel.Consts.SCHEMA_NS class SimpleContent extends SchemaComponent { @@ -53,8 +57,8 @@ class SimpleContent extends SchemaComponent { creator.createSimpleContent(this, ctx) } - def compare(generator, other){ - generator.compareSimpleContent(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareSimpleContent(this, other, ctx) } } diff --git a/core/src/main/groovy/com/predic8/schema/SimpleType.groovy b/core/src/main/groovy/com/predic8/schema/SimpleType.groovy index 84c471b6..c99dbb4f 100644 --- a/core/src/main/groovy/com/predic8/schema/SimpleType.groovy +++ b/core/src/main/groovy/com/predic8/schema/SimpleType.groovy @@ -18,11 +18,13 @@ import groovy.xml.QName; import java.util.List; +import com.predic8.soamodel.AbstractDiffGenerator; import com.predic8.soamodel.CreatorContext +import com.predic8.soamodel.DiffGeneratorContext; import com.predic8.wstool.creator.* import com.predic8.schema.restriction.* -import static com.predic8.soamodel.Consts.SCHEMA_NS +import static com.predic8.soamodel.Consts.SCHEMA_NS import groovy.xml.* class SimpleType extends TypeDefinition { @@ -81,8 +83,8 @@ class SimpleType extends TypeDefinition { creator.createSimpleType(this, ctx.clone()) } - def compare(generator, other){ - generator.compareSimpleType(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareSimpleType(this, other, ctx) } String toString(){ diff --git a/core/src/main/groovy/com/predic8/schema/diff/BuiltInSchemaTypeDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/BuiltInSchemaTypeDiffGenerator.groovy index b100657e..46d58dd1 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/BuiltInSchemaTypeDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/BuiltInSchemaTypeDiffGenerator.groovy @@ -14,10 +14,9 @@ package com.predic8.schema.diff -import java.util.List; import com.predic8.soamodel.* -class BuiltInSchemaTypeDiffGenerator { +class BuiltInSchemaTypeDiffGenerator extends AbstractDiffGenerator { def generator def a,b @@ -35,5 +34,11 @@ class BuiltInSchemaTypeDiffGenerator { // } [] } + + + @Override + protected Object updateLabels() { + return null; + } } diff --git a/core/src/main/groovy/com/predic8/schema/diff/ComplexContentDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/ComplexContentDiffGenerator.groovy index 33a35483..ac7548f3 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/ComplexContentDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/ComplexContentDiffGenerator.groovy @@ -59,7 +59,7 @@ class ComplexContentDiffGenerator extends AbstractDiffGenerator{ return [new Difference(description:"${a.derivation.elementName.localPart.capitalize()} ${labelHasChanged}: " , type: 'complexContent', diffs: [new Difference(description:"ModelGroup has changed from '${a.derivation.model.elementName}' to '${b.derivation.model.elementName}'." , type: 'model', breaks:true, exchange: a.exchange)], exchange: a.exchange)] } - def lDiffs = a.derivation.model?.compare(generator, b.derivation.model) + def lDiffs = a.derivation.model?.compare(generator, b.derivation.model, ctx.clone()) if(lDiffs){ return [new Difference(description:"${a.derivation.elementName.localPart.capitalize()} ${labelHasChanged}: " , type: 'complexContent', diffs: lDiffs, exchange: a.exchange)] } diff --git a/core/src/main/groovy/com/predic8/schema/diff/ComplexTypeDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/ComplexTypeDiffGenerator.groovy index 0e39e06d..64923f1e 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/ComplexTypeDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/ComplexTypeDiffGenerator.groovy @@ -33,7 +33,7 @@ class ComplexTypeDiffGenerator extends UnitDiffGenerator{ } List compareUnit(){ - def lDiffs = new AnnotationDiffGenerator(a: a.annotation, b: b.annotation, generator: generator).compare() + def lDiffs = new AnnotationDiffGenerator(a: a.annotation, b: b.annotation, generator: generator).compare() lDiffs.addAll( compareModel()) lDiffs } @@ -45,7 +45,7 @@ class ComplexTypeDiffGenerator extends UnitDiffGenerator{ } else if(a.model) { a.model.exchange.addAll(a.exchange) b.model?.exchange?.addAll(b.exchange) - lDiffs.addAll(a.model.compare(generator, b.model )) + lDiffs.addAll(a.model.compare(generator, b.model, ctx.clone())) } lDiffs.addAll(generator.compareAttributes(a, b)) diff --git a/core/src/main/groovy/com/predic8/schema/diff/ElementDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/ElementDiffGenerator.groovy index 7d9b86df..50d5072e 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/ElementDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/ElementDiffGenerator.groovy @@ -45,8 +45,8 @@ class ElementDiffGenerator extends UnitDiffGenerator { } List compareUnit(){ - log.debug("compareElement") - def lDiffs = [] + log.debug("compareElement") + def lDiffs = [] lDiffs.addAll(generator.compareAnnotation(a.annotation, b.annotation)) lDiffs.addAll(compareType()) lDiffs.addAll(compareMinMaxOccurs()) @@ -73,20 +73,24 @@ class ElementDiffGenerator extends UnitDiffGenerator { lDiffs } + //Recursion is possible if an element in the embedded type references a complexType, which returns to the wrapping element of the embedded type. private List compareEmbeddedType() { a.embeddedType?.exchange.addAll(a.exchange) b.embeddedType?.exchange.addAll(b.exchange) - a.embeddedType?.compare(generator, b.embeddedType) ?: [] + a.embeddedType?.compare(generator, b.embeddedType, ctx.clone()) ?: [] } + //Recursion is possible if an element references a type, which returns to the element in further steps. List compare4WSDL() { def diffs = [] def aT = a.schema.getType(a.type) def bT = b.schema.getType(b.type) - if(aT && bT &&a.type == b.type){ + if(aT && bT && a.type == b.type){ + //exchange marks the message direction in the using wsdl:operation aT?.exchange.addAll(a.exchange) bT?.exchange.addAll(b.exchange) - diffs.addAll(aT.compare(generator, bT)) + + diffs.addAll(aT.compare(generator, bT, ctx.clone())) } diffs } diff --git a/core/src/main/groovy/com/predic8/schema/diff/SchemaDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/SchemaDiffGenerator.groovy index 051939f2..55785769 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/SchemaDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/SchemaDiffGenerator.groovy @@ -37,6 +37,7 @@ class SchemaDiffGenerator extends AbstractDiffGenerator{ updateLabels() } + //ctx public SchemaDiffGenerator(Schema a, Schema b){ this.a = a this.b = b @@ -73,44 +74,44 @@ class SchemaDiffGenerator extends AbstractDiffGenerator{ new ComplexTypesDiffGenerator(a: a.complexTypes, b: b.complexTypes, generator: this).compare() } - private def compareComplexType(a, b){ - new ComplexTypeDiffGenerator(a: a, b: b, generator: this).compare() + private def compareComplexType(a, b, ctx){ + new ComplexTypeDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareSequence(a, b) { - new SequenceDiffGenerator(a: a, b: b, generator: this).compare() + def compareSequence(a, b, ctx) { + new SequenceDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareChoice(a, b) { - new ChoiceDiffGenerator(a: a, b: b, generator: this).compare() + def compareChoice(a, b, ctx) { + new ChoiceDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareAll(a, b) { - new AllDiffGenerator(a: a, b: b, generator: this).compare() + def compareAll(a, b, ctx) { + new AllDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } def compareGroups(groupA, groupB ) { throw new RuntimeException('compareGroups() not implemented yet!') } - def compareGroupRef( groupRefA, groupRefB ) { - new GroupRefDiffGenerator(a: groupRefA, b: groupRefB, generator: this).compare() + def compareGroupRef( groupRefA, groupRefB, ctx) { + new GroupRefDiffGenerator(a: groupRefA, b: groupRefB, generator: this, ctx: ctx).compare() } private def compareSimpleTypes(){ new SimpleTypesDiffGenerator(a: a.simpleTypes, b: b.simpleTypes, generator: this).compare() } - private def compareSimpleType(a, b){ - new SimpleTypeDiffGenerator(a: a, b: b, generator: this).compare() + private def compareSimpleType(a, b, ctx){ + new SimpleTypeDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } private def compareElements(){ new ElementsDiffGenerator(a: a?.elements ?: [], b: b?.elements ?: [], generator: this).compare() } - def compareElement(a, b){ - new ElementDiffGenerator(a: a, b: b, generator: this).compare() + def compareElement(a, b, ctx){ + new ElementDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } private def compareImports(){ @@ -122,32 +123,32 @@ class SchemaDiffGenerator extends AbstractDiffGenerator{ new AttributesDiffGenerator(a: a.attributes, b: b.attributes, generator: this).compare() } - def compareAttribute(a,b){ - new AttributeDiffGenerator(a: a, b: b, generator: this).compare() + def compareAttribute(a,b, ctx){ + new AttributeDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } def compareAnnotation(a, b){ new AnnotationDiffGenerator(a: a, b: b, generator: this).compare() } - def compareAny(a, b) { - new AnyDiffGenerator(a: a, b: b, generator: this).compare() + def compareAny(a, b, ctx) { + new AnyDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareComplexContent(a, b){ - new ComplexContentDiffGenerator(a: a, b: b, generator: this).compare() + def compareComplexContent(a, b, ctx){ + new ComplexContentDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareSimpleContent(a, b) { - new SimpleContentDiffGenerator(a: a, b: b, generator: this).compare() + def compareSimpleContent(a, b, ctx) { + new SimpleContentDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareSimpleRestriction(a, b){ - new SimpleRestrictionDiffGenerator(a: a, b: b, generator: this).compare() + def compareSimpleRestriction(a, b, ctx){ + new SimpleRestrictionDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } - def compareBuiltInSchemaType(a, b){ - new BuiltInSchemaTypeDiffGenerator(a: a, b: b, generator: this).compare() + def compareBuiltInSchemaType(a, b, ctx){ + new BuiltInSchemaTypeDiffGenerator(a: a, b: b, generator: this, ctx: ctx).compare() } protected def updateLabels(){ diff --git a/core/src/main/groovy/com/predic8/schema/diff/SequenceDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/SequenceDiffGenerator.groovy index cee3d49f..3c9f7407 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/SequenceDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/SequenceDiffGenerator.groovy @@ -55,7 +55,7 @@ class SequenceDiffGenerator extends UnitDiffGenerator { bPs << bP aP.exchange.addAll(a.exchange) bP.exchange.addAll(b.exchange) - def lDiffs = aP.compare(generator, bP) + def lDiffs = aP.compare(generator, bP, ctx.clone()) diffs.addAll(lDiffs) return } diff --git a/core/src/main/groovy/com/predic8/schema/diff/SimpleContentDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/SimpleContentDiffGenerator.groovy index 3a268455..29bcadb9 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/SimpleContentDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/SimpleContentDiffGenerator.groovy @@ -46,7 +46,7 @@ class SimpleContentDiffGenerator extends AbstractDiffGenerator{ if(a.extension.model?.class != b.extension.model?.class){ return [new Difference(description:"ModelGroup has changed from ${a.extension.model.class} to ${b.extension.model.class}." , type: 'extension', breaks:true)] } - return a.extension.model?.compare(generator, b.extension.model ) + return a.extension.model?.compare(generator, b.extension.model, ctx.clone()) } // if(a.restriction?.base != b.restriction?.base){ @@ -54,7 +54,7 @@ class SimpleContentDiffGenerator extends AbstractDiffGenerator{ // } if(a.restriction && b.restriction){ - return a.restriction.compare(generator, b.restriction) ?: [] + return a.restriction.compare(generator, b.restriction, ctx.clone()) ?: [] } } diff --git a/core/src/main/groovy/com/predic8/schema/diff/UnitDiffGenerator.groovy b/core/src/main/groovy/com/predic8/schema/diff/UnitDiffGenerator.groovy index 0555014e..c47152b0 100644 --- a/core/src/main/groovy/com/predic8/schema/diff/UnitDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/schema/diff/UnitDiffGenerator.groovy @@ -23,8 +23,15 @@ abstract class UnitDiffGenerator extends AbstractDiffGenerator{ public List compare() { if(a && !b) return [removed()] if(!a && b) return [added()] - if(a && b && compareUnit()) { - return [changed(compareUnit())] + + //If the unit is already visited, return to avoid recursion. + if(ctx.visited.contains(a)) return [] + ctx.visited << a + + def lDiffs = compareUnit() + + if(a && b && lDiffs) { + return [changed(lDiffs)] } [] } diff --git a/core/src/main/groovy/com/predic8/schema/restriction/BaseRestriction.groovy b/core/src/main/groovy/com/predic8/schema/restriction/BaseRestriction.groovy index f321fdc3..75e8a319 100644 --- a/core/src/main/groovy/com/predic8/schema/restriction/BaseRestriction.groovy +++ b/core/src/main/groovy/com/predic8/schema/restriction/BaseRestriction.groovy @@ -15,12 +15,14 @@ package com.predic8.schema.restriction; import javax.xml.namespace.QName as JQName + import groovy.xml.QName as GQName import com.predic8.wstool.creator.* import com.predic8.schema.restriction.facet.* import com.predic8.schema.* import com.predic8.soamodel.* + import static com.predic8.soamodel.Consts.SCHEMA_NS class BaseRestriction extends SchemaComponent { @@ -137,8 +139,8 @@ class BaseRestriction extends SchemaComponent { creator.createSimpleRestriction(this, ctx) } - def compare(generator, other ) { - generator.compareSimpleRestriction(this, other) + def compare(AbstractDiffGenerator generator, other, DiffGeneratorContext ctx = new DiffGeneratorContext()){ + generator.compareSimpleRestriction(this, other, ctx) } def createXML(builder,element, path, formParams){} diff --git a/core/src/main/groovy/com/predic8/soamodel/AbstractDiffGenerator.groovy b/core/src/main/groovy/com/predic8/soamodel/AbstractDiffGenerator.groovy index ff51e2ce..ec66cac5 100644 --- a/core/src/main/groovy/com/predic8/soamodel/AbstractDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/soamodel/AbstractDiffGenerator.groovy @@ -14,13 +14,10 @@ package com.predic8.soamodel -import java.util.Locale; -import java.util.ResourceBundle; +import groovy.xml.QName import com.predic8.schema.* -import com.predic8.schema.restriction.facet.*; - -import groovy.xml.QName +import com.predic8.schema.restriction.facet.* abstract class AbstractDiffGenerator { @@ -28,6 +25,7 @@ abstract class AbstractDiffGenerator { def generator def a,b + DiffGeneratorContext ctx = new DiffGeneratorContext() def abstract compare() diff --git a/core/src/main/groovy/com/predic8/soamodel/DiffGeneratorContext.groovy b/core/src/main/groovy/com/predic8/soamodel/DiffGeneratorContext.groovy new file mode 100644 index 00000000..630631b9 --- /dev/null +++ b/core/src/main/groovy/com/predic8/soamodel/DiffGeneratorContext.groovy @@ -0,0 +1,22 @@ +/* Copyright 2012 predic8 GmbH, www.predic8.com + + 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 com.predic8.soamodel + +class DiffGeneratorContext implements Cloneable { + + //List of compared elements to avoid a recursive comparison. + List visited = [] +} + diff --git a/core/src/main/groovy/com/predic8/wsdl/diff/WsdlDiffGenerator.groovy b/core/src/main/groovy/com/predic8/wsdl/diff/WsdlDiffGenerator.groovy index 2c83b453..9ef89a84 100644 --- a/core/src/main/groovy/com/predic8/wsdl/diff/WsdlDiffGenerator.groovy +++ b/core/src/main/groovy/com/predic8/wsdl/diff/WsdlDiffGenerator.groovy @@ -25,8 +25,7 @@ class WsdlDiffGenerator extends AbstractDiffGenerator{ private Log log = LogFactory.getLog(this.class) - public WsdlDiffGenerator(){ - } + public WsdlDiffGenerator(){ } public WsdlDiffGenerator(Definitions a, Definitions b){ this.a = a diff --git a/core/src/test/groovy/com/predic8/schema/SimpleContentTest.groovy b/core/src/test/groovy/com/predic8/schema/SimpleContentTest.groovy index a2681f9e..73d764e1 100644 --- a/core/src/test/groovy/com/predic8/schema/SimpleContentTest.groovy +++ b/core/src/test/groovy/com/predic8/schema/SimpleContentTest.groovy @@ -46,7 +46,7 @@ class SimpleContentTest extends GroovyTestCase { SimpleContent a = element.embeddedType.model def b = new SimpleContent(extension: new Extension()) b.extension.base = new QName('http://www.w3.org/2001/XMLSchema','int') - def diffs = diffGen.compareSimpleContent(a, b) + def diffs = a.compare(diffGen, b) assertEquals(1, diffs.size()) assertTrue(diffs.toString().contains("SimpleContent has changed")) assertTrue(diffs[0].dump().contains("Extension base has changed from {http://www.w3.org/2001/XMLSchema}decimal to {http://www.w3.org/2001/XMLSchema}int.")) diff --git a/core/src/test/groovy/com/predic8/wstool/creator/NSConflictInRequestCreatorTest.groovy b/core/src/test/groovy/com/predic8/wstool/creator/NSConflictInRequestCreatorTest.groovy new file mode 100644 index 00000000..8785a770 --- /dev/null +++ b/core/src/test/groovy/com/predic8/wstool/creator/NSConflictInRequestCreatorTest.groovy @@ -0,0 +1,68 @@ +/* Copyright 2012 predic8 GmbH, www.predic8.com + + 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 com.predic8.wstool.creator + +import groovy.xml.* + +import com.predic8.schema.* +import com.predic8.soamodel.Consts +import com.predic8.wsdl.WSDLParser +import com.predic8.xml.util.* + +class NSConflictInRequestCreatorTest extends GroovyTestCase{ + + def schema + + public void setUp(){ + def parser = new SchemaParser(resourceResolver: new ClasspathResolver()) + schema = parser.parse("prefix-conflict-test/Test4NamespaceConfilict.xsd") + } + + void testCreatTemplateRequest() { +// println schema.getElement('Test').requestTemplate +// def requestTemplate = new XmlSlurper().parseText(schema.getElement('Test').requestTemplate) +// assertEquals('programer', requestTemplate.employee.department.activity.text()) + } + + void testCreatRequestWithEmbeddedType() { + def strWriter = new StringWriter() + def creator = new RequestCreator(builder : new MarkupBuilder(strWriter)) + def formParams = [:] + formParams['xpath:/Test/From1']='test' + formParams['xpath:/Test/FromSecondSchema/e1']='ABC' + formParams['xpath:/Test/FromSecondSchema/e2']='12345' + formParams['xpath:/Test/FromSecondSchema/e3']='2013-08-19' + schema.getElement('Test').create(creator, new RequestCreatorContext(formParams:formParams)) +// println strWriter +// def request = new XmlSlurper().parseText(strWriter.toString()) +// assertEquals('1', request.employee[0].id.text()) +// assertEquals('predic8', request.employee[1].department.company.text()) + } + + void testSOARequest(){ + def wsdl = new WSDLParser(resourceResolver: new ClasspathResolver()).parse('prefix-conflict-test/NSConflictTest.wsdl') + def sw = new StringWriter() + def formParams = [:] + formParams['xpath:/Test/FromFirstNS']='test' + formParams['xpath:/Test/FromSecondNS/e1']='ABC' + formParams['xpath:/Test/FromSecondNS/e2']='12345' + formParams['xpath:/Test/FromSecondNS/e3']='2013-08-19' + def creator = new SOARequestCreator(wsdl, new RequestCreator(),new MarkupBuilder(sw)) + creator.formParams = formParams + creator.createRequest 'NSConflictTest', 'NewOperation', 'NSConflictTestSOAP' +// println sw + } + +} diff --git a/core/src/test/resources/prefix-conflict-test/NSConflictTest.wsdl b/core/src/test/resources/prefix-conflict-test/NSConflictTest.wsdl new file mode 100644 index 00000000..c309ef6d --- /dev/null +++ b/core/src/test/resources/prefix-conflict-test/NSConflictTest.wsdl @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict.xsd b/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict.xsd new file mode 100644 index 00000000..72e830df --- /dev/null +++ b/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict2.xsd b/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict2.xsd new file mode 100644 index 00000000..0d8eb410 --- /dev/null +++ b/core/src/test/resources/prefix-conflict-test/Test4NamespaceConfilict2.xsd @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file