X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FStdA1ClientTest.java;h=68b56f3ec0b78f66836a414c226b68e5bce96259;hb=refs%2Fchanges%2F83%2F2783%2F4;hp=3efbebb3df6bfcdbbf941378c2adff9e35eb40cf;hpb=86108abda4eafd500f50644f1bbb34e9673f8497;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java b/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java index 3efbebb3..68b56f3e 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/clients/StdA1ClientTest.java @@ -21,8 +21,6 @@ package org.oransc.policyagent.clients; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,6 +30,7 @@ import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.oransc.policyagent.repository.Policy; @@ -42,9 +41,9 @@ import reactor.test.StepVerifier; @ExtendWith(MockitoExtension.class) public class StdA1ClientTest { private static final String RIC_URL = "RicUrl"; - private static final String POLICYTYPES_IDENTITIES_URL = "/policytypes"; + private static final String POLICY_TYPES_IDENTITIES_URL = "/policytypes"; private static final String POLICIES_IDENTITIES_URL = "/policies"; - private static final String POLICYTYPES_URL = "/policytypes/"; + private static final String POLICY_TYPES_URL = "/policytypes/"; private static final String POLICIES_URL = "/policies/"; private static final String POLICY_TYPE_1_NAME = "type1"; @@ -57,55 +56,58 @@ public class StdA1ClientTest { private static final String POLICY_JSON_INVALID = "\"policyId\":\"policy1\"}"; private static final String POLICY_TYPE = "typeName"; - StdA1Client clientUnderTest; + StdA1ClientVersion1 clientUnderTest; + @Mock AsyncRestClient asyncRestClientMock; @BeforeEach public void init() { - asyncRestClientMock = mock(AsyncRestClient.class); - clientUnderTest = new StdA1Client(A1ClientHelper.createRic(RIC_URL).getConfig(), asyncRestClientMock); + clientUnderTest = new StdA1ClientVersion1(asyncRestClientMock); } @Test public void testGetPolicyTypeIdentities() { Mono policyTypeIds = Mono.just(Arrays.asList(POLICY_TYPE_1_NAME, POLICY_TYPE_2_NAME).toString()); - when(asyncRestClientMock.get(POLICYTYPES_IDENTITIES_URL)).thenReturn(policyTypeIds); + when(asyncRestClientMock.get(anyString())).thenReturn(policyTypeIds); Mono policyTypeIdsFlux = clientUnderTest.getPolicyTypeIdentities(); - verify(asyncRestClientMock).get(POLICYTYPES_IDENTITIES_URL); + + verify(asyncRestClientMock).get(POLICY_TYPES_IDENTITIES_URL); StepVerifier.create(policyTypeIdsFlux).expectNextCount(1).expectComplete().verify(); } @Test public void testGetPolicyIdentities() { Mono policyIds = Mono.just(Arrays.asList(POLICY_1_ID, POLICY_2_ID).toString()); - when(asyncRestClientMock.get(POLICIES_IDENTITIES_URL)).thenReturn(policyIds); + when(asyncRestClientMock.get(anyString())).thenReturn(policyIds); Mono policyIdsFlux = clientUnderTest.getPolicyIdentities(); + verify(asyncRestClientMock).get(POLICIES_IDENTITIES_URL); StepVerifier.create(policyIdsFlux).expectNextCount(1).expectComplete().verify(); } @Test public void testGetValidPolicyType() { - Mono policyTypeResp = + Mono policyTypeResp = Mono.just("{\"policySchema\": " + POLICY_TYPE_SCHEMA_VALID + ", \"statusSchema\": {} }"); - doReturn(policyTypeResp).when(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_1_NAME); + when(asyncRestClientMock.get(anyString())).thenReturn(policyTypeResp); Mono policyTypeMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_NAME); - verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_1_NAME); + + verify(asyncRestClientMock).get(POLICY_TYPES_URL + POLICY_TYPE_1_NAME); StepVerifier.create(policyTypeMono).expectNext(POLICY_TYPE_SCHEMA_VALID).expectComplete().verify(); } @Test public void testGetInvalidPolicyType() { - when(asyncRestClientMock.get(POLICYTYPES_URL + POLICY_TYPE_1_NAME)) - .thenReturn(Mono.just(POLICY_TYPE_SCHEMA_INVALID)); + when(asyncRestClientMock.get(anyString())).thenReturn(Mono.just(POLICY_TYPE_SCHEMA_INVALID)); Mono policyTypeMono = clientUnderTest.getPolicyTypeSchema(POLICY_TYPE_1_NAME); - verify(asyncRestClientMock).get(POLICYTYPES_URL + POLICY_TYPE_1_NAME); + + verify(asyncRestClientMock).get(POLICY_TYPES_URL + POLICY_TYPE_1_NAME); StepVerifier.create(policyTypeMono).expectErrorMatches(throwable -> throwable instanceof JSONException) .verify(); } @@ -116,6 +118,7 @@ public class StdA1ClientTest { Mono policyMono = clientUnderTest .putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE)); + verify(asyncRestClientMock).put(POLICIES_URL + POLICY_1_ID + "?policyTypeId=" + POLICY_TYPE, POLICY_JSON_VALID); StepVerifier.create(policyMono).expectNext(POLICY_JSON_VALID).expectComplete().verify(); } @@ -126,6 +129,7 @@ public class StdA1ClientTest { Mono policyMono = clientUnderTest .putPolicy(A1ClientHelper.createPolicy(RIC_URL, POLICY_1_ID, POLICY_JSON_VALID, POLICY_TYPE)); + StepVerifier.create(policyMono).expectErrorMatches(throwable -> throwable instanceof JSONException).verify(); }