Skip to content

Commit

Permalink
#6 Placeholder for unique scenarios was added
Browse files Browse the repository at this point in the history
  • Loading branch information
mkolisnyk committed Jan 5, 2015
1 parent 44c5603 commit 437e595
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@
<artifactId>jersey-common</artifactId>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.github.kristofa</groupId>
<artifactId>mock-http-server</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@ public Map<String, List<String>> generateTestData() throws Exception {
+ " ValidInput varchar(5))");

for (InputRecord record : expanded) {
String validInput = "false";
if (record.isValidInput()) {
validInput = "true";
}
db.execute(String.format("INSERT INTO input (Name, Type, Value, Condition, ValidInput)"
+ " VALUES ('%s','%s','%s','%s','%s')",
record.getName(),
record.getType(),
record.getValue(),
record.getCondition(),
validInput));
"" + record.isValidInput()));
}

String[] names = this.getUniqueNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
Expand Down Expand Up @@ -73,6 +75,29 @@ private String generateTestData(Map<String, List<String>> testData, boolean posi
return content;
}

private String generateUniqueScenarioData(
Map<String, List<String>> testData,
List<InputRecord> input,
String[] uniqueFields) {
System.out.println(testData.size());
System.out.println(input.size());
System.out.println(uniqueFields.length);
return "";
}

private String[] getFieldsWithUniqueAttributes(List<InputRecord> input) {
Set<String> fields = new HashSet<String>();
String[] result;
for (InputRecord record : input) {
if (record.isUnique()) {
fields.add(record.getName());
}
}
result = new String[fields.size()];
result = fields.toArray(result);
return result;
}

private String generatePreRequisites(ArrayList<DocumentSection<?>> preRequisites) throws Exception {
String result = "";
if (preRequisites != null) {
Expand Down Expand Up @@ -104,6 +129,19 @@ public String generate() throws Exception {
content += this.getSections().get(Tokens.ERROR_OUTPUT_TOKEN).get(0).generate() + ls;
content += StringUtils.repeat(" ", offset) + "Examples:"
+ ls + this.generateTestData(testData, false) + ls;
String[] uniqueRecords = getFieldsWithUniqueAttributes(input.getInputs());
if (uniqueRecords.length > 0) {
content += StringUtils.repeat(" ", offset) + "Scenario Outline: " + this.getName()
+ " unique values test" + ls;
content += this.generatePreRequisites(this.getSections().get(Tokens.PREREQUISITES_TOKEN));

content += this.getSections().get(Tokens.ACTION_TOKEN).get(0).generate() + ls;
content += this.getSections().get(Tokens.VALID_OUTPUT_TOKEN).get(0).generate() + ls;
content += this.getSections().get(Tokens.ACTION_TOKEN).get(0).generate() + ls;
content += this.getSections().get(Tokens.ERROR_OUTPUT_TOKEN).get(0).generate() + ls;
content += StringUtils.repeat(" ", offset) + "Examples:"
+ ls + this.generateUniqueScenarioData(testData, input.getInputs(), uniqueRecords) + ls;
}
return content;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void setUp() throws Exception {
List<InputRecord> initialData = new ArrayList<InputRecord>()
{
{
add(new InputRecord("Name", "string", "(\\d)-(\\S{1,3})", "", true));
add(new InputRecord("Name", "string", "(\\d)-([A-Za-z]{1,3})", "", true));
add(new InputRecord("Date", "date", "MM/dd/yyyy", "", true));
add(new InputRecord("Count", "int", "[0;100)", "", true));
}
Expand Down

0 comments on commit 437e595

Please sign in to comment.