ControlPointService { public void applyPolicy( final String policy, final String documentsStateToken, final String documentsSecurityInfo ) throws ControlPointApiException { checkEnabled(); final ControlPointApplyPolicyResponse response = apiClient.postUrlencoded("policyfiles/bystoredstate", Arrays.asList( new BasicNameValuePair("api-version", "1.0"), new BasicNameValuePair("policyId", policy), new BasicNameValuePair("stateMatchId", documentsStateToken), new BasicNameValuePair("securityInfo", documentsSecurityInfo) ), Collections.emptyList(), ControlPointApplyPolicyResponse.class); if (!response.isSuccess()) { throw new ControlPointApiException("Failed to apply policy"); } if (response.isPartialApplication()) { throw new ControlPointApiException("Policy was partially applied"); } } ControlPointService(final HttpClient httpClient, final ControlPointConfig config); @Autowired  ControlPointService(
        final HttpClient httpClient,
        final ConfigService<IdolFindConfig> configService
    ); boolean isEnabled(); ControlPointPolicies getPolicies(); void applyPolicy(
        final String policy,
        final String documentsStateToken,
        final String documentsSecurityInfo
    );  }
@Test public void testApplyPolicy() throws IOException, ControlPointApiException { Mockito.when(httpClient.execute(Mockito.any())) .thenReturn(ControlPointApiClientTest.buildLoginResponse()) .thenReturn(ControlPointApiClientTest.buildResponse(200, "OK", "{\"Success\":true,\"ItemsWillBeIgnored\":false}")); service.applyPolicy("the policy", "state token", null); }
@Test(expected = ControlPointApiException.class) public void testApplyPolicy_returnsFailure() throws IOException, ControlPointApiException { Mockito.when(httpClient.execute(Mockito.any())) .thenReturn(ControlPointApiClientTest.buildLoginResponse()) .thenReturn(ControlPointApiClientTest.buildResponse(200, "OK", "{\"Success\":false,\"ItemsWillBeIgnored\":false}")); service.applyPolicy("the policy", "state token", null); }
@Test(expected = ControlPointApiException.class) public void testApplyPolicy_partialSuccess() throws IOException, ControlPointApiException { Mockito.when(httpClient.execute(Mockito.any())) .thenReturn(ControlPointApiClientTest.buildLoginResponse()) .thenReturn(ControlPointApiClientTest.buildResponse(200, "OK", "{\"Success\":true,\"ItemsWillBeIgnored\":true}")); service.applyPolicy("the policy", "state token", null); }