Search in sources :

Example 26 with StackMachine

use of org.nhindirect.policy.impl.machine.StackMachine in project nhin-d by DirectProject.

the class StackMachineCompiler_compileTest method testCompile_simpleBinaryLiteralOperation_assertEntriesAndEvaluation.

public void testCompile_simpleBinaryLiteralOperation_assertEntriesAndEvaluation() throws Exception {
    // build the expression
    final PolicyValue<Integer> op1 = PolicyValueFactory.getInstance(1);
    final PolicyValue<Integer> op2 = PolicyValueFactory.getInstance(1);
    final LiteralPolicyExpression<Integer> expr1 = LiteralPolicyExpressionFactory.getInstance(op1);
    final LiteralPolicyExpression<Integer> expr2 = LiteralPolicyExpressionFactory.getInstance(op2);
    final Vector<PolicyExpression> operands = new Vector<PolicyExpression>();
    operands.add(expr1);
    operands.add(expr2);
    final OperationPolicyExpression oper = OperationPolicyExpressionFactory.getInstance(PolicyOperator.EQUALS, operands);
    final StackMachineCompiler compiler = new StackMachineCompiler();
    final Vector<Opcode> entries = compiler.compile(null, oper);
    assertEquals(3, entries.size());
    assertEquals(op1, ((StackMachineEntry) entries.get(0)).getValue());
    assertEquals(op2, ((StackMachineEntry) entries.get(1)).getValue());
    assertEquals(PolicyOperator.EQUALS, ((StackMachineEntry) entries.get(2)).getOperator());
    // execute the compiled expression in the stack machine
    final StackMachine machine = new StackMachine();
    final Boolean evalVal = machine.evaluate(entries);
    assertTrue(evalVal);
}
Also used : StackMachine(org.nhindirect.policy.impl.machine.StackMachine) Opcode(org.nhindirect.policy.Opcode) LiteralPolicyExpression(org.nhindirect.policy.LiteralPolicyExpression) PolicyExpression(org.nhindirect.policy.PolicyExpression) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression) StackMachineCompiler(org.nhindirect.policy.impl.machine.StackMachineCompiler) Vector(java.util.Vector) OperationPolicyExpression(org.nhindirect.policy.OperationPolicyExpression)

Example 27 with StackMachine

use of org.nhindirect.policy.impl.machine.StackMachine in project nhin-d by DirectProject.

the class StackMachine_createOperatorExecutorTest method testCreateLogicalAndOperator.

public void testCreateLogicalAndOperator() throws Exception {
    StackMachine stMachine = new StackMachine();
    BinaryBooleanPolicyOperatorExecutor<?, ?> executor = BinaryBooleanPolicyOperatorExecutor.class.cast(stMachine.createOperatorExecutor(PolicyOperator.LOGICAL_AND, PolicyValueFactory.getInstance("12345"), PolicyValueFactory.getInstance("12345")));
    assertNotNull(executor);
}
Also used : StackMachine(org.nhindirect.policy.impl.machine.StackMachine)

Example 28 with StackMachine

use of org.nhindirect.policy.impl.machine.StackMachine in project nhin-d by DirectProject.

the class StackMachine_createOperatorExecutorTest method testCreateRegExOperator.

public void testCreateRegExOperator() throws Exception {
    StackMachine stMachine = new StackMachine();
    BinaryBooleanPolicyOperatorExecutor<?, ?> executor = BinaryBooleanPolicyOperatorExecutor.class.cast(stMachine.createOperatorExecutor(PolicyOperator.REG_EX, PolicyValueFactory.getInstance("12345"), PolicyValueFactory.getInstance("12345")));
    assertNotNull(executor);
}
Also used : StackMachine(org.nhindirect.policy.impl.machine.StackMachine)

Example 29 with StackMachine

use of org.nhindirect.policy.impl.machine.StackMachine in project nhin-d by DirectProject.

the class StackMachine_createOperatorExecutorTest method testCreateBitwiseOrOperator.

public void testCreateBitwiseOrOperator() throws Exception {
    StackMachine stMachine = new StackMachine();
    BinaryIntegerPolicyOperatorExecutor<?, ?> executor = BinaryIntegerPolicyOperatorExecutor.class.cast(stMachine.createOperatorExecutor(PolicyOperator.BITWISE_OR, PolicyValueFactory.getInstance(12345), PolicyValueFactory.getInstance(12345)));
    assertNotNull(executor);
}
Also used : StackMachine(org.nhindirect.policy.impl.machine.StackMachine)

Example 30 with StackMachine

use of org.nhindirect.policy.impl.machine.StackMachine in project nhin-d by DirectProject.

the class StackMachine_createOperatorExecutorTest method testCreateBitwiseAndOperator.

public void testCreateBitwiseAndOperator() throws Exception {
    StackMachine stMachine = new StackMachine();
    BinaryIntegerPolicyOperatorExecutor<?, ?> executor = BinaryIntegerPolicyOperatorExecutor.class.cast(stMachine.createOperatorExecutor(PolicyOperator.BITWISE_AND, PolicyValueFactory.getInstance(12345), PolicyValueFactory.getInstance(12345)));
    assertNotNull(executor);
}
Also used : StackMachine(org.nhindirect.policy.impl.machine.StackMachine)

Aggregations

StackMachine (org.nhindirect.policy.impl.machine.StackMachine)52 Vector (java.util.Vector)43 Opcode (org.nhindirect.policy.Opcode)43 StackMachineEntry (org.nhindirect.policy.impl.machine.StackMachineEntry)40 LiteralPolicyExpression (org.nhindirect.policy.LiteralPolicyExpression)5 OperationPolicyExpression (org.nhindirect.policy.OperationPolicyExpression)5 PolicyExpression (org.nhindirect.policy.PolicyExpression)5 StackMachineCompiler (org.nhindirect.policy.impl.machine.StackMachineCompiler)5 X509Certificate (java.security.cert.X509Certificate)3 ExtendedKeyUsageExtensionField (org.nhindirect.policy.x509.ExtendedKeyUsageExtensionField)3 KeyUsageExtensionField (org.nhindirect.policy.x509.KeyUsageExtensionField)3 PolicyProcessException (org.nhindirect.policy.PolicyProcessException)2