@Test public void testEvaluate() { FirstMatchChain fmc = new FirstMatchChain(ImmutableList.of(BooleanExprs.FALSE, BooleanExprs.TRUE)); Result result = fmc.evaluate( Environment.builder(new Configuration("host", ConfigurationFormat.JUNIPER)).build()); assertThat(result, equalTo(new Result(false, false, false, false))); fmc = new FirstMatchChain(ImmutableList.of(BooleanExprs.TRUE, BooleanExprs.FALSE)); result = fmc.evaluate( Environment.builder(new Configuration("host", ConfigurationFormat.JUNIPER)).build()); assertThat(result, equalTo(new Result(true, false, false, false))); }
@Override public Result evaluate(Environment environment) { for (BooleanExpr subroutine : _subroutines) { Result subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } }
FirstMatchChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { for (BooleanExpr subroutine : _subroutines) { Result subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } }
FirstMatchChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { for (BooleanExpr subroutine : _subroutines) { Result subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } FirstMatchChain(List<BooleanExpr> subroutines); }
FirstMatchChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { for (BooleanExpr subroutine : _subroutines) { Result subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } FirstMatchChain(List<BooleanExpr> subroutines); @Override T accept(BooleanExprVisitor<T, U> visitor, U arg); @Override Set<String> collectSources(
      Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w); @Override Result evaluate(Environment environment); @Nonnull @JsonProperty(PROP_SUBROUTINES) List<BooleanExpr> getSubroutines(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString(); }
FirstMatchChain extends BooleanExpr { @Override public Result evaluate(Environment environment) { for (BooleanExpr subroutine : _subroutines) { Result subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { return subroutineResult; } else if (!subroutineResult.getFallThrough()) { return subroutineResult.toBuilder().setReturn(false).build(); } } String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); Result defaultPolicyResult = callDefaultPolicy.evaluate(environment); return defaultPolicyResult.toBuilder().setReturn(false).build(); } else { throw new BatfishException("Default policy is not set"); } } FirstMatchChain(List<BooleanExpr> subroutines); @Override T accept(BooleanExprVisitor<T, U> visitor, U arg); @Override Set<String> collectSources(
      Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w); @Override Result evaluate(Environment environment); @Nonnull @JsonProperty(PROP_SUBROUTINES) List<BooleanExpr> getSubroutines(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override String toString();  }