From e44f1a1c58efed9fbe2efce78864aaee3b577003 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 17 Feb 2020 13:57:56 -0500 Subject: More changes to actor code Use Coder.convert() from policy-common. Passed response to setOutcome(). Changed class names from XxxOperator to XxxOperation. Modified SDNC junits to invoke start() instead of startOperationAsync(). Changed context obtain() to re-run if the future was canceled. Added junit support class, BasicBidirectionalTopicOperation. Modified HttpOperation to allow subsequent requests to be issued. Some actors, like SO, send an initial HTTP request and then follow it with HTTP "are you done?" requests. Issue-ID: POLICY-2363-prop Change-Id: I12b5c2d4f07254e0cb79fabfe1ccf844b70a0654 Signed-off-by: Jim Hahn --- .../actor/sdnc/BandwidthOnDemandOperationTest.java | 76 +++++++++++ .../actor/sdnc/BandwidthOnDemandOperatorTest.java | 76 ----------- .../controlloop/actor/sdnc/BasicSdncOperation.java | 152 +++++++++++++++++++++ .../controlloop/actor/sdnc/BasicSdncOperator.java | 151 -------------------- .../actor/sdnc/RerouteOperationTest.java | 76 +++++++++++ .../actor/sdnc/RerouteOperatorTest.java | 76 ----------- .../controlloop/actor/sdnc/SdncOperationTest.java | 87 ++++++++++++ .../controlloop/actor/sdnc/SdncOperatorTest.java | 87 ------------ 8 files changed, 391 insertions(+), 390 deletions(-) create mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java delete mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperatorTest.java create mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java delete mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperator.java create mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java delete mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperatorTest.java create mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java delete mode 100644 models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperatorTest.java (limited to 'models-interactions/model-actors/actor.sdnc/src/test') diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java new file mode 100644 index 000000000..42042da67 --- /dev/null +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.sdnc.SdncRequest; + +public class BandwidthOnDemandOperationTest extends BasicSdncOperation { + + private BandwidthOnDemandOperation oper; + + public BandwidthOnDemandOperationTest() { + super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME); + } + + /** + * Set up. + */ + @Before + public void setUp() throws Exception { + super.setUp(); + oper = new BandwidthOnDemandOperation(params, operator); + } + + @Test + public void testBandwidthOnDemandOperator() { + assertEquals(DEFAULT_ACTOR, oper.getActorName()); + assertEquals(BandwidthOnDemandOperation.NAME, oper.getName()); + } + + @Test + public void testMakeRequest() throws Exception { + SdncRequest request = oper.makeRequest(1); + assertEquals("my-service", request.getNsInstanceId()); + assertEquals(REQ_ID, request.getRequestId()); + assertEquals(BandwidthOnDemandOperation.URI, request.getUrl()); + assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); + + verifyRequest("bod.json", request); + + verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new); + + // perform the operation + makeContext(); + verifyRequest("bod.json", verifyOperation(oper)); + } + + @Override + protected Map makeEnrichment() { + return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID, + "my-vnf"); + } +} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperatorTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperatorTest.java deleted file mode 100644 index 0623df2f5..000000000 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperatorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actor.sdnc; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.sdnc.SdncRequest; - -public class BandwidthOnDemandOperatorTest extends BasicSdncOperator { - - private BandwidthOnDemandOperation oper; - - public BandwidthOnDemandOperatorTest() { - super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME); - } - - /** - * Set up. - */ - @Before - public void setUp() throws Exception { - super.setUp(); - oper = new BandwidthOnDemandOperation(params, operator); - } - - @Test - public void testBandwidthOnDemandOperator() { - assertEquals(DEFAULT_ACTOR, oper.getActorName()); - assertEquals(BandwidthOnDemandOperation.NAME, oper.getName()); - } - - @Test - public void testMakeRequest() throws Exception { - SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); - assertEquals(REQ_ID, request.getRequestId()); - assertEquals(BandwidthOnDemandOperation.URI, request.getUrl()); - assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); - - verifyRequest("bod.json", request); - - verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new); - - // perform the operation - makeContext(); - verifyRequest("bod.json", verifyOperation(oper)); - } - - @Override - protected Map makeEnrichment() { - return Map.of(BandwidthOnDemandOperation.SERVICE_ID_KEY, "my-service", BandwidthOnDemandOperation.VNF_ID, - "my-vnf"); - } -} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java new file mode 100644 index 000000000..db8751d26 --- /dev/null +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.sdnc; + +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; +import java.util.function.BiFunction; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.controlloop.actor.test.BasicHttpOperation; +import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; +import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.policy.PolicyResult; +import org.onap.policy.sdnc.SdncRequest; +import org.onap.policy.sdnc.SdncResponse; +import org.onap.policy.sdnc.SdncResponseOutput; +import org.powermock.reflect.Whitebox; + +/** + * Superclass for various operator tests. + */ +public abstract class BasicSdncOperation extends BasicHttpOperation { + + protected SdncResponse response; + + /** + * Constructs the object using a default actor and operation name. + */ + public BasicSdncOperation() { + super(); + } + + /** + * Constructs the object. + * + * @param actor actor name + * @param operation operation name + */ + public BasicSdncOperation(String actor, String operation) { + super(actor, operation); + } + + /** + * Initializes mocks and sets up. + */ + public void setUp() throws Exception { + super.setUp(); + + response = new SdncResponse(); + + SdncResponseOutput output = new SdncResponseOutput(); + response.setResponseOutput(output); + output.setResponseCode("200"); + + when(rawResponse.readEntity(String.class)).thenReturn(new StandardCoder().encode(response)); + } + + /** + * Runs the operation and verifies that the response is successful. + * + * @param operation operation to run + * @return the request that was posted + */ + protected SdncRequest verifyOperation(SdncOperation operation) + throws InterruptedException, ExecutionException, TimeoutException { + + CompletableFuture future2 = operation.start(); + executor.runAll(100); + assertFalse(future2.isDone()); + + verify(client).post(callbackCaptor.capture(), any(), requestCaptor.capture(), any()); + callbackCaptor.getValue().completed(rawResponse); + + executor.runAll(100); + assertTrue(future2.isDone()); + + assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); + + return requestCaptor.getValue().getEntity(); + } + + /** + * Pretty-prints a request and verifies that the result matches the expected JSON. + * + * @param request type + * @param expectedJsonFile name of the file containing the expected JSON + * @param request request to verify + * @throws CoderException if the request cannot be pretty-printed + */ + protected void verifyRequest(String expectedJsonFile, T request) throws CoderException { + String json = new StandardCoder().encode(request, true); + String expected = ResourceUtils.getResourceAsString(expectedJsonFile); + + // strip request id, because it changes each time + final String stripper = "svc-request-id[^,]*"; + json = json.replaceFirst(stripper, "").trim(); + expected = expected.replaceFirst(stripper, "").trim(); + + assertEquals(expected, json); + } + + /** + * Verifies that an exception is thrown if a field is missing from the enrichment + * data. + * + * @param fieldName name of the field to be removed from the enrichment data + * @param expectedText text expected in the exception message + */ + protected void verifyMissing(String fieldName, String expectedText, + BiFunction maker) { + + makeContext(); + enrichment.remove(fieldName); + + SdncOperation oper = maker.apply(params, operator); + + assertThatIllegalArgumentException().isThrownBy(() -> Whitebox.invokeMethod(oper, "makeRequest", 1)) + .withMessageContaining("missing").withMessageContaining(expectedText); + } + + protected abstract Map makeEnrichment(); +} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperator.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperator.java deleted file mode 100644 index deafc4e9d..000000000 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperator.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actor.sdnc; - -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import java.util.function.BiFunction; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.controlloop.actor.test.BasicHttpOperation; -import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; -import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; -import org.onap.policy.controlloop.policy.PolicyResult; -import org.onap.policy.sdnc.SdncRequest; -import org.onap.policy.sdnc.SdncResponse; -import org.onap.policy.sdnc.SdncResponseOutput; -import org.powermock.reflect.Whitebox; - -/** - * Superclass for various operator tests. - */ -public abstract class BasicSdncOperator extends BasicHttpOperation { - - protected SdncResponse response; - - /** - * Constructs the object using a default actor and operation name. - */ - public BasicSdncOperator() { - super(); - } - - /** - * Constructs the object. - * - * @param actor actor name - * @param operation operation name - */ - public BasicSdncOperator(String actor, String operation) { - super(actor, operation); - } - - /** - * Initializes mocks and sets up. - */ - public void setUp() throws Exception { - super.setUp(); - - response = new SdncResponse(); - - SdncResponseOutput output = new SdncResponseOutput(); - response.setResponseOutput(output); - output.setResponseCode("200"); - - when(rawResponse.readEntity(String.class)).thenReturn(new StandardCoder().encode(response)); - } - - /** - * Runs the operation and verifies that the response is successful. - * - * @param operation operation to run - * @return the request that was posted - */ - protected SdncRequest verifyOperation(SdncOperation operation) - throws InterruptedException, ExecutionException, TimeoutException { - - CompletableFuture future2 = operation.startOperationAsync(1, outcome); - assertFalse(future2.isDone()); - - verify(client).post(callbackCaptor.capture(), any(), requestCaptor.capture(), any()); - callbackCaptor.getValue().completed(rawResponse); - - executor.runAll(100); - assertTrue(future2.isDone()); - - assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); - - return requestCaptor.getValue().getEntity(); - } - - /** - * Pretty-prints a request and verifies that the result matches the expected JSON. - * - * @param request type - * @param expectedJsonFile name of the file containing the expected JSON - * @param request request to verify - * @throws CoderException if the request cannot be pretty-printed - */ - protected void verifyRequest(String expectedJsonFile, T request) throws CoderException { - String json = new StandardCoder().encode(request, true); - String expected = ResourceUtils.getResourceAsString(expectedJsonFile); - - // strip request id, because it changes each time - final String stripper = "svc-request-id[^,]*"; - json = json.replaceFirst(stripper, "").trim(); - expected = expected.replaceFirst(stripper, "").trim(); - - assertEquals(expected, json); - } - - /** - * Verifies that an exception is thrown if a field is missing from the enrichment - * data. - * - * @param fieldName name of the field to be removed from the enrichment data - * @param expectedText text expected in the exception message - */ - protected void verifyMissing(String fieldName, String expectedText, - BiFunction maker) { - - makeContext(); - enrichment.remove(fieldName); - - SdncOperation oper = maker.apply(params, operator); - - assertThatIllegalArgumentException().isThrownBy(() -> Whitebox.invokeMethod(oper, "makeRequest", 1)) - .withMessageContaining("missing").withMessageContaining(expectedText); - } - - protected abstract Map makeEnrichment(); -} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java new file mode 100644 index 000000000..a98c38180 --- /dev/null +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.sdnc.SdncRequest; + +public class RerouteOperationTest extends BasicSdncOperation { + + private RerouteOperation oper; + + public RerouteOperationTest() { + super(DEFAULT_ACTOR, RerouteOperation.NAME); + } + + /** + * Set up. + */ + @Before + public void setUp() throws Exception { + super.setUp(); + oper = new RerouteOperation(params, operator); + } + + @Test + public void testRerouteOperator() { + assertEquals(DEFAULT_ACTOR, oper.getActorName()); + assertEquals(RerouteOperation.NAME, oper.getName()); + } + + @Test + public void testMakeRequest() throws Exception { + SdncRequest request = oper.makeRequest(1); + assertEquals("my-service", request.getNsInstanceId()); + assertEquals(REQ_ID, request.getRequestId()); + assertEquals(RerouteOperation.URI, request.getUrl()); + assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); + + verifyRequest("reroute.json", request); + + verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new); + verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new); + + // perform the operation + makeContext(); + verifyRequest("reroute.json", verifyOperation(oper)); + } + + @Override + protected Map makeEnrichment() { + return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network"); + } +} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperatorTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperatorTest.java deleted file mode 100644 index 7fc5ee7c2..000000000 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperatorTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actor.sdnc; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.sdnc.SdncRequest; - -public class RerouteOperatorTest extends BasicSdncOperator { - - private RerouteOperation oper; - - public RerouteOperatorTest() { - super(DEFAULT_ACTOR, RerouteOperation.NAME); - } - - /** - * Set up. - */ - @Before - public void setUp() throws Exception { - super.setUp(); - oper = new RerouteOperation(params, operator); - } - - @Test - public void testRerouteOperator() { - assertEquals(DEFAULT_ACTOR, oper.getActorName()); - assertEquals(RerouteOperation.NAME, oper.getName()); - } - - @Test - public void testMakeRequest() throws Exception { - SdncRequest request = oper.makeRequest(1); - assertEquals("my-service", request.getNsInstanceId()); - assertEquals(REQ_ID, request.getRequestId()); - assertEquals(RerouteOperation.URI, request.getUrl()); - assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); - - verifyRequest("reroute.json", request); - - verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new); - verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new); - - // perform the operation - makeContext(); - verifyRequest("reroute.json", verifyOperation(oper)); - } - - @Override - protected Map makeEnrichment() { - return Map.of(RerouteOperation.SERVICE_ID_KEY, "my-service", RerouteOperation.NETWORK_ID_KEY, "my-network"); - } -} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java new file mode 100644 index 000000000..e0825e13b --- /dev/null +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperationTest.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.sdnc; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Map; +import java.util.TreeMap; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.sdnc.SdncRequest; + +public class SdncOperationTest extends BasicSdncOperation { + + private SdncRequest request; + private SdncOperation oper; + + /** + * Sets up. + */ + @Before + public void setUp() throws Exception { + super.setUp(); + + oper = new SdncOperation(params, operator) { + @Override + protected SdncRequest makeRequest(int attempt) { + return request; + } + }; + } + + @Test + public void testSdncOperator() { + assertEquals(DEFAULT_ACTOR, oper.getActorName()); + assertEquals(DEFAULT_OPERATION, oper.getName()); + } + + @Test + public void testStartOperationAsync_testStartRequestAsync() throws Exception { + verifyOperation(oper); + } + + @Test + public void testIsSuccess() { + // success case + response.getResponseOutput().setResponseCode("200"); + assertTrue(oper.isSuccess(null, response)); + + // failure code + response.getResponseOutput().setResponseCode("555"); + assertFalse(oper.isSuccess(null, response)); + + // null code + response.getResponseOutput().setResponseCode(null); + assertFalse(oper.isSuccess(null, response)); + + // null output + response.setResponseOutput(null); + assertFalse(oper.isSuccess(null, response)); + } + + @Override + protected Map makeEnrichment() { + return new TreeMap<>(); + } +} diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperatorTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperatorTest.java deleted file mode 100644 index 4bc514c08..000000000 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/SdncOperatorTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - * ================================================================================ - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actor.sdnc; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Map; -import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.sdnc.SdncRequest; - -public class SdncOperatorTest extends BasicSdncOperator { - - private SdncRequest request; - private SdncOperation oper; - - /** - * Sets up. - */ - @Before - public void setUp() throws Exception { - super.setUp(); - - oper = new SdncOperation(params, operator) { - @Override - protected SdncRequest makeRequest(int attempt) { - return request; - } - }; - } - - @Test - public void testSdncOperator() { - assertEquals(DEFAULT_ACTOR, oper.getActorName()); - assertEquals(DEFAULT_OPERATION, oper.getName()); - } - - @Test - public void testStartOperationAsync_testStartRequestAsync() throws Exception { - verifyOperation(oper); - } - - @Test - public void testIsSuccess() { - // success case - response.getResponseOutput().setResponseCode("200"); - assertTrue(oper.isSuccess(null, response)); - - // failure code - response.getResponseOutput().setResponseCode("555"); - assertFalse(oper.isSuccess(null, response)); - - // null code - response.getResponseOutput().setResponseCode(null); - assertFalse(oper.isSuccess(null, response)); - - // null output - response.setResponseOutput(null); - assertFalse(oper.isSuccess(null, response)); - } - - @Override - protected Map makeEnrichment() { - return new TreeMap<>(); - } -} -- cgit 1.2.3-korg