Rename Onap A1 client
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / clients / A1ClientFactoryTest.java
index 926485d..6122c19 100644 (file)
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 Nordix Foundation
+ * Copyright (C) 2020 Nordix Foundation
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 package org.oransc.policyagent.clients;
 
+import static ch.qos.logback.classic.Level.WARN;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
@@ -28,10 +29,11 @@ import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
-import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.read.ListAppender;
+
 import java.util.Vector;
+
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
@@ -42,6 +44,7 @@ import org.oransc.policyagent.configuration.ApplicationConfig;
 import org.oransc.policyagent.configuration.ImmutableRicConfig;
 import org.oransc.policyagent.repository.Ric;
 import org.oransc.policyagent.utils.LoggingUtils;
+
 import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 
@@ -63,7 +66,7 @@ public class A1ClientFactoryTest {
     A1Client sdncOscA1ClientMock;
 
     @Mock
-    A1Client sdnrOnapA1ClientMock;
+    A1Client sdncOnapA1ClientMock;
 
     private ImmutableRicConfig ricConfig =
         ImmutableRicConfig.builder().name(RIC_NAME).baseUrl("baseUrl").managedElementIds(new Vector<>()).build();
@@ -78,7 +81,7 @@ public class A1ClientFactoryTest {
 
     @Test
     public void createStd_ok() {
-        whenGetProtocolVersionSdnrOnapA1ClientThrowException();
+        whenGetProtocolVersionSdncOnapA1ClientThrowException();
         whenGetProtocolVersionSdncOscA1ClientThrowException();
         whenGetProtocolVersionOscA1ClientThrowException();
         whenGetProtocolVersionStdA1ClientReturnCorrectProtocol();
@@ -93,7 +96,7 @@ public class A1ClientFactoryTest {
 
     @Test
     public void createOsc_ok() {
-        whenGetProtocolVersionSdnrOnapA1ClientThrowException();
+        whenGetProtocolVersionSdncOnapA1ClientThrowException();
         whenGetProtocolVersionSdncOscA1ClientThrowException();
         whenGetProtocolVersionOscA1ClientReturnCorrectProtocol();
 
@@ -107,7 +110,7 @@ public class A1ClientFactoryTest {
 
     @Test
     public void createSdncOsc_ok() {
-        whenGetProtocolVersionSdnrOnapA1ClientThrowException();
+        whenGetProtocolVersionSdncOnapA1ClientThrowException();
         whenGetProtocolVersionSdncOscA1ClientReturnCorrectProtocol();
 
         StepVerifier.create(factoryUnderTest.createA1Client(ric)) //
@@ -119,32 +122,32 @@ public class A1ClientFactoryTest {
     }
 
     @Test
-    public void createSdnrOnap_ok() {
-        whenGetProtocolVersionSdnrOnapA1ClientReturnCorrectProtocol();
+    public void createSdncOnap_ok() {
+        whenGetProtocolVersionSdncOnapA1ClientReturnCorrectProtocol();
 
         StepVerifier.create(factoryUnderTest.createA1Client(ric)) //
             .expectSubscription() //
-            .expectNext(sdnrOnapA1ClientMock) //
+            .expectNext(sdncOnapA1ClientMock) //
             .verifyComplete();
 
-        assertEquals(A1ProtocolType.SDNR_ONAP, ric.getProtocolVersion(), "Not correct protocol");
+        assertEquals(A1ProtocolType.SDNC_ONAP, ric.getProtocolVersion(), "Not correct protocol");
     }
 
     @Test
     public void createWithNoProtocol_error() {
-        whenGetProtocolVersionSdnrOnapA1ClientThrowException();
+        whenGetProtocolVersionSdncOnapA1ClientThrowException();
         whenGetProtocolVersionSdncOscA1ClientThrowException();
         whenGetProtocolVersionOscA1ClientThrowException();
         whenGetProtocolVersionStdA1ClientThrowException();
 
-        final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(A1ClientFactory.class);
+        final ListAppender<ILoggingEvent> logAppender = LoggingUtils.getLogListAppender(A1ClientFactory.class, WARN);
         StepVerifier.create(factoryUnderTest.createA1Client(ric)) //
             .expectSubscription() //
             .expectErrorMatches(
                 throwable -> throwable instanceof Exception && throwable.getMessage().equals(EXCEPTION_MESSAGE))
             .verify();
 
-        assertEquals(Level.WARN, logAppender.list.get(0).getLevel(), "Warning not logged");
+        assertEquals(WARN, logAppender.list.get(0).getLevel(), "Warning not logged");
         assertTrue(logAppender.list.toString().contains("Could not get protocol version from RIC: " + RIC_NAME),
             "Correct message not logged");
 
@@ -164,20 +167,20 @@ public class A1ClientFactoryTest {
 
         assertEquals(A1ProtocolType.STD_V1, ric.getProtocolVersion(), "Not correct protocol");
 
-        verifyNoMoreInteractions(sdnrOnapA1ClientMock);
+        verifyNoMoreInteractions(sdncOnapA1ClientMock);
         verifyNoMoreInteractions(sdncOscA1ClientMock);
         verifyNoMoreInteractions(oscA1ClientMock);
         verifyNoMoreInteractions(stdA1ClientMock);
     }
 
-    private void whenGetProtocolVersionSdnrOnapA1ClientThrowException() {
-        doReturn(sdnrOnapA1ClientMock).when(factoryUnderTest).createSdnrOnapA1Client(ric);
-        when(sdnrOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.error(new Exception(EXCEPTION_MESSAGE)));
+    private void whenGetProtocolVersionSdncOnapA1ClientThrowException() {
+        doReturn(sdncOnapA1ClientMock).when(factoryUnderTest).createSdncOnapA1Client(ric);
+        when(sdncOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.error(new Exception(EXCEPTION_MESSAGE)));
     }
 
-    private void whenGetProtocolVersionSdnrOnapA1ClientReturnCorrectProtocol() {
-        doReturn(sdnrOnapA1ClientMock).when(factoryUnderTest).createSdnrOnapA1Client(any(Ric.class));
-        when(sdnrOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.just(A1ProtocolType.SDNR_ONAP));
+    private void whenGetProtocolVersionSdncOnapA1ClientReturnCorrectProtocol() {
+        doReturn(sdncOnapA1ClientMock).when(factoryUnderTest).createSdncOnapA1Client(any(Ric.class));
+        when(sdncOnapA1ClientMock.getProtocolVersion()).thenReturn(Mono.just(A1ProtocolType.SDNC_ONAP));
     }
 
     private void whenGetProtocolVersionSdncOscA1ClientThrowException() {