* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import jakarta.ws.rs.client.InvocationCallback;
+import jakarta.ws.rs.core.Response;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
-import javax.ws.rs.client.InvocationCallback;
-import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
-import org.onap.policy.controlloop.policy.PolicyResult;
/**
* Tests HttpOperation when polling is enabled.
*/
+@RunWith(MockitoJUnitRunner.class)
public class HttpPollingOperationTest {
private static final String BASE_URI = "http://my-host:6969/base-uri/";
private static final String MY_PATH = "my-path";
*/
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
-
when(client.getBaseUrl()).thenReturn(BASE_URI);
when(config.getClient()).thenReturn(client);
- when(config.getPath()).thenReturn(MY_PATH);
when(config.getMaxPolls()).thenReturn(MAX_POLLS);
when(config.getPollPath()).thenReturn(POLL_PATH);
when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC);
when(rawResponse.readEntity(String.class)).thenReturn(response);
params = ControlLoopOperationParams.builder().actor(MY_ACTOR).operation(MY_OPERATION).build();
- outcome = params.makeOutcome(null);
+ outcome = params.makeOutcome();
oper = new MyOper(params, config);
}
// should throw an exception if we pass a plain HttpConfig
HttpConfig config2 = mock(HttpConfig.class);
- when(config2.getClient()).thenReturn(client);
- when(config2.getPath()).thenReturn(MY_PATH);
assertThatIllegalStateException().isThrownBy(() -> new MyOper(params, config2).setUsePolling());
}
oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response);
assertTrue(future2.isDone());
assertSame(outcome, future2.get());
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertNotNull(oper.getSubRequestId());
assertSame(response, outcome.getResponse());
future2 = oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response);
assertTrue(future2.isDone());
assertSame(outcome, future2.get());
- assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ assertEquals(OperationResult.FAILURE, outcome.getResult());
assertNotNull(oper.getSubRequestId());
assertSame(response, outcome.getResponse());
}
oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response);
assertSame(outcome, future2.get(5, TimeUnit.SECONDS));
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(2, oper.getPollCount());
/*
future2 = oper.postProcessResponse(outcome, FULL_PATH, rawResponse, response);
assertSame(outcome, future2.get(5, TimeUnit.SECONDS));
- assertEquals(PolicyResult.FAILURE_TIMEOUT, outcome.getResult());
+ assertEquals(OperationResult.FAILURE_TIMEOUT, outcome.getResult());
assertEquals(MAX_POLLS + 1, oper.getPollCount());
oper.resetPollCount();