-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove property expansions on WSDL and WADL import
- Loading branch information
1 parent
973f762
commit 6373165
Showing
9 changed files
with
371 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
soapui/src/main/java/com/eviware/soapui/tools/PropertyExpansionRemover.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.eviware.soapui.tools; | ||
|
|
||
| /** | ||
| * Removes property expansions from an input string. | ||
| */ | ||
| public class PropertyExpansionRemover | ||
| { | ||
|
|
||
| public static final String EXPANSION_START = "${"; | ||
|
|
||
| public static String removeExpansions( String input ) | ||
| { | ||
| String output = input; | ||
| while (containsPropertyExpansion(output)) | ||
| { | ||
| output = removeExpansionAt( output, output.indexOf( EXPANSION_START ) ); | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| private static String removeExpansionAt( String input, int startIndex ) | ||
| { | ||
| String output = input; | ||
| while (containsNestedExpansion(output, startIndex)) | ||
| { | ||
| output = removeExpansionAt( output, output.indexOf( EXPANSION_START, startIndex + 1 ) ); | ||
| } | ||
| int endIndex = output.indexOf('}', startIndex); | ||
| return output.substring(0, startIndex) + output.substring(endIndex + 1); | ||
| } | ||
|
|
||
| private static boolean containsNestedExpansion( String output, int startIndex ) | ||
| { | ||
| String textToProcess = output.substring(startIndex + EXPANSION_START.length()); | ||
| return textToProcess.contains( EXPANSION_START ) && | ||
| textToProcess.indexOf( EXPANSION_START ) < textToProcess.indexOf( '}' ); | ||
| } | ||
|
|
||
| private static boolean containsPropertyExpansion( String input ) | ||
| { | ||
| if (!input.contains( EXPANSION_START )) | ||
| { | ||
| return false; | ||
| } | ||
| int startIndex = input.indexOf( EXPANSION_START ); | ||
| return input.indexOf('}', startIndex) != -1; | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
soapui/src/test/java/com/eviware/soapui/tools/PropertyExpansionRemoverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.eviware.soapui.tools; | ||
|
|
||
| import org.junit.Test; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.is; | ||
| import static org.junit.Assert.assertThat; | ||
|
|
||
| /** | ||
| * Unit tests for PropertyExpansionRemover. | ||
| */ | ||
| public class PropertyExpansionRemoverTest | ||
| { | ||
|
|
||
| @Test | ||
| public void removesPropertyExpansion() throws Exception | ||
| { | ||
| String stringWithPropertyExpansion = "<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"${#Project#MyValue }\"/>"; | ||
| assertThat( PropertyExpansionRemover.removeExpansions(stringWithPropertyExpansion ), | ||
| is("<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"\"/>")); | ||
| } | ||
|
|
||
| @Test | ||
| public void removesDynamicPropertyExpansion() throws Exception | ||
| { | ||
| String stringWithDynamicPropertyExpansion = "<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"${= new java.util.Date() }\"/>"; | ||
| assertThat( PropertyExpansionRemover.removeExpansions(stringWithDynamicPropertyExpansion ), | ||
| is("<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"\"/>")); | ||
| } | ||
|
|
||
| @Test | ||
| public void removesNestedPropertyExpansion() throws Exception | ||
| { | ||
| String stringWithDynamicPropertyExpansion = "<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"${#testxml#${testxpath}}\"/>"; | ||
| assertThat( PropertyExpansionRemover.removeExpansions(stringWithDynamicPropertyExpansion ), | ||
| is("<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"\"/>")); | ||
| } | ||
|
|
||
| @Test | ||
| public void removesMultiplePropertyExpansions() throws Exception | ||
| { | ||
| String stringWithMultiplePropertyExpansions = | ||
| "<!-- ${= 5- + 2}--><xsd:attribute name=\"name\" type=\"xsd:string\" default=\"${#testxml#${testxpath}}\"/>"; | ||
| assertThat( PropertyExpansionRemover.removeExpansions(stringWithMultiplePropertyExpansions ), | ||
| is("<!-- --><xsd:attribute name=\"name\" type=\"xsd:string\" default=\"\"/>")); | ||
| } | ||
|
|
||
| @Test | ||
| public void doesNotRemoveSpecialCharactersWhenNotPropertyExpansion() throws Exception | ||
| { | ||
| String stringWithSpecialCharacters = "<xsd:attribute name=\"name\" type=\"xsd:string\" default=\"$ { #testxml#$ {testxpath} } ${\"/>"; | ||
| assertThat( PropertyExpansionRemover.removeExpansions(stringWithSpecialCharacters ), | ||
| is(stringWithSpecialCharacters)); | ||
| } | ||
| } |
Oops, something went wrong.