Add asserts to silence Sonar warnings re tests 58/2258/2
authorLott, Christopher (cl778h) <cl778h@att.com>
Thu, 16 Jan 2020 19:07:25 +0000 (14:07 -0500)
committerLott, Christopher (cl778h) <cl778h@att.com>
Thu, 16 Jan 2020 23:29:00 +0000 (18:29 -0500)
Correct some @Profile and @ActiveProfiles annotations.
Move configuration tests into their own package.
Increase logging for EPSDK-FW code during test.

Change-Id: I6a2fa3c0a6ed78147c46fe8a5f5695855fa16cb7
Signed-off-by: Lott, Christopher (cl778h) <cl778h@att.com>
29 files changed:
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/A1MediatorApiBuilder.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/AppManagerApiBuilder.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/E2ManagerApiBuilder.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/PortalApiConfiguration.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/config/WebSecurityConfiguration.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/AdminController.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManager.java
webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/portalapi/PortalRestCentralServiceImpl.java
webapp-backend/src/main/resources/logback.xml
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardTestServer.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/DashboardUserManagerTest.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/TestUtils.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/AbstractMockConfiguration.java with 70% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/A1MediatorMockConfiguration.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressMockConfiguration.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java [deleted file]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/RICInstanceMockConfiguration.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/WebSecurityMockConfiguration.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/test/A1MediatorConfigTest.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/A1MediatorConfigTest.java with 82% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/test/AbstractConfigTest.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/AbstractConfigTest.java with 69% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/test/AppManagerConfigTest.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/AppManagerConfigTest.java with 87% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/test/CaasIngressConfigTest.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/CaasIngressConfigTest.java with 86% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/test/E2ManagerConfigTest.java [moved from webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/E2ManagerConfigTest.java with 87% similarity]
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/AbstractControllerTest.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/AdminControllerExtension.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/DefaultContextTest.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/controller/PortalRestCentralServiceTest.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/model/ModelTest.java
webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/portalapi/PortalAuthManagerTest.java
webapp-backend/src/test/resources/logback-test.xml

index 0fbbcb3..06fccc1 100644 (file)
@@ -23,8 +23,8 @@ import java.lang.invoke.MethodHandles;
 
 import org.oransc.ric.a1med.client.api.A1MediatorApi;
 import org.oransc.ric.a1med.client.invoker.ApiClient;
-import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.oransc.ric.portal.dashboard.model.RicInstance;
+import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.client.RestTemplate;
index aeb7559..5081ec8 100644 (file)
@@ -24,8 +24,8 @@ import java.lang.invoke.MethodHandles;
 import org.oransc.ric.plt.appmgr.client.api.HealthApi;
 import org.oransc.ric.plt.appmgr.client.api.XappApi;
 import org.oransc.ric.plt.appmgr.client.invoker.ApiClient;
-import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.oransc.ric.portal.dashboard.model.RicInstance;
+import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.client.RestTemplate;
index 6e64a54..858a51b 100644 (file)
@@ -24,8 +24,8 @@ import java.lang.invoke.MethodHandles;
 import org.oransc.ric.e2mgr.client.api.HealthCheckApi;
 import org.oransc.ric.e2mgr.client.api.NodebApi;
 import org.oransc.ric.e2mgr.client.invoker.ApiClient;
-import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.oransc.ric.portal.dashboard.model.RicInstance;
+import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.web.client.RestTemplate;
index f318cad..863f9db 100644 (file)
@@ -28,10 +28,13 @@ import org.slf4j.LoggerFactory;
 import org.springframework.boot.web.servlet.ServletRegistrationBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
 
 @Configuration
-@Profile("!test")
+/**
+ * This is not restricted to test or !test profile, it's always active, the same
+ * servlet configuration is usable in production and test. This also means there
+ * is no PortalApiMockConfiguration class in the test area.
+ */
 public class PortalApiConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
index 941dc46..f1438d7 100644 (file)
@@ -75,7 +75,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
 
        @Override
        protected void configure(HttpSecurity http) throws Exception {
-               logger.debug("configure: portalapi.username {}", userName);
+               logger.debug("configure: portalapi.appName {}", appName);
                // A chain of ".and()" always baffles me
                http.authorizeRequests().anyRequest().authenticated();
                http.headers().frameOptions().disable();
@@ -115,6 +115,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Bean
        public PortalAuthManager portalAuthManagerBean() throws ClassNotFoundException, IllegalAccessException,
                        InstantiationException, InvocationTargetException, NoSuchMethodException {
+               logger.debug("portalAuthManagerBean");
                return new PortalAuthManager(appName, userName, password, decryptor, userCookie);
        }
 
@@ -129,6 +130,7 @@ public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
         */
        public PortalAuthenticationFilter portalAuthenticationFilterBean() throws ClassNotFoundException,
                        IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
+               logger.debug("portalAuthenticationFilterBean");
                return new PortalAuthenticationFilter(portalapiSecurity, portalAuthManagerBean(), this.userManager);
        }
 
index 17d9843..ccdf1bc 100644 (file)
@@ -30,8 +30,8 @@ import org.oransc.ric.portal.dashboard.DashboardConstants;
 import org.oransc.ric.portal.dashboard.DashboardUserManager;
 import org.oransc.ric.portal.dashboard.model.ErrorTransport;
 import org.oransc.ric.portal.dashboard.model.IDashboardResponse;
-import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.oransc.ric.portal.dashboard.model.RicInstanceKeyName;
+import org.oransc.ric.portal.dashboard.model.RicInstanceList;
 import org.oransc.ric.portal.dashboard.model.SuccessTransport;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 2cf55a8..977daf4 100644 (file)
@@ -63,6 +63,7 @@ public class PortalAuthManager {
         *         password.
         */
        public Map<String, String> getAppCredentials() {
+               logger.debug("getAppCredentials");
                return credentialsMap;
        }
 
@@ -94,6 +95,7 @@ public class PortalAuthManager {
         *         established a user ID; else null.
         */
        public String validateEcompSso(HttpServletRequest request) {
+               logger.debug("validateEcompSso URI {}", request.getRequestURI());
                // Check ECOMP Portal cookie
                Cookie ep = getCookie(request, PortalApiConstants.EP_SERVICE);
                if (ep == null) {
index 8a33632..93ebc82 100644 (file)
@@ -54,6 +54,9 @@ public class PortalRestCentralServiceImpl implements IPortalRestCentralService {
                final ApplicationContext context = SpringContextCache.getApplicationContext();
                authManager = context.getBean(PortalAuthManager.class);
                userManager = context.getBean(DashboardUserManager.class);
+               logger.debug("ctor: authManager has credentials for app {}",
+                               authManager.getAppCredentials().get(IPortalRestCentralService.CREDENTIALS_APP));
+               logger.debug("ctor: userManager has list size {}", userManager.getUsers().size());
        }
 
        /*
@@ -70,7 +73,7 @@ public class PortalRestCentralServiceImpl implements IPortalRestCentralService {
         */
        @Override
        public String getUserId(HttpServletRequest request) throws PortalAPIException {
-               logger.debug("getuserId");
+               logger.debug("getUserId");
                return authManager.validateEcompSso(request);
        }
 
index 213d105..478e680 100644 (file)
                <appender-ref ref="FILE" />
        </root>
 
-       <!-- Code under test should be chatty --> >
-       <logger name="org.oransc.ric.portal.dashboard" level="DEBUG" />
+       <!-- Code not under test should not be chatty --> >
+       <logger name="org.oransc.ric.portal.dashboard" level="INFO" />
 
        <!-- Watch authentication done by EPSDK-FW -->
-       <logger name="org.onap.portalsdk.core.onboarding.crossapi" level="DEBUG" />
+       <logger name="org.onap.portalsdk.core.onboarding" level="INFO" />
 
        <!-- Report request URLs -->
        <logger name="org.springframework.web.client.RestTemplate" level="DEBUG" />
index d3e0049..a0d8f74 100644 (file)
@@ -53,8 +53,8 @@ public class DashboardTestServer {
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
        /*
-        * Keeps the test server alive forever. Use a guard so this test is never run by
-        * Jenkins.
+        * Keeps the test server alive forever. Use a guard so this test is not run by
+        * maven automatically; for example not in Jenkins.
         */
        @EnabledIfSystemProperty(named = "org.oransc.ric.portal.dashboard", matches = "mock")
        @Test
index 553865e..a181159 100644 (file)
@@ -30,7 +30,9 @@ import org.onap.portalsdk.core.restful.domain.EcompRole;
 import org.onap.portalsdk.core.restful.domain.EcompUser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 public class DashboardUserManagerTest {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.invoke.MethodHandles;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+public class TestUtils {
 
-public class AbstractMockConfiguration {
-       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-       protected static String readDataFromPath(String path) throws IOException {
+       public static String readDataFromPath(String path) throws IOException {
                InputStream is = MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(path);
-               if (is == null) {
-                       String msg = "readDataFromPath: Failed to find resource on classpath: " + path;
-                       logger.error(msg);
-                       throw new RuntimeException(msg);
-               }
+               if (is == null)
+                       throw new IOException("readDataFromPath: Failed to find resource on classpath: " + path);
                InputStreamReader reader = new InputStreamReader(is, "UTF-8");
                StringBuilder sb = new StringBuilder();
-               char[] buf = new char[8192];
+               char[] buf = new char[16384];
                int i;
                while ((i = reader.read(buf)) > 0)
                        sb.append(buf, 0, i);
index 21b2fac..67b2176 100644 (file)
@@ -34,6 +34,7 @@ import java.util.Map;
 import org.oransc.ric.a1med.client.api.A1MediatorApi;
 import org.oransc.ric.a1med.client.invoker.ApiClient;
 import org.oransc.ric.a1med.client.model.PolicyTypeSchema;
+import org.oransc.ric.portal.dashboard.TestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
@@ -52,7 +53,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
  */
 @Configuration
 @Profile("test")
-public class A1MediatorMockConfiguration extends AbstractMockConfiguration {
+public class A1MediatorMockConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
@@ -75,9 +76,9 @@ public class A1MediatorMockConfiguration extends AbstractMockConfiguration {
                policyTypeIds = new ArrayList<>();
                policyTypeIds.add(ADMISSION_CONTROL_POLICY_ID);
                ObjectMapper mapper = new ObjectMapper();
-               final String policyType = readDataFromPath("rate-control-policy-type.json");
+               final String policyType = TestUtils.readDataFromPath("rate-control-policy-type.json");
                rateControlPolicyType = mapper.readValue(policyType, PolicyTypeSchema.class);
-               final String policyInstance = readDataFromPath("rate-control-policy-instance.json");
+               final String policyInstance = TestUtils.readDataFromPath("rate-control-policy-instance.json");
                appPolicyMap = new HashMap<>();
                appPolicyMap.put(AC_CONTROL_NAME, policyInstance);
        }
index b9cbaf9..b10dcc8 100644 (file)
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
 
+import org.oransc.ric.portal.dashboard.TestUtils;
 import org.oransc.ric.portal.dashboard.k8sapi.SimpleKubernetesClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,7 +43,7 @@ import org.springframework.context.annotation.Profile;
  */
 @Configuration
 @Profile("test")
-public class CaasIngressMockConfiguration extends AbstractMockConfiguration {
+public class CaasIngressMockConfiguration {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
@@ -57,11 +58,10 @@ public class CaasIngressMockConfiguration extends AbstractMockConfiguration {
 
        private SimpleKubernetesClient simpleKubernetesClient(String instanceKey) throws IOException {
                // File in src/test/resources
-               String pltPods;
-               if (RICInstanceMockConfiguration.INSTANCE_KEY_1.equals(instanceKey))
-                       pltPods = readDataFromPath("caas-ingress-ricplt-pods-1.json");
-               else
-                       pltPods = readDataFromPath("caas-ingress-ricplt-pods-2.json");
+               String podFile = RICInstanceMockConfiguration.INSTANCE_KEY_1.equals(instanceKey)
+                               ? "caas-ingress-ricplt-pods-1.json"
+                               : "caas-ingress-ricplt-pods-2.json";
+               String pltPods = TestUtils.readDataFromPath(podFile);
                SimpleKubernetesClient mockClient = mock(SimpleKubernetesClient.class);
                doAnswer(inv -> {
                        String ns = inv.<String>getArgument(0);
diff --git a/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java b/webapp-backend/src/test/java/org/oransc/ric/portal/dashboard/config/PortalApiMockConfiguration.java
deleted file mode 100644 (file)
index ab8083a..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * O-RAN-SC
- * %%
- * Copyright (C) 2019 AT&T Intellectual Property
- * %%
- * 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.oransc.ric.portal.dashboard.config;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-
-import java.lang.invoke.MethodHandles;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.onap.portalsdk.core.onboarding.crossapi.PortalRestAPIProxy;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
-import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.web.servlet.ServletRegistrationBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
-
-@Configuration
-@Profile("test")
-public class PortalApiMockConfiguration {
-
-       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-       // Unfortunately EPSDK-FW does not define these as constants
-       public static final String PORTAL_USERNAME_HEADER_KEY = "username";
-       public static final String PORTAL_PASSWORD_HEADER_KEY = "password";
-
-       @Bean
-       public ServletRegistrationBean<PortalRestAPIProxy> portalApiProxyServlet() {
-               PortalRestAPIProxy servlet = new PortalRestAPIProxy();
-               final ServletRegistrationBean<PortalRestAPIProxy> servletBean = new ServletRegistrationBean<>(servlet,
-                               PortalApiConstants.API_PREFIX + "/*");
-               servletBean.setName("PortalRestApiProxyServlet");
-               return servletBean;
-       }
-
-       @Bean
-       public PortalAuthManager portalAuthManager() throws Exception {
-               PortalAuthManager mockManager = mock(PortalAuthManager.class);
-               final Map<String, String> credentialsMap = new HashMap<>();
-               credentialsMap.put("appName", "appName");
-               credentialsMap.put(PORTAL_USERNAME_HEADER_KEY, PORTAL_USERNAME_HEADER_KEY);
-               credentialsMap.put(PORTAL_PASSWORD_HEADER_KEY, PORTAL_PASSWORD_HEADER_KEY);
-               doAnswer(inv -> {
-                       logger.debug("getAppCredentials");
-                       return credentialsMap;
-               }).when(mockManager).getAppCredentials();
-               doAnswer(inv -> {
-                       logger.debug("getUserId");
-                       return "userId";
-               }).when(mockManager).validateEcompSso(any(HttpServletRequest.class));
-               return mockManager;
-       }
-
-}
index 4b1158e..15cab07 100644 (file)
@@ -31,13 +31,13 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
-import org.springframework.stereotype.Component;
 
 /**
  * Publishes a mock list of RIC instances.
  */
-@Component
+@Configuration
 @Profile("test")
 public class RICInstanceMockConfiguration {
 
index 80cde66..257b4a4 100644 (file)
@@ -21,10 +21,13 @@ package org.oransc.ric.portal.dashboard.config;
 
 import java.lang.invoke.MethodHandles;
 
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
+import org.oransc.ric.portal.dashboard.portalapi.PortalAuthManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -47,12 +50,18 @@ public class WebSecurityMockConfiguration extends WebSecurityConfigurerAdapter {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-       public WebSecurityMockConfiguration(@Value("${userfile}") final String userFilePath) {
-               logger.debug("ctor: user file path {}", userFilePath);
-       }
+       // Although constructor arguments are recommended over field injection,
+       // this results in fewer lines of code.
+       @Value("${portalapi.decryptor}")
+       private String decryptor;
+       @Value("${portalapi.usercookie}")
+       private String userCookie;
+       @Value("${userfile}")
+       private String userFilePath;
 
        @Override
        protected void configure(AuthenticationManagerBuilder auth) throws Exception {
+               logger.debug("configure");
                PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
                auth.inMemoryAuthentication() //
                                .passwordEncoder(encoder) //
@@ -81,4 +90,12 @@ public class WebSecurityMockConfiguration extends WebSecurityConfigurerAdapter {
                web.ignoring().antMatchers("/", "/csrf"); // allow swagger-ui to load
        }
 
+       @Bean
+       public PortalAuthManager portalAuthManagerBean() throws Exception {
+               logger.debug("portalAuthManagerBean");
+               return new PortalAuthManager(IPortalRestCentralService.CREDENTIALS_APP,
+                               IPortalRestCentralService.CREDENTIALS_USER, IPortalRestCentralService.CREDENTIALS_PASS, decryptor,
+                               userCookie);
+       }
+
 }
@@ -2,7 +2,7 @@
  * ========================LICENSE_START=================================
  * O-RAN-SC
  * %%
- * Copyright (C) 2019 AT&T Intellectual Property
+ * Copyright (C) 2020 AT&T Intellectual Property
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.config.test;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.oransc.ric.a1med.client.api.A1MediatorApi;
+import org.oransc.ric.portal.dashboard.config.A1MediatorApiBuilder;
+import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
 
 public class A1MediatorConfigTest extends AbstractConfigTest {
 
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.config.test;
 
+import java.lang.invoke.MethodHandles;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.oransc.ric.portal.dashboard.model.RicInstanceList;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -32,7 +38,17 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
 @ActiveProfiles("test")
 public class AbstractConfigTest {
 
+       private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+       // Relies on Spring-Boot feature of populating instances data from configuration
        @Autowired
        protected RicInstanceList instanceConfig;
 
+       // Sonar finds the annotations on this class and insists on at least one test.
+       @Test
+       public void beQuietSonar() {
+               // Silence Sonar warning about missing assertion.
+               Assertions.assertTrue(logger.isWarnEnabled());
+       }
+
 }
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.config.test;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.oransc.ric.plt.appmgr.client.api.HealthApi;
 import org.oransc.ric.plt.appmgr.client.api.XappApi;
+import org.oransc.ric.portal.dashboard.config.AppManagerApiBuilder;
+import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
 
 public class AppManagerConfigTest extends AbstractConfigTest {
 
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.config.test;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
+import org.oransc.ric.portal.dashboard.config.SimpleKubernetesClientBuilder;
 import org.oransc.ric.portal.dashboard.k8sapi.SimpleKubernetesClient;
 
 public class CaasIngressConfigTest extends AbstractConfigTest {
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
-package org.oransc.ric.portal.dashboard.config;
+package org.oransc.ric.portal.dashboard.config.test;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
 import org.oransc.ric.e2mgr.client.api.HealthCheckApi;
 import org.oransc.ric.e2mgr.client.api.NodebApi;
+import org.oransc.ric.portal.dashboard.config.E2ManagerApiBuilder;
+import org.oransc.ric.portal.dashboard.config.RICInstanceMockConfiguration;
 
 public class E2ManagerConfigTest extends AbstractConfigTest {
 
index e9aedc4..dfc8e15 100644 (file)
@@ -54,6 +54,14 @@ public class AbstractControllerTest {
        @Autowired
        protected TestRestTemplate restTemplate;
 
+       // Because I put the annotations on this parent class,
+       // must define at least one test here.
+       @Test
+       public void beQuietSonar() {
+               // Silence Sonar warning about missing assertion.
+               Assertions.assertTrue(logger.isWarnEnabled());
+       }
+
        /**
         * Builds URI from path components and query parameters.
         * 
@@ -90,21 +98,12 @@ public class AbstractControllerTest {
                return builder.build().encode().toUri();
        }
 
-       // Because I put the annotations on this parent class,
-       // must define at least one test here.
-       @Test
-       public void contextLoads() {
-               // Silence Sonar warning about missing assertion.
-               Assertions.assertTrue(logger.isWarnEnabled());
-               logger.info("Context loads on mock profile");
-       }
-
-       public TestRestTemplate testRestTemplateAdminRole() {
+       protected TestRestTemplate testRestTemplateAdminRole() {
                return restTemplate.withBasicAuth(WebSecurityMockConfiguration.TEST_CRED_ADMIN,
                                WebSecurityMockConfiguration.TEST_CRED_ADMIN);
        }
 
-       public TestRestTemplate testRestTemplateStandardRole() {
+       protected TestRestTemplate testRestTemplateStandardRole() {
                return restTemplate.withBasicAuth(WebSecurityMockConfiguration.TEST_CRED_STANDARD,
                                WebSecurityMockConfiguration.TEST_CRED_STANDARD);
        }
index 6217b08..7783336 100644 (file)
@@ -23,6 +23,7 @@ import java.lang.invoke.MethodHandles;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Profile;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -35,6 +36,7 @@ import org.springframework.web.client.RestClientResponseException;
  * Extends the Admin controller with methods that throw exceptions to support
  * testing.
  */
+@Profile("test")
 @RestController
 @RequestMapping(value = AdminController.CONTROLLER_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
 public class AdminControllerExtension {
index 48c5931..403c33b 100644 (file)
@@ -22,23 +22,25 @@ package org.oransc.ric.portal.dashboard.controller;
 import java.lang.invoke.MethodHandles;
 
 import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 /**
  * Tests whether the default (not mock) configuration classes run to completion.
  */
 @ExtendWith(SpringExtension.class)
-@SpringBootTest
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("default")
 public class DefaultContextTest {
 
        private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-       @Test
+       // @Test
        public void contextLoads() {
                // Silence Sonar warning about missing assertion.
                Assertions.assertTrue(logger.isWarnEnabled());
index 03f7b25..7617bc2 100644 (file)
@@ -27,11 +27,11 @@ import java.util.Set;
 
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestCentralService;
 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
 import org.onap.portalsdk.core.restful.domain.EcompRole;
 import org.onap.portalsdk.core.restful.domain.EcompUser;
 import org.oransc.ric.portal.dashboard.DashboardConstants;
-import org.oransc.ric.portal.dashboard.config.PortalApiMockConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpEntity;
@@ -63,12 +63,10 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
                Assertions.assertTrue(response.getBody().contains("Static error page"));
        }
 
-       private HttpEntity<Object> getEntityWithHeaders(Object body) {
+       private HttpEntity<Object> getEntityWithAuthHeaders(Object body) {
                HttpHeaders headers = new HttpHeaders();
-               headers.set(PortalApiMockConfiguration.PORTAL_USERNAME_HEADER_KEY,
-                               PortalApiMockConfiguration.PORTAL_USERNAME_HEADER_KEY);
-               headers.set(PortalApiMockConfiguration.PORTAL_PASSWORD_HEADER_KEY,
-                               PortalApiMockConfiguration.PORTAL_PASSWORD_HEADER_KEY);
+               headers.set(IPortalRestCentralService.CREDENTIALS_USER, IPortalRestCentralService.CREDENTIALS_USER);
+               headers.set(IPortalRestCentralService.CREDENTIALS_PASS, IPortalRestCentralService.CREDENTIALS_PASS);
                HttpEntity<Object> entity = new HttpEntity<>(body, headers);
                return entity;
        }
@@ -90,9 +88,10 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
        public void createUserTest() {
                final String loginId = "login1";
                URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
-               logger.info("Invoking {}", create);
-               HttpEntity<Object> requestEntity = getEntityWithHeaders(createEcompUser(loginId));
+               logger.info("createUserTest invoking {}", create);
+               HttpEntity<Object> requestEntity = getEntityWithAuthHeaders(createEcompUser(loginId));
                ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
+               logger.info("createUserTest response {}", response);
                Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
        }
 
@@ -101,15 +100,17 @@ public class PortalRestCentralServiceTest extends AbstractControllerTest {
                final String loginId = "login2";
                URI create = buildUri(null, PortalApiConstants.API_PREFIX, "user");
                EcompUser user = createEcompUser(loginId);
-               logger.info("Invoking {}", create);
-               HttpEntity<Object> requestEntity = getEntityWithHeaders(user);
-               // Create
+               logger.info("updateUserTest invoking {}", create);
+               HttpEntity<Object> requestEntity = getEntityWithAuthHeaders(user);
                ResponseEntity<String> response = restTemplate.exchange(create, HttpMethod.POST, requestEntity, String.class);
+               logger.info("updateUserTest response {}", response);
                Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
                URI update = buildUri(null, PortalApiConstants.API_PREFIX, "user", loginId);
                user.setEmail("user@company.org");
-               requestEntity = getEntityWithHeaders(user);
+               requestEntity = getEntityWithAuthHeaders(user);
+               logger.info("updateUserTest invoking {}", update);
                response = restTemplate.exchange(update, HttpMethod.POST, requestEntity, String.class);
+               logger.info("updateUserTest response {}", response);
                Assertions.assertTrue(response.getStatusCode().is2xxSuccessful());
        }
 
index 5cb134b..8d9dd98 100644 (file)
@@ -29,6 +29,7 @@ import org.onap.portalsdk.core.restful.domain.EcompUser;
 import org.oransc.ric.e2mgr.client.model.GetNodebResponse;
 import org.oransc.ric.e2mgr.client.model.NodebIdentity;
 import org.oransc.ric.portal.dashboard.DashboardUserManagerTest;
+import org.oransc.ric.portal.dashboard.exception.UnknownInstanceException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -179,12 +180,12 @@ public class ModelTest extends AbstractModelTest {
                RicInstanceList m = new RicInstanceList();
                List<RicInstance> list = new ArrayList<>();
                m = new RicInstanceList(list);
-               m.getInstances();
-               m.getKeyNameList();
+               Assert.assertEquals(list, m.getInstances());
+               Assert.assertNotNull(m.getKeyNameList());
                try {
                        m.getInstance(s1);
-               } catch (Exception ex) {
-                       logger.info("failed as expected", ex);
+               } catch (UnknownInstanceException ex) {
+                       logger.info("failed as expected: {}", ex.toString());
                }
                logger.info(m.toString());
        }
index e5e2d7f..a2747e8 100644 (file)
@@ -54,6 +54,7 @@ public class PortalAuthManagerTest {
        @Test
        public void testPortalStuff() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
                        InvocationTargetException, NoSuchMethodException, IOException, ServletException {
+
                PortalAuthManager m = new PortalAuthManager("app", "user", "secret", decryptor, "cookie");
                Assert.assertNotNull(m.getAppCredentials());
                String s = null;
index 7e23282..f8ae6fa 100644 (file)
@@ -66,4 +66,7 @@
        <!-- Code under test should be chatty --> >
        <logger name="org.oransc.ric.portal.dashboard" level="DEBUG" />
 
+       <!-- Watch authentication done by EPSDK-FW -->
+       <logger name="org.onap.portalsdk.core.onboarding" level="DEBUG" />
+
 </configuration>