|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| XMLRenderer.java | 90% | 92% | 100% | 91,9% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) 2003, Marco Jansen / Contrado Technologies (http://www.contrado.nl)
|
|
| 3 |
*
|
|
| 4 |
* This program is free software; you can redistribute it and/or
|
|
| 5 |
* modify it under the terms of the GNU General Public License as
|
|
| 6 |
* published by the Free Software Foundation; either version 2 of the
|
|
| 7 |
* License, or (at your option) any later version.
|
|
| 8 |
*
|
|
| 9 |
* This program is distributed in the hope that it will be useful, but
|
|
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
| 12 |
* General Public License for more details.
|
|
| 13 |
*/
|
|
| 14 |
|
|
| 15 |
package net.sourceforge.anttestsetgen.renderer;
|
|
| 16 |
|
|
| 17 |
import net.sourceforge.anttestsetgen.AntTestSetGenUtil;
|
|
| 18 |
import net.sourceforge.anttestsetgen.Entry;
|
|
| 19 |
import net.sourceforge.anttestsetgen.Output;
|
|
| 20 |
import net.sourceforge.anttestsetgen.TestSet;
|
|
| 21 |
import net.sourceforge.anttestsetgen.TestSetGenerator;
|
|
| 22 |
import org.apache.tools.ant.BuildException;
|
|
| 23 |
import org.apache.tools.ant.Project;
|
|
| 24 |
|
|
| 25 |
import java.io.BufferedWriter;
|
|
| 26 |
import java.io.FileWriter;
|
|
| 27 |
import java.io.IOException;
|
|
| 28 |
import java.io.PrintWriter;
|
|
| 29 |
import java.util.Iterator;
|
|
| 30 |
import java.util.List;
|
|
| 31 |
|
|
| 32 |
public class XMLRenderer implements Renderer { |
|
| 33 |
|
|
| 34 | 26 |
public void render(TestSetGenerator testSetGenerator, Output output) { |
| 35 |
|
|
| 36 | 26 |
AntTestSetGenUtil.requiredCheck("file", output.getFile());
|
| 37 | 24 |
AntTestSetGenUtil.requiredCheck("root", output.getRoot());
|
| 38 |
|
|
| 39 | 22 |
String fileName = output.getFile(); |
| 40 |
|
|
| 41 | 22 |
try {
|
| 42 | 22 |
PrintWriter outputFile = new PrintWriter(new BufferedWriter(new FileWriter(fileName))); |
| 43 | 22 |
printTestSets(testSetGenerator, output, outputFile); |
| 44 | 22 |
outputFile.close(); |
| 45 | 22 |
testSetGenerator.log("TestSet rendered to XML File " + fileName, Project.MSG_INFO);
|
| 46 |
|
|
| 47 |
} catch (IOException e) {
|
|
| 48 | 0 |
throw new BuildException("Could not create XML File: " + fileName); |
| 49 |
} |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/**
|
|
| 53 |
* Print the results of a test set.
|
|
| 54 |
*
|
|
| 55 |
* @param outputFile The property files where the results needs to be added to
|
|
| 56 |
*/
|
|
| 57 | 22 |
private static void printTestSets(TestSetGenerator testSetGenerator, Output output, PrintWriter outputFile) { |
| 58 | 22 |
outputFile.println("<" + output.getRoot() + ">"); |
| 59 | 22 |
for (Iterator iterator = testSetGenerator.getTestSets().iterator(); iterator.hasNext();) {
|
| 60 | 44 |
TestSet testSet = (TestSet) iterator.next(); |
| 61 |
|
|
| 62 | 44 |
for (int i = 0; i < testSet.getEntries().size(); i++) { |
| 63 | 88 |
Entry entry = (Entry) testSet.getEntries().get(i); |
| 64 |
|
|
| 65 | 88 |
if (entry.getValues().size() == 0) {
|
| 66 |
// Nothing Found
|
|
| 67 | 0 |
outputFile.println(" <" + entry.getKey() + "/>"); |
| 68 | 88 |
} else if (TestSet.SELECT_FIRST_ROW.equals(testSet.getRowtoselect())) { |
| 69 |
// One found
|
|
| 70 | 44 |
outputFile.println(" <" + entry.getKey() + ">" + entry.getValues().get(0) + "</" + entry.getKey() + ">"); |
| 71 |
} else {
|
|
| 72 |
// Multiple found
|
|
| 73 | 44 |
outputFile.println(" <" + entry.getKey() + ">"); |
| 74 | 44 |
List values = entry.getValues(); |
| 75 | 44 |
for (int j = 0; j < values.size(); j++) { |
| 76 | 276 |
String value = (String) values.get(j); |
| 77 | 276 |
outputFile.println(" <" + entry.getXmlType() + ">" + value + "</" + entry.getXmlType() + ">"); |
| 78 |
} |
|
| 79 | 44 |
outputFile.println(" </" + entry.getKey() + ">"); |
| 80 |
} |
|
| 81 |
} |
|
| 82 |
} |
|
| 83 | 22 |
outputFile.println("</" + output.getRoot() + ">"); |
| 84 |
} |
|
| 85 |
|
|
| 86 |
} |
|
| 87 |
|
|
||||||||||