Skip to content

Commit

Permalink
Checked parser and tests so the correct line number is thrown.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Keiner committed Feb 21, 2019
1 parent 540e7ca commit 95f79fe
Show file tree
Hide file tree
Showing 46 changed files with 369 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static List<Command> parse(final Mark context, final Node actionNode)
// Check if the name is a permitted action item
if (!Constants.isPermittedActionItem(itemName))
{
throw new ParserException("Node", actionNode.getStartMark(), " contains a not permitted action item",
throw new ParserException("Node", context, " contains a not permitted action item",
((ScalarNode) item.getKeyNode()).getStartMark());
}
AbstractActionSubItemParser actionItemParser = null;
Expand All @@ -90,8 +90,8 @@ public static List<Command> parse(final Mark context, final Node actionNode)
}
else
{
throw new ParserException("Node", actionNode.getStartMark(), " defines a Name but not as first item.",
((ScalarNode) item.getKeyNode()).getStartMark());
throw new ParserException("Node", context, " defines a Name but not as first item.",
item.getKeyNode().getStartMark());
}

case Constants.REQUEST:
Expand All @@ -105,9 +105,9 @@ public static List<Command> parse(final Mark context, final Node actionNode)
}
else
{
throw new ParserException("Node", actionNode.getStartMark(),
throw new ParserException("Node", context,
" defines a request after another request, a response or a subrequest but must be defined before them.",
((ScalarNode) item.getKeyNode()).getStartMark());
item.getKeyNode().getStartMark());
}

case Constants.RESPONSE:
Expand All @@ -121,9 +121,9 @@ public static List<Command> parse(final Mark context, final Node actionNode)
}
else
{
throw new ParserException("Node", actionNode.getStartMark(),
throw new ParserException("Node", context,
" defines a response after another response or a subrequest but must be defined before it.",
((ScalarNode) item.getKeyNode()).getStartMark());
item.getKeyNode().getStartMark());

}

Expand All @@ -135,8 +135,7 @@ public static List<Command> parse(final Mark context, final Node actionNode)

default:
// We didn't find something fitting, so throw an Exception
throw new ParserException("Node at", actionNode.getStartMark(), " is permitted but unknown",
item.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contains a permitted but unknown item", item.getKeyNode().getStartMark());
}

// If we specified an actionItemParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.parser.ParserException;

import com.gargoylesoftware.htmlunit.util.NameValuePair;
Expand Down Expand Up @@ -68,8 +67,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node requestN
// Check if the name is a permitted action item
if (!Constants.isPermittedRequestItem(itemName))
{
throw new ParserException("Node", requestNode.getStartMark(), " contains a not permitted request item",
((ScalarNode) item.getKeyNode()).getStartMark());
throw new ParserException("Node", context, " contains a not permitted request item", item.getKeyNode().getStartMark());
}

// We generally want to read the value of the fieldName but assign it to different variables
Expand Down Expand Up @@ -116,7 +114,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node requestN

default:
// We didn't find something fitting, so throw an Exception
throw new ParserException("Node", requestNode.getStartMark(), " containst a permitted but unknown request item",
throw new ParserException("Node", context, " contains a permitted but unknown request item",
item.getKeyNode().getStartMark());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node response
// Check if the name is a permitted action item
if (!Constants.isPermittedResponseItem(itemName))
{
throw new ParserException("Node", responseNode.getStartMark(), " contains a not permitted response item",
item.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contains a not permitted response item", item.getKeyNode().getStartMark());
}

switch (itemName)
Expand All @@ -86,7 +85,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node response

default:
// We didn't find something fitting, so throw an Exception
throw new ParserException("Node", responseNode.getStartMark(), " contains a permitted but unknown response item",
throw new ParserException("Node", context, " contains a permitted but unknown response item",
item.getKeyNode().getStartMark());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ protected Validator parseSingleValidator(final Mark context, final Node validati
// Verify that an object was used
if (!(validationNodeWrapper instanceof MappingNode))
{
throw new ParserException("Node at", context, " is " + validationNodeWrapper.getNodeId() + " but needs to be an object",
throw new ParserException("Node", context,
" contains a " + validationNodeWrapper.getNodeId() + " but it must contain an object",
validationNodeWrapper.getStartMark());
}
String validationName = "";
Expand All @@ -81,8 +82,7 @@ protected Validator parseSingleValidator(final Mark context, final Node validati
// Verify the validation is an object
if (!(validationContent instanceof MappingNode))
{
throw new ParserException("Node", validation.getKeyNode().getStartMark(),
" contains a " + validationContent.getNodeId() + " but needs to be an object",
throw new ParserException("Node", context, " contains a " + validationContent.getNodeId() + " but needs to be an object",
validationContent.getStartMark());
}
final List<NodeTuple> singleValidationContentItems = ((MappingNode) validationContent).getValue();
Expand All @@ -96,11 +96,10 @@ protected Validator parseSingleValidator(final Mark context, final Node validati
// Verify, that no extractor was parsed already
if (extractor != null)
{
throw new ParserException("Node", validationContent.getStartMark(),
" contains two definitions of an extractor but only one is allowed.",
throw new ParserException("Node", context, " contains two definitions of an extractor but only one is allowed.",
contentItem.getKeyNode().getStartMark());
}
extractor = new ExtractorParser(contentKey).parse(validationContent.getStartMark(), singleValidationContentItems);
extractor = new ExtractorParser(contentKey).parse(context, singleValidationContentItems);
XltLogger.runTimeLogger.debug("Extraction Mode is " + extractor);

}
Expand All @@ -110,26 +109,25 @@ else if (Constants.isPermittedValidationMethod(contentKey))
// Verify, that an extractor was parsed already
if (extractor == null)
{
throw new ParserException("Node", validationContent.getStartMark(),
throw new ParserException("Node", context,
" contains a definition of a validation method but this cannot be parsed before an extractor was defined.",
contentItem.getKeyNode().getStartMark());
}
// Verify, that no validation was parsed already
if (validationMethod != null)
{
throw new ParserException("Node", validationContent.getStartMark(),
throw new ParserException("Node", context,
" contains two definitions of validation methods but only one is allowed.",
contentItem.getKeyNode().getStartMark());
}
// Parse the validation method
validationMethod = new ValidatorParser(contentKey).parse(validationContent.getStartMark(), contentItem.getValueNode());
validationMethod = new ValidatorParser(contentKey).parse(context, contentItem.getValueNode());
XltLogger.runTimeLogger.debug("Validation Method is " + validationMethod);
}
// If it is not Group OR Group and extractor is null, throw an error
else if (!Constants.GROUP.equals(contentKey) || extractor == null)
{
throw new ParserException("Node", validationContent.getStartMark(), " contains an unknown item.",
contentItem.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contains an unknown item.", contentItem.getKeyNode().getStartMark());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node subreque
// Verify that we have an array
if (!(subrequestNode instanceof SequenceNode))
{
throw new ParserException("Node at", context, " is " + subrequestNode.getNodeId().toString() + " but needs to be an array",
throw new ParserException("Node", context, " contains a " + subrequestNode.getNodeId() + " but it must contain an array",
subrequestNode.getStartMark());
}
// Initialize Variables
Expand All @@ -51,8 +51,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node subreque
// Verify that an array was used and not an object
if (!(subrequestWrapper instanceof MappingNode))
{
throw new ParserException("Node at", subrequestNode.getStartMark(),
" is " + subrequestWrapper.getNodeId().toString() + " but needs to be a mapping",
throw new ParserException("Node", context, " contains " + subrequestWrapper.getNodeId() + " but it must contain a mapping",
subrequestWrapper.getStartMark());
}
final List<NodeTuple> subrequestList = ((MappingNode) subrequestWrapper).getValue();
Expand All @@ -73,8 +72,7 @@ public List<AbstractActionSubItem> parse(final Mark context, final Node subreque
break;

default:
throw new ParserException("Node", subrequestWrapper.getStartMark(), " contains an unknown item.",
subrequest.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contains an unknown item.", subrequest.getKeyNode().getStartMark());
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)
// Verify the node is an ObjectNode or a NullNode
if (!(xhrNode instanceof MappingNode))
{
throw new ParserException("Node", context, " contains a " + xhrNode.getNodeId().toString() + " but it must contain a mapping",
throw new ParserException("Node", context, " contains a " + xhrNode.getNodeId() + " but it must contain a mapping",
xhrNode.getStartMark());
}
// Initialize variables
Expand All @@ -55,8 +55,7 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)
// Check if the name is a permitted action item
if (!Constants.isPermittedActionItem(itemName))
{
throw new ParserException("Node", xhrNode.getStartMark(), " contans a not permitted Xhr Action item",
item.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contans a not permitted Xhr Action item", item.getKeyNode().getStartMark());
}
AbstractActionSubItem actionItem = null;

Expand All @@ -78,7 +77,7 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)
}
else
{
throw new ParserException("Node", xhrNode.getStartMark(), " defines a Name but not as first item.",
throw new ParserException("Node", context, " defines a Name but not as first item.",
item.getKeyNode().getStartMark());
}

Expand All @@ -95,15 +94,14 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)
}
else
{
throw new ParserException("Node", xhrNode.getStartMark(),
"contains an item, that could not be converted to a request object.",
throw new ParserException("Node", context, "contains an item, that could not be converted to a request object.",
item.getValueNode().getStartMark());
}
break;
}
else
{
throw new ParserException("Node", xhrNode.getStartMark(),
throw new ParserException("Node", context,
" defines a request after another request, a response or a subrequest, which isn't allowed.",
item.getKeyNode().getStartMark());
}
Expand All @@ -119,7 +117,7 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)
}
else
{
throw new ParserException("Node", xhrNode.getStartMark(),
throw new ParserException("Node", context,
" defines a response after another response or a subrequest, which isn't allowed.",
item.getKeyNode().getStartMark());
}
Expand All @@ -132,8 +130,7 @@ public XhrSubrequest parse(final Mark context, final Node xhrNode)

default:
// We didn't find something fitting, so throw an Exception
throw new ParserException("Node", xhrNode.getStartMark(), " contains a permitted but unknown item",
item.getKeyNode().getStartMark());
throw new ParserException("Node", context, " contains a permitted but unknown item", item.getKeyNode().getStartMark());
}
if (actionItem != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static List<Command> parse(final Mark context, final NodeTuple node)

default:
// We didn't find something fitting, so throw an Exception
throw new ParserException("Node at", node.getKeyNode().getStartMark(), " is permitted but unknown", null);
throw new ParserException("Node", context, " contains a permitted but unknown list item", node.getKeyNode().getStartMark());
}

return scriptItems;
Expand Down

This file was deleted.

Loading

0 comments on commit 95f79fe

Please sign in to comment.