use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_requiredCertField_validateTokens.
public void testBuildExpression_requiredCertField_validateTokens() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
final InputStream stream = IOUtils.toInputStream("X509.TBS.EXTENSION.SubjectKeyIdentifier+ = 1.3.2.3");
Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
// now build expressions
PolicyExpression expression = parser.buildExpression(tokens.iterator());
// check that the expression is an equals
assertNotNull(expression);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.EQUALS, operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be a literal and an operation
expression = operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
assertTrue(expression instanceof SubjectKeyIdentifierExtensionField);
assertTrue(((SubjectKeyIdentifierExtensionField) expression).isRequired());
expression = operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
stream.close();
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_extensionName_keyUsage_validatePolicyExpression.
public void testBuildExpression_extensionName_keyUsage_validatePolicyExpression() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/lexiconWithKeyUsage.txt"));
final Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
// now build expressions
PolicyExpression expression = parser.buildExpression(tokens.iterator());
// check that the expression is an equals
assertNotNull(expression);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.EQUALS, operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be a cert reference and a literal
expression = operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
assertTrue(expression instanceof KeyUsageExtensionField);
expression = operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_tinaryExpression_operatorExpressionOperands_validatePolicyExpression.
public void testBuildExpression_tinaryExpression_operatorExpressionOperands_validatePolicyExpression() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
InputStream stream = IOUtils.toInputStream("false = !true && !false");
Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
// now build expressions
PolicyExpression expression = parser.buildExpression(tokens.iterator());
// check that the expression is an equals
assertNotNull(expression);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.LOGICAL_AND, operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be two operations
OperationPolicyExpression subOperation = (OperationPolicyExpression) operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.OPERATION, subOperation.getExpressionType());
assertEquals(PolicyOperator.EQUALS, subOperation.getPolicyOperator());
expression = subOperation.getOperands().get(0);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("false", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
OperationPolicyExpression subSubOperation = (OperationPolicyExpression) subOperation.getOperands().get(1);
assertEquals(PolicyExpressionType.OPERATION, subSubOperation.getExpressionType());
assertEquals(PolicyOperator.LOGICAL_NOT, subSubOperation.getPolicyOperator());
subOperation = (OperationPolicyExpression) operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.OPERATION, subOperation.getExpressionType());
assertEquals(PolicyOperator.LOGICAL_NOT, subOperation.getPolicyOperator());
expression = subOperation.getOperands().get(0);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("false", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_tbsFieldName_rdnAttribute_validatePolicyExpression.
public void testBuildExpression_tbsFieldName_rdnAttribute_validatePolicyExpression() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/literalWithSpaces.txt"));
final Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
// now build expressions
PolicyExpression expression = parser.buildExpression(tokens.iterator());
// check that the expression is an equals
assertNotNull(expression);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.EQUALS, operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be a cert reference and a literal
expression = operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.REFERENCE, expression.getExpressionType());
assertTrue(expression instanceof SubjectAttributeField);
expression = operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("United States", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
use of org.nhindirect.policy.PolicyExpression in project nhin-d by DirectProject.
the class SimpleTextV1LexiconPolicyParser_buildExpressionTest method testBuildExpression_simpleExpression_validatePolicyExpression.
public void testBuildExpression_simpleExpression_validatePolicyExpression() throws Exception {
final SimpleTextV1LexiconPolicyParser parser = new SimpleTextV1LexiconPolicyParser();
final InputStream stream = FileUtils.openInputStream(new File("./src/test/resources/policies/simpleLexiconSamp1.txt"));
final Vector<SimpleTextV1LexiconPolicyParser.TokenTypeAssociation> tokens = parser.parseToTokens(stream);
// now build expressions
PolicyExpression expression = parser.buildExpression(tokens.iterator());
// check that the expression is a logical and
assertNotNull(expression);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.LOGICAL_AND, operationExpression.getPolicyOperator());
// now break down the operands which should each be a operator expressions
// operator 1
// should be an equals operator expressions
expression = operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression param1operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.EQUALS, param1operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be two literals
expression = param1operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
expression = param1operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("2", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
// operator 2
// should be an equals operator expressions
expression = operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.OPERATION, expression.getExpressionType());
OperationPolicyExpression param2operationExpression = (OperationPolicyExpression) expression;
assertEquals(PolicyOperator.NOT_EQUALS, param2operationExpression.getPolicyOperator());
// break down the sub operation parameters... should be two literals
expression = param2operationExpression.getOperands().get(0);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("2", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
expression = param2operationExpression.getOperands().get(1);
assertEquals(PolicyExpressionType.LITERAL, expression.getExpressionType());
assertEquals("1", ((LiteralPolicyExpression<?>) expression).getPolicyValue().getPolicyValue());
}
Aggregations