Skip to content

Commit

Permalink
Merge pull request #402 from mbriskar/WINDUP-433
Browse files Browse the repository at this point in the history
WINDUP-433: Test input vs output variables for Conditions + small variab...
  • Loading branch information
jsight committed Jan 6, 2015
2 parents d5d7fdd + 1676ba2 commit 6c984c7
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 10 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.jboss.windup.config.condition;

import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.operation.Iteration;
import org.ocpsoft.rewrite.config.Condition;
import org.ocpsoft.rewrite.config.DefaultConditionBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;
Expand All @@ -30,7 +31,7 @@ public abstract class GraphCondition extends DefaultConditionBuilder
{

private String inputVariablesName;
private String outputVariablesName;
private String outputVariablesName = Iteration.DEFAULT_VARIABLE_LIST_STRING;

public abstract boolean evaluate(GraphRewrite event, EvaluationContext context);

Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.jboss.windup.graph.model.WindupVertexFrame;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.rules.apps.java.model.project.MavenProjectModel;
import org.ocpsoft.rewrite.config.ConditionBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;

public class Project extends GraphCondition
Expand All @@ -26,6 +27,15 @@ public static Project dependsOnArtifact(Artifact artifact)
project.artifact = artifact;
return project;
}

public static ProjectFrom from(String from)
{
return new ProjectFrom(from);
}

public void setArtifact(Artifact artifact) {
this.artifact=artifact;
}

public Artifact getArtifact()
{
Expand Down Expand Up @@ -86,9 +96,10 @@ public boolean evaluate(GraphRewrite event, EvaluationContext context)



public void as(String as)
public ConditionBuilder as(String as)
{
super.setOutputVariablesName(as);
return this;
}

public String toString()
Expand Down
@@ -0,0 +1,20 @@
package org.jboss.windup.project.condition;


public class ProjectFrom
{
private String inputVarName;

public ProjectFrom(String from)
{
this.inputVarName = from;
}

public Project dependsOnArtifact(Artifact artifact)
{
Project project = new Project();
project.setArtifact(artifact);
project.setInputVariablesName(inputVarName);
return project;
}
}
@@ -0,0 +1,20 @@
package org.jboss.windup.project.condition.test;

import org.jboss.windup.project.condition.Artifact;
import org.jboss.windup.project.condition.Project;
import org.junit.Assert;
import org.junit.Test;

public class ProjectTest
{

/**
* Testing that .from() and .as() sets the right variable
*/
@Test
public void xmlFileInputOutputVariableTest() {
Project as = (Project)Project.from("input").dependsOnArtifact(Artifact.withArtifactId("abc")).as("output");
Assert.assertEquals("input", as.getInputVariablesName());
Assert.assertEquals("output", as.getOutputVariablesName());
}
}
Expand Up @@ -57,7 +57,6 @@ public class JavaClass extends ParameterizedGraphCondition implements JavaClassB

private final String uniqueID; // maintains a unique identifier for each
private List<TypeReferenceLocation> locations = Collections.emptyList();
private String variable = Iteration.DEFAULT_VARIABLE_LIST_STRING;

private RegexParameterizedPatternParser referencePattern;
private RegexParameterizedPatternParser typeFilterPattern;
Expand Down Expand Up @@ -111,7 +110,7 @@ public JavaClassBuilderAt at(TypeReferenceLocation... locations)
public ConditionBuilder as(String variable)
{
Assert.notNull(variable, "Variable name must not be null.");
this.variable = variable;
this.setOutputVariablesName(variable);
return this;
}

Expand Down Expand Up @@ -326,7 +325,7 @@ public void setParameterStore(ParameterStore store)
@Override
protected String getVarname()
{
return variable;
return getOutputVariablesName();
}

public String toString()
Expand All @@ -345,7 +344,7 @@ public String toString()
{
builder.append(".at(" + locations + ")");
}
builder.append(".as(" + variable + ")");
builder.append(".as(" + getVarname() + ")");
return builder.toString();
}
}
Expand Up @@ -41,6 +41,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ocpsoft.rewrite.config.ConditionBuilder;
import org.ocpsoft.rewrite.config.Configuration;
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
import org.ocpsoft.rewrite.context.EvaluationContext;
Expand Down Expand Up @@ -135,6 +136,17 @@ public void testJavaClassCondition() throws IOException, InstantiationException,
Assert.assertEquals(2, provider.getSecondRuleMatchCount());
}
}

/**
* Testing that .from() and .as() sets the right variable
*/
@Test
public void testJavaClassInputOutputVariables()
{
JavaClass as = (JavaClass) JavaClass.from("input").references("abc").as("output");
Assert.assertEquals("input", as.getInputVariablesName());
Assert.assertEquals("output", as.getOutputVariablesName());
}

private Path getDefaultPath()
{
Expand Down
Expand Up @@ -54,7 +54,6 @@ public class XmlFile extends GraphCondition
private static XPathFactory factory = XPathFactory.newInstance();
private XPath xpathEngine = factory.newXPath();

private String variable = Iteration.DEFAULT_VARIABLE_LIST_STRING;
private String xpathString;
private XPathExpression compiledXPath;
private Map<String, String> namespaces = new HashMap<>();
Expand Down Expand Up @@ -94,7 +93,7 @@ public static XmlFile withDTDPublicId(String publicIdRegex)
public ConditionBuilder as(String variable)
{
Assert.notNull(variable, "Variable name must not be null.");
this.variable = variable;
this.setOutputVariablesName(variable);
return this;
}

Expand Down Expand Up @@ -255,7 +254,7 @@ else if (iterated instanceof XmlFileModel)
}
}
}
Variables.instance(event).setVariable(variable, resultLocations);
Variables.instance(event).setVariable(getOutputVariablesName(), resultLocations);
ExecutionStatistics.get().end("XmlFile.evaluate");
return !resultLocations.isEmpty();
}
Expand Down Expand Up @@ -314,7 +313,7 @@ public String toString()
{
builder.append(".withDTDPublicId(" + publicId + ")");
}
builder.append(".as(" + variable + ")");
builder.append(".as(" + getInputVariablesName() + ")");
return builder.toString();
}
}
@@ -0,0 +1,19 @@
package org.jboss.windup.rules.xml;

import org.jboss.windup.rules.apps.xml.condition.XmlFile;
import org.junit.Assert;
import org.junit.Test;

public class XmlFileTest
{

/**
* Testing that .from() and .as() sets the right variable
*/
@Test
public void xmlFileInputOutputVariableTest() {
XmlFile as = (XmlFile)XmlFile.from("input").matchesXpath("abc").as("output");
Assert.assertEquals("input", as.getInputVariablesName());
Assert.assertEquals("output", as.getOutputVariablesName());
}
}

0 comments on commit 6c984c7

Please sign in to comment.