Skip to content

Commit

Permalink
WINDUP-222: Fix test failures after merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Sep 18, 2014
1 parent 4cbdc67 commit 14a3ac6
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 130 deletions.
Expand Up @@ -9,8 +9,7 @@
import java.util.List;
import java.util.Map;


import org.ocpsoft.rewrite.config.Rule;
import org.ocpsoft.rewrite.config.Rule;
import org.jboss.forge.furnace.util.Assert;
import org.jboss.windup.config.GraphRewrite;
import org.jboss.windup.config.Variables;
Expand Down Expand Up @@ -60,6 +59,7 @@ private XmlFile(String xpath)
XmlFile()
{
}

/**
* Create a new {@link XmlFile} {@link Condition}.
*/
Expand Down Expand Up @@ -126,14 +126,20 @@ public boolean evaluate(final GraphRewrite event, final EvaluationContext contex
for (WindupVertexFrame iterated : allXmls)
{
XmlFileModel xml = null;
if(iterated instanceof FileReferenceModel) {
xml = (XmlFileModel)((FileReferenceModel)iterated).getFile();
} else if(iterated instanceof XmlFileModel){
xml= (XmlFileModel)iterated;
} else {
throw new WindupException("XmlFile was called on the wrong graph type ( " + iterated.toPrettyString() + ")");
if (iterated instanceof FileReferenceModel)
{
xml = (XmlFileModel) ((FileReferenceModel) iterated).getFile();
}
else if (iterated instanceof XmlFileModel)
{
xml = (XmlFileModel) iterated;
}
else
{
throw new WindupException("XmlFile was called on the wrong graph type ( " + iterated.toPrettyString()
+ ")");
}

if (fileName != null && !fileName.equals(""))
{
if (!xml.getFileName().equals(fileName))
Expand All @@ -143,7 +149,8 @@ public boolean evaluate(final GraphRewrite event, final EvaluationContext contex
}
if (publicId != null && !publicId.equals(""))
{
if (xml.getDoctype() == null || xml.getDoctype().getPublicId() == null || !xml.getDoctype().getPublicId().matches(publicId))
if (xml.getDoctype() == null || xml.getDoctype().getPublicId() == null
|| !xml.getDoctype().getPublicId().matches(publicId))
{
continue;
}
Expand All @@ -153,10 +160,10 @@ public boolean evaluate(final GraphRewrite event, final EvaluationContext contex
{
try
{

Document document = xml.asDocument();
NodeList result = XmlUtil.xpathNodeList(document, xpath, namespaces);
List<String> lines = Files.readAllLines(Paths.get(xml.getFilePath()),Charset.defaultCharset());
List<String> lines = Files.readAllLines(Paths.get(xml.getFilePath()), Charset.defaultCharset());
if (result != null && (result.getLength() != 0))
{
for (int i = 0; i < result.getLength(); i++)
Expand Down Expand Up @@ -199,11 +206,12 @@ public boolean evaluate(final GraphRewrite event, final EvaluationContext contex
}
resultLocations.add(fileLocation);
}
} }
}
}
catch (MarshallingException e)
{
GraphService<ClassificationModel> classificationService = event.getGraphContext().getService(
ClassificationModel.class);
GraphService<ClassificationModel> classificationService = new GraphService<>(
event.getGraphContext(), ClassificationModel.class);

ClassificationModel classification = classificationService.getUniqueByProperty(
ClassificationModel.PROPERTY_CLASSIFICATION, XmlFile.UNPARSEABLE_XML_CLASSIFICATION);
Expand All @@ -225,7 +233,6 @@ public boolean evaluate(final GraphRewrite event, final EvaluationContext contex
}

}


}
Variables.instance(event).setVariable(variable, resultLocations);
Expand All @@ -247,9 +254,10 @@ public void setPublicId(String publicId)
{
this.publicId = publicId;
}

public String toString() {
return "XmlFile.from().matchesXpath(" + xpath + ").inFile(" + fileName + ").withDTDPublicId(" + publicId + ");";

public String toString()
{
return "XmlFile.from().matchesXpath(" + xpath + ").inFile(" + fileName + ").withDTDPublicId(" + publicId + ");";
}

}
Expand Up @@ -35,7 +35,6 @@

public class XSLTTransformation extends AbstractIterationOperation<XmlFileModel>
{

private ClassLoader contextClassLoader;

@Inject
Expand Down
Expand Up @@ -8,10 +8,6 @@
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -30,13 +26,10 @@
import org.jboss.windup.config.RulePhase;
import org.jboss.windup.config.WindupRuleProvider;
import org.jboss.windup.config.operation.ruleelement.AbstractIterationOperation;
import org.jboss.windup.engine.WindupConfiguration;
import org.jboss.windup.engine.WindupProcessor;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.config.operation.Iteration;
import org.jboss.windup.config.operation.ruleelement.AbstractIterationOperation;
import org.jboss.windup.engine.WindupProcessor;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphContextFactory;
import org.jboss.windup.graph.model.ProjectModel;
import org.jboss.windup.graph.model.WindupConfigurationModel;
import org.jboss.windup.graph.model.resource.FileModel;
Expand All @@ -46,9 +39,6 @@
import org.jboss.windup.reporting.config.Link;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.FileLocationModel;
import org.jboss.windup.reporting.config.Link;
import org.jboss.windup.reporting.model.ClassificationModel;
import org.jboss.windup.reporting.model.FileLocationModel;
import org.jboss.windup.reporting.model.InlineHintModel;
import org.jboss.windup.rules.apps.xml.condition.XmlFile;
import org.junit.Assert;
Expand All @@ -67,7 +57,6 @@ public class XMLHintsClassificationsTest
@AddonDependency(name = "org.jboss.windup.exec:windup-exec"),
@AddonDependency(name = "org.jboss.windup.rules.apps:rules-java", version = "2.0.0-SNAPSHOT"),
@AddonDependency(name = "org.jboss.windup.rules.apps:rules-xml"),
@AddonDependency(name = "org.jboss.windup.rules.apps:java-decompiler", version = "2.0.0-SNAPSHOT"),
@AddonDependency(name = "org.jboss.windup.reporting:windup-reporting"),
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi")
})
Expand All @@ -81,7 +70,6 @@ public static ForgeArchive getDeployment()
AddonDependencyEntry.create("org.jboss.windup.exec:windup-exec"),
AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-java"),
AddonDependencyEntry.create("org.jboss.windup.rules.apps:rules-xml"),
AddonDependencyEntry.create("org.jboss.windup.rules.apps:java-decompiler"),
AddonDependencyEntry.create("org.jboss.windup.reporting:windup-reporting"),
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
);
Expand All @@ -96,59 +84,70 @@ public static ForgeArchive getDeployment()
private WindupProcessor processor;

@Inject
private GraphContext context;
private GraphContextFactory factory;

@Test
public void testIterationVariableResolving() throws IOException
{
ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
pm.setName("Main Project");
FileModel inputPath = context.getFramed().addVertex(null, FileModel.class);
inputPath.setFilePath("src/test/resources/");
try (GraphContext context = factory.create())
{
ProjectModel pm = context.getFramed().addVertex(null, ProjectModel.class);
pm.setName("Main Project");
FileModel inputPath = context.getFramed().addVertex(null, FileModel.class);
inputPath.setFilePath("src/test/resources/");

Path outputPath = Paths.get(FileUtils.getTempDirectory().toString(), "windup_" + UUID.randomUUID().toString());
FileUtils.deleteDirectory(outputPath.toFile());
Files.createDirectories(outputPath);
Path outputPath = Paths.get(FileUtils.getTempDirectory().toString(), "windup_"
+ UUID.randomUUID().toString());
FileUtils.deleteDirectory(outputPath.toFile());
Files.createDirectories(outputPath);

WindupConfigurationModel config = GraphService.getConfigurationModel(context);
config.setInputPath(inputPath);
config.setSourceMode(true);
config.setOutputPath(outputPath.toString());
WindupConfigurationModel config = GraphService.getConfigurationModel(context);
config.setInputPath(inputPath);
config.setSourceMode(true);
config.setOutputPath(outputPath.toString());

inputPath.setProjectModel(pm);
pm.setRootFileModel(inputPath);
inputPath.setProjectModel(pm);
pm.setRootFileModel(inputPath);

try
{
Predicate<WindupRuleProvider> predicate = new Predicate<WindupRuleProvider>()
try
{
@Override
public boolean accept(WindupRuleProvider provider)
Predicate<WindupRuleProvider> predicate = new Predicate<WindupRuleProvider>()
{
return (provider.getPhase() != RulePhase.REPORT_GENERATION) &&
(provider.getPhase() != RulePhase.MIGRATION_RULES);
}
};
processor.execute(predicate);
}
catch (Exception e)
{
if (!e.getMessage().contains("CreateMainApplicationReport"))
throw e;
}

GraphService<InlineHintModel> hintService = new GraphService<>(context, InlineHintModel.class);
GraphService<ClassificationModel> classificationService = new GraphService<>(context, ClassificationModel.class);
@Override
public boolean accept(WindupRuleProvider provider)
{
return (provider.getPhase() != RulePhase.REPORT_GENERATION) &&
(provider.getPhase() != RulePhase.MIGRATION_RULES);
}
};
WindupConfiguration windupConfiguration = new WindupConfiguration()
.setRuleProviderFilter(predicate)
.setGraphContext(context);
processor.execute(windupConfiguration);
}
catch (Exception e)
{
if (!e.getMessage().contains("CreateMainApplicationReport"))
throw e;
}

GraphService<InlineHintModel> hintService = new GraphService<>(context, InlineHintModel.class);
GraphService<ClassificationModel> classificationService = new GraphService<>(context,
ClassificationModel.class);

Assert.assertEquals(2, provider.getXmlFileMatches().size());
List<InlineHintModel> hints = Iterators.asList(hintService.findAll());
Assert.assertEquals(2, hints.size());
List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll());
for (ClassificationModel model : classifications)
{
String classification = model.getClassification();
String string = classification.toString();
Assert.assertNotNull(string);
}
Assert.assertEquals(1, classifications.size());

Assert.assertEquals(2, provider.getXmlFileMatches().size());
List<InlineHintModel> hints = Iterators.asList(hintService.findAll());
Assert.assertEquals(2, hints.size());
List<ClassificationModel> classifications = Iterators.asList(classificationService.findAll());
for (ClassificationModel model : classifications) {
String classification = model.getClassification();
String string = classification.toString();
}
Assert.assertEquals(1, classifications.size());
}

@Singleton
Expand Down

0 comments on commit 14a3ac6

Please sign in to comment.