Search in sources :

Example 16 with OperationPolicyExpression

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Vector(java.util.Vector) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Aggregations

LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)16 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)16 PolicyExpression (org.nhindirect.policy.PolicyExpression)16 Vector (java.util.Vector)9 InputStream (java.io.InputStream)7 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)7 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)6 Opcode (org.nhindirect.policy.Opcode)5 StackMachine (org.nhindirect.policy.impl.machine.StackMachine)5 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 File (java.io.File)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 X509Certificate (java.security.cert.X509Certificate)3 StackMachineEntry (org.nhindirect.policy.impl.machine.StackMachineEntry)3 XMLLexiconPolicyParser (org.nhindirect.policy.impl.XMLLexiconPolicyParser)2 SubjectAttributeField (org.nhindirect.policy.x509.SubjectAttributeField)1 SubjectKeyIdentifierExtensionField (org.nhindirect.policy.x509.SubjectKeyIdentifierExtensionField)1 X509Field (org.nhindirect.policy.x509.X509Field)1