Skip to content

Commit

Permalink
Add grammer changes
Browse files Browse the repository at this point in the history
Add grammer changes to remove attributes and add params
  • Loading branch information
GDLMadushanka committed Nov 29, 2024
1 parent f527756 commit 744b93f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ VAR: 'var';
PAYLOAD: 'payload' | '$';
HEADERS: 'headers';
CONFIG: 'config';
ATTRIBUTES: 'attributes' | 'attr';
PARAMS: 'params';
PROPERTY: 'props' | 'properties';
AND: 'and' | '&&';
OR: 'or' | '||';
NOT: '!';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ factor
| payloadAccess
| headerAccess
| configAccess
| attributeAccess
| parameterAccess
| propertyAccess
| LPAREN expression RPAREN
;

Expand All @@ -50,8 +51,12 @@ headerAccess
: HEADERS propertyName
;

attributeAccess
: ATTRIBUTES (DOT ID propertyName)
parameterAccess
: PARAMS (DOT ID propertyName)
;

propertyAccess
: PROPERTY (DOT ID propertyName)
;

propertyName
Expand Down Expand Up @@ -126,7 +131,8 @@ filterComponent
| payloadAccess
| headerAccess
| configAccess
| attributeAccess
| parameterAccess
| propertyAccess
| functionCall
| stringOrOperator
;
Expand All @@ -144,4 +150,4 @@ functionCall
functionCallSuffix
: DOT ID LPAREN (expression (COMMA expression)*)? RPAREN // Method chaining
| jsonPathExpression
;
;
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public ExpressionNode visitFactor(ExpressionParser.FactorContext ctx) {
return visit(ctx.headerAccess());
} else if (ctx.configAccess() != null) {
return visit(ctx.configAccess());
} else if (ctx.attributeAccess() != null) {
return visit(ctx.attributeAccess());
} else if (ctx.propertyAccess() != null) {
return visit(ctx.propertyAccess());
} else if (ctx.parameterAccess() != null) {
return visit(ctx.parameterAccess());
}
return null;
}
Expand Down Expand Up @@ -410,8 +412,10 @@ public ExpressionNode visitFilterComponent(ExpressionParser.FilterComponentConte
return visit(ctx.headerAccess());
} else if (ctx.configAccess() != null) {
return visit(ctx.configAccess());
} else if (ctx.attributeAccess() != null) {
return visit(ctx.attributeAccess());
} else if (ctx.propertyAccess() != null) {
return visit(ctx.propertyAccess());
} else if (ctx.parameterAccess() != null) {
return visit(ctx.parameterAccess());
}
return null;
}
Expand Down Expand Up @@ -445,7 +449,7 @@ public ExpressionNode visitConfigAccess(ExpressionParser.ConfigAccessContext ctx
}

@Override
public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessContext ctx) {
public ExpressionNode visitPropertyAccess(ExpressionParser.PropertyAccessContext ctx) {
if (ctx.propertyName() != null) {
if (ctx.ID() != null) {
String scope = ctx.ID().getText();
Expand All @@ -454,6 +458,18 @@ public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessConte
return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), ExpressionConstants.AXIS2);
case SynapseConstants.SYNAPSE:
return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.SYNAPSE);
}
}
}
return null;
}

@Override
public ExpressionNode visitParameterAccess(ExpressionParser.ParameterAccessContext ctx) {
if (ctx.propertyName() != null) {
if (ctx.ID() != null) {
String scope = ctx.ID().getText();
switch (scope) {
case ExpressionConstants.QUERY_PARAM:
return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()),
ExpressionConstants.QUERY_PARAM);
Expand All @@ -468,6 +484,7 @@ public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessConte
return null;
}


@Override
public ExpressionNode visitConditionalExpression(ExpressionParser.ConditionalExpressionContext ctx) {
ExpressionNode condition = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,53 +144,53 @@ public void testTransportHeaderNumerical() throws Exception {

@Test
public void testAxis2Header() throws Exception {
SynapseExpression testPath = new SynapseExpression("attr.axis2.test");
SynapseExpression testPath = new SynapseExpression("props.axis2.test");
Assert.assertEquals("Sic Mundus", testPath.stringValueOf(synCtx));
}

@Test
public void testAxis2HeaderWithExpression() throws Exception {
SynapseExpression testPath = new SynapseExpression("attributes.axis2.test + \" \" " +
"+ attributes.axis2.test2");
SynapseExpression testPath = new SynapseExpression("properties.axis2.test + \" \" " +
"+ props.axis2.test2");
Assert.assertEquals("Sic Mundus Creatus Est", testPath.stringValueOf(synCtx));
}

@Test
public void testAxis2HeaderInFilter() throws Exception {
SynapseExpression testPath = new SynapseExpression("$..book[?(@.category == attributes.axis2.category)].title");
SynapseExpression testPath = new SynapseExpression("$..book[?(@.category == props.axis2.category)].title");
Assert.assertEquals("[\"The Diary of a Young Girl\"]", testPath.stringValueOf(synCtx));
}
@Test
public void testAxis2HeaderWithReservedName() throws Exception {
SynapseExpression testPath = new SynapseExpression("attributes.axis2.[\"empty\"]");
SynapseExpression testPath = new SynapseExpression("props.axis2.[\"empty\"]");
Assert.assertEquals("Thus the world was created", testPath.stringValueOf(synCtx));
}

@Test
public void testSynapseHeader() throws Exception {
SynapseExpression testPath = new SynapseExpression("attributes.synapse.phrase");
SynapseExpression testPath = new SynapseExpression("props.synapse.phrase");
Assert.assertEquals("Now I Am Become Death, the Destroyer of Worlds", testPath.stringValueOf(synCtx));
}

@Test
public void testSynapseHeaderWithFunction() throws Exception {
SynapseExpression testPath = new SynapseExpression("length(split(attributes.synapse.phrase, \" \"))");
SynapseExpression testPath = new SynapseExpression("length(split(properties.synapse.phrase, \" \"))");
Assert.assertEquals("9", testPath.stringValueOf(synCtx));
}

@Test
public void testSynapseHeaderInFilter() throws Exception {
SynapseExpression testPath = new SynapseExpression("$..book[?(@.title == attributes.synapse.[\"selected book\"])].price");
SynapseExpression testPath = new SynapseExpression("$..book[?(@.title == props.synapse.[\"selected book\"])].price");
Assert.assertEquals("[7.99]", testPath.stringValueOf(synCtx));
}

@Test
public void testNonExistingEmptyAndNull() throws Exception {
SynapseExpression testPath = new SynapseExpression("attributes.synapse.nonExisting");
SynapseExpression testPath = new SynapseExpression("props.synapse.nonExisting");
Assert.assertNull(testPath.stringValueOf(synCtx));
testPath = new SynapseExpression("attributes.synapse.[\"null\"]");
testPath = new SynapseExpression("props.synapse.[\"null\"]");
Assert.assertNull(testPath.stringValueOf(synCtx));
testPath = new SynapseExpression("attributes.synapse[\"empty\"]");
testPath = new SynapseExpression("props.synapse[\"empty\"]");
Assert.assertEquals("", testPath.stringValueOf(synCtx));
}
}

0 comments on commit 744b93f

Please sign in to comment.