@Test(expected = IllegalArgumentException.class) public void testApplyPolicy_controlPointDisabled() throws ControlPointApiException { Mockito.when(cpService.isEnabled()).thenReturn(false); controller.applyPolicy("the policy", 123L, null); }
private void applyPolicy(final String policy, final SavedSnapshot snapshot) throws ControlPointApiException { final TypedStateToken stateToken = snapshot.getStateTokens().stream() .filter(x -> x.getType().equals(TypedStateToken.StateTokenType.QUERY)) .findFirst() .orElseThrow(() -> new RuntimeException("Saved Snapshot has no associated state token")); final AciParameters aciParams = new AciParameters(); aciParameterHandler.addSecurityInfo(aciParams); final String securityInfo = aciParams.get(QueryParams.SecurityInfo.name()); controlPointService.applyPolicy(policy, stateToken.getStateToken(), securityInfo); }
ControlPointPolicyController { private void applyPolicy(final String policy, final SavedSnapshot snapshot) throws ControlPointApiException { final TypedStateToken stateToken = snapshot.getStateTokens().stream() .filter(x -> x.getType().equals(TypedStateToken.StateTokenType.QUERY)) .findFirst() .orElseThrow(() -> new RuntimeException("Saved Snapshot has no associated state token")); final AciParameters aciParams = new AciParameters(); aciParameterHandler.addSecurityInfo(aciParams); final String securityInfo = aciParams.get(QueryParams.SecurityInfo.name()); controlPointService.applyPolicy(policy, stateToken.getStateToken(), securityInfo); } }
ControlPointPolicyController { private void applyPolicy(final String policy, final SavedSnapshot snapshot) throws ControlPointApiException { final TypedStateToken stateToken = snapshot.getStateTokens().stream() .filter(x -> x.getType().equals(TypedStateToken.StateTokenType.QUERY)) .findFirst() .orElseThrow(() -> new RuntimeException("Saved Snapshot has no associated state token")); final AciParameters aciParams = new AciParameters(); aciParameterHandler.addSecurityInfo(aciParams); final String securityInfo = aciParams.get(QueryParams.SecurityInfo.name()); controlPointService.applyPolicy(policy, stateToken.getStateToken(), securityInfo); } @Autowired  ControlPointPolicyController(
        final ControlPointService controlPointService,
        final SavedSearchService<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotService,
        final HavenSearchAciParameterHandler aciParameterHandler
    ); }
ControlPointPolicyController { private void applyPolicy(final String policy, final SavedSnapshot snapshot) throws ControlPointApiException { final TypedStateToken stateToken = snapshot.getStateTokens().stream() .filter(x -> x.getType().equals(TypedStateToken.StateTokenType.QUERY)) .findFirst() .orElseThrow(() -> new RuntimeException("Saved Snapshot has no associated state token")); final AciParameters aciParams = new AciParameters(); aciParameterHandler.addSecurityInfo(aciParams); final String securityInfo = aciParams.get(QueryParams.SecurityInfo.name()); controlPointService.applyPolicy(policy, stateToken.getStateToken(), securityInfo); } @Autowired  ControlPointPolicyController(
        final ControlPointService controlPointService,
        final SavedSearchService<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotService,
        final HavenSearchAciParameterHandler aciParameterHandler
    ); @RequestMapping(method = RequestMethod.GET) List<ControlPointPolicy> getPolicies(); @RequestMapping(value = APPLY_PATH, method = RequestMethod.POST) void applyPolicy(
        @RequestParam(value = POLICY_PARAM) final String policy,
        @RequestParam(value = SAVED_SNAPSHOT_ID_PARAM, required = false) final Long snapshotId,
        @RequestBody(required = false) final SavedQuery query
    ); }
ControlPointPolicyController { private void applyPolicy(final String policy, final SavedSnapshot snapshot) throws ControlPointApiException { final TypedStateToken stateToken = snapshot.getStateTokens().stream() .filter(x -> x.getType().equals(TypedStateToken.StateTokenType.QUERY)) .findFirst() .orElseThrow(() -> new RuntimeException("Saved Snapshot has no associated state token")); final AciParameters aciParams = new AciParameters(); aciParameterHandler.addSecurityInfo(aciParams); final String securityInfo = aciParams.get(QueryParams.SecurityInfo.name()); controlPointService.applyPolicy(policy, stateToken.getStateToken(), securityInfo); } @Autowired  ControlPointPolicyController(
        final ControlPointService controlPointService,
        final SavedSearchService<SavedSnapshot, SavedSnapshot.Builder> savedSnapshotService,
        final HavenSearchAciParameterHandler aciParameterHandler
    ); @RequestMapping(method = RequestMethod.GET) List<ControlPointPolicy> getPolicies(); @RequestMapping(value = APPLY_PATH, method = RequestMethod.POST) void applyPolicy(
        @RequestParam(value = POLICY_PARAM) final String policy,
        @RequestParam(value = SAVED_SNAPSHOT_ID_PARAM, required = false) final Long snapshotId,
        @RequestBody(required = false) final SavedQuery query
    );  }