use of org.nhindirect.policy.OperationPolicyExpression in project nhin-d by DirectProject.
the class JavaSerializedObjectLexiconPolicyParser_serializeTest method testSerialize_simpleExpression_validateExpression.
public void testSerialize_simpleExpression_validateExpression() throws Exception {
final JavaSerializedObjectLexiconPolicyParser parser = new JavaSerializedObjectLexiconPolicyParser();
// build the expression
final PolicyValue<Boolean> op1 = PolicyValueFactory.getInstance(true);
final LiteralPolicyExpression<Boolean> expr = LiteralPolicyExpressionFactory.getInstance(op1);
final Vector<PolicyExpression> operands = new Vector<PolicyExpression>();
operands.add(expr);
final OperationPolicyExpression oper = OperationPolicyExpressionFactory.getInstance(PolicyOperator.LOGICAL_NOT, operands);
// serialize
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
parser.serialize(oper, outStream);
assertTrue(outStream.size() > 0);
String serialzied = new String(outStream.toByteArray());
System.out.println(serialzied);
// deserialize
final ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
final PolicyExpression deserExpression = parser.parse(inStream);
assertNotNull(deserExpression);
assertEquals(PolicyExpressionType.OPERATION, deserExpression.getExpressionType());
}
Aggregations