X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-actors%2Factor.aai%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcontrolloop%2Factor%2Faai%2FAaiCustomQueryOperationTest.java;h=dd6d0ec18f32ca2f9422735a5b82c443d3c6fd38;hb=e3938e43b8a1f02f74368ecb75c38530285feac0;hp=abfd2eb41aeda96b727da7a9bfc4d93d882ab9cf;hpb=2460e2e4ffb60d793d65bf942d89d85d4711a680;p=policy%2Fmodels.git diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index abfd2eb41..dd6d0ec18 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 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. @@ -21,13 +22,12 @@ package org.onap.policy.controlloop.actor.aai; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -43,32 +43,23 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.mockito.Mock; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.policy.aai.AaiConstants; import org.onap.policy.aai.AaiCqResponse; -import org.onap.policy.common.endpoints.http.client.HttpClientFactory; import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.StandardCoderObject; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; -import org.onap.policy.controlloop.actorserviceprovider.Util; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; -import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; +import org.onap.policy.controlloop.actorserviceprovider.OperationProperties; +import org.onap.policy.controlloop.actorserviceprovider.OperationResult; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams; -import org.onap.policy.controlloop.actorserviceprovider.spi.Actor; -import org.onap.policy.controlloop.policy.PolicyResult; -public class AaiCustomQueryOperationTest extends BasicAaiOperation> { +@RunWith(MockitoJUnitRunner.class) +public class AaiCustomQueryOperationTest extends BasicAaiOperation { private static final StandardCoder coder = new StandardCoder(); private static final String MY_LINK = "my-link"; - private static final String MY_VSERVER = "my-vserver-name"; - private static final String SIM_VSERVER = "OzVServer"; - - @Mock - private Actor tenantActor; private AaiCustomQueryOperation oper; @@ -93,14 +84,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation new AaiCustomQueryOperation(params, config)).doesNotThrowAnyException(); + } - // try without enrichment data - params.getContext().getEnrichment().remove(AaiCustomQueryOperation.VSERVER_VSERVER_NAME); - assertThatIllegalArgumentException().isThrownBy(() -> new AaiCustomQueryOperation(params, config)) - .withMessage("missing " + AaiCustomQueryOperation.VSERVER_VSERVER_NAME + " in enrichment data"); + @Test + public void testGetPropertyNames() { + assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_VSERVER_LINK)); } @Test @@ -147,51 +126,19 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation future2 = oper.start(); - assertEquals(PolicyResult.SUCCESS, getResult(future2)); - - // tenant response should have been cached within the context - assertNotNull(context.getProperty(AaiGetTenantOperation.getKey(MY_VSERVER))); - - // custom query response should have been cached within the context - AaiCqResponse cqData = context.getProperty(AaiCqResponse.CONTEXT_KEY); - assertNotNull(cqData); + assertEquals(OperationResult.SUCCESS, getResult(future2)); assertEquals("1", future2.get().getSubRequestId()); } - /** - * Tests when preprocessor step is not needed. - */ - @Test - @SuppressWarnings("unchecked") - public void testStartOperationAsync_testStartPreprocessorAsyncNotNeeded() throws Exception { - // pre-load the tenant data - final StandardCoderObject data = preloadTenantData(); - - // only need one response - when(rawResponse.readEntity(String.class)).thenReturn(makeCqReply()); - when(webAsync.put(any(), any(InvocationCallback.class))).thenAnswer(provideResponse(rawResponse, 1)); - - CompletableFuture future2 = oper.start(); - - assertEquals(PolicyResult.SUCCESS, getResult(future2)); - - // should not have replaced tenant response - assertSame(data, context.getProperty(AaiGetTenantOperation.getKey(MY_VSERVER))); - - // custom query response should have been cached within the context - AaiCqResponse cqData = context.getProperty(AaiCqResponse.CONTEXT_KEY); - assertNotNull(cqData); - } - @Test public void testMakeHeaders() { verifyHeaders(oper.makeHeaders()); @@ -199,10 +146,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation reqMap = coder.decode(reqText, Map.class); + Map reqMap = coder.decode(reqText, Map.class); // sort the request fields so they match the order in cq.json Map request = new TreeMap<>(reqMap); @@ -221,17 +165,18 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation future2 = oper.start(); + @Test + public void testSetOutcome() { + outcome = oper.setOutcome(params.makeOutcome(), OperationResult.SUCCESS, null, null); + assertNull(outcome.getResponse()); - assertEquals(PolicyResult.FAILURE_EXCEPTION, getResult(future2)); + outcome = oper.setOutcome(params.makeOutcome(), OperationResult.SUCCESS, null, "{}"); + assertTrue(outcome.getResponse() instanceof AaiCqResponse); } private String makeTenantReply() throws Exception { @@ -246,18 +191,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation future2) + private OperationResult getResult(CompletableFuture future2) throws InterruptedException, ExecutionException, TimeoutException { executor.runAll(100); @@ -265,25 +200,4 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation buildOperation(ControlLoopOperationParams params) { - return new AaiGetTenantOperation(params, getCurrentConfig()); - } - - @Override - protected HttpClientFactory getClientFactory() { - return factory; - } - } }