Skip to content

Commit

Permalink
WINDUP-504: XmlFile.inFile(***) is a ParameterizedPattern, not a Regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Briskar authored and lincolnthree committed Feb 12, 2015
1 parent c20c34a commit 7198477
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
Expand Up @@ -9,6 +9,7 @@
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
Expand Down Expand Up @@ -74,13 +75,14 @@ public class XmlFile extends ParameterizedGraphCondition implements XmlFileDTD,X
private String xpathString;
private XPathExpression compiledXPath;
private Map<String, String> namespaces = new HashMap<>();
private String fileName;
private String publicId;
private String xpathResultMatch;

// just to extract required parameter names
private RegexParameterizedPatternParser xpathPattern;

private RegexParameterizedPatternParser fileNamePattern;

public void setXpathResultMatch(String xpathResultMatch)
{
this.xpathResultMatch = xpathResultMatch;
Expand Down Expand Up @@ -146,7 +148,7 @@ public ConditionBuilder as(String variable)
*/
public XmlFileIn inFile(String fileName)
{
this.fileName = fileName;
this.fileNamePattern = new RegexParameterizedPatternParser(fileName);
return this;
}

Expand All @@ -164,9 +166,9 @@ public XPathExpression getXPathExpression()
return compiledXPath;
}

public String getInFile()
public RegexParameterizedPatternParser getInFilePattern()
{
return fileName;
return fileNamePattern;
}

public String getPublicId()
Expand Down Expand Up @@ -331,9 +333,13 @@ else if (iterated instanceof XmlFileModel)
+ ")");
}

if (fileName != null && !fileName.equals(""))
if (fileNamePattern != null)
{
if (!xml.getFileName().matches(fileName))
final ParameterStore store = DefaultParameterStore.getInstance(context);
Pattern compiledPattern = fileNamePattern.getCompiledPattern(store);
String pattern = compiledPattern.pattern();
String fileName = xml.getFileName();
if (!fileName.matches(pattern))
{
continue;
}
Expand Down Expand Up @@ -444,9 +450,9 @@ public String toString()
{
builder.append(".matches(" + xpathString + ")");
}
if (fileName != null)
if (fileNamePattern != null)
{
builder.append(".inFile(" + fileName + ")");
builder.append(".inFile(" + fileNamePattern.toString() + ")");
}
if (publicId != null)
{
Expand Down
Expand Up @@ -74,7 +74,9 @@ public XmlFile processElement(ParserContext handlerManager, Element element)
{
xmlFile.namespace(nsMapping.getKey(), nsMapping.getValue());
}
xmlFile.inFile(inFile);
if(inFile !=null) {
xmlFile.inFile(inFile);
}
xmlFile.as(as);
return (XmlFile)xmlFile;
}
Expand Down
Expand Up @@ -3,7 +3,7 @@
<rules>
<rule>
<when>
<xmlfile as="default" matches="//datasource/@pool-name" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//datasource/@pool-name" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -15,7 +15,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasource/@jndi-name" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//datasource/@jndi-name" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -27,7 +27,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasource/@jta" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//datasource/@jta" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -39,7 +39,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasource/@spy" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//datasource/@spy" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -51,7 +51,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasource/@use-ccm" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//datasource/@use-ccm" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -63,7 +63,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//connection-url" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//connection-url" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -75,7 +75,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//driver-class" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//driver-class" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -87,7 +87,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//new-connection-sql" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//new-connection-sql" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -99,7 +99,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//min-pool-size" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//min-pool-size" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -111,7 +111,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//max-pool-size" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//max-pool-size" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -123,7 +123,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//prefill" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//prefill" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -135,7 +135,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//use-strict-min" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//use-strict-min" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -147,7 +147,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//transaction-isolation" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//transaction-isolation" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -159,7 +159,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//flush-strategy" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//flush-strategy" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -171,7 +171,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//user-name" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//user-name" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -183,7 +183,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//password" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//password" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -195,7 +195,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//background-validation" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//background-validation" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -207,7 +207,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//use-fast-fail" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//use-fast-fail" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -219,7 +219,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//idle-timeout-minutes" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//idle-timeout-minutes" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -231,7 +231,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//xa-resource-timeout" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//xa-resource-timeout" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -243,7 +243,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//track-statements" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//track-statements" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -255,7 +255,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//prepared-statement-cache-size" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//prepared-statement-cache-size" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -267,7 +267,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//check-valid-connection-sql" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//check-valid-connection-sql" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -279,7 +279,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//validate-on-match" in=".*ds-eap6.xml">
<xmlfile as="default" matches="//validate-on-match" in="{*}ds-eap6.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -291,7 +291,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:postgres')]" in=".*-ds.xml">
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:postgres')]" in="{*}-ds.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -303,7 +303,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:oracle')]" in=".*-ds.xml">
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:oracle')]" in="{*}-ds.xml">
</xmlfile>
</when>
<perform>
Expand All @@ -315,7 +315,7 @@
</rule>
<rule>
<when>
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:sqlserver')]" in=".*-ds.xml">
<xmlfile as="default" matches="//datasources/local-tx-datasource/connection-url[contains(text(),'jdbc:sqlserver')]" in="{*}-ds.xml">
</xmlfile>
</when>
<perform>
Expand Down
Expand Up @@ -77,15 +77,15 @@ public void testXmlFileCondition() throws Exception
// verify xmlfile
Assert.assertEquals(null, xmlFile.getInputVariablesName());
Assert.assertEquals("public", xmlFile.getPublicId());
Assert.assertEquals(".*", xmlFile.getInFile());
Assert.assertEquals("{*}", xmlFile.getInFilePattern().getPattern());
Assert.assertEquals("/abc:project", xmlFile.getXpathString());

Element secondXmlFile = xmlFileList.get(1);
xmlFile = parser.<XmlFile> processElement(secondXmlFile);
// verify xmlfile
Assert.assertEquals(null, xmlFile.getInputVariablesName());
Assert.assertEquals("public", xmlFile.getPublicId());
Assert.assertEquals(null, xmlFile.getInFile());
Assert.assertEquals(null, xmlFile.getInFilePattern());
Assert.assertEquals(null, xmlFile.getXpathString());
}

Expand All @@ -103,4 +103,4 @@ public void testXmlFileWithoutPublidIdAndXpath() throws Exception
Element thirdXmlFile = xmlFileList.get(2);
XmlFile xmlFile = parser.<XmlFile> processElement(thirdXmlFile);
}
}
}

0 comments on commit 7198477

Please sign in to comment.