summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHima Elisetty <hbindu@research.att.com>2018-01-12 10:36:42 -0500
committerHima Elisetty <hbindu@research.att.com>2018-01-17 12:08:18 -0500
commit1298fd26f37cd451cbf1adbea68b98151662e796 (patch)
treeca09e0586c1d0d401841fc6e12228e4dbc7f2f6f
parent304033445a8333cd088910fc3e43ca9222237816 (diff)
Introduce JUNIT Plumbing
Issue-ID: PORTAL-161, PORTAL-160, PORTAL-159 Includes Change in encryption and decryption algorithm Change-Id: I5f379d6d9ac25536744152ac1d61223a52f1ce7f Signed-off-by: Hima Elisetty <hbindu@research.att.com>
-rw-r--r--ecomp-sdk/epsdk-analytics/pom.xml33
-rw-r--r--ecomp-sdk/epsdk-app-common/README.md5
-rw-r--r--ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkDMLMySql_2_1_Common.sql30
-rw-r--r--ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Rollback_2_1_to_1710_Common.sql10
-rw-r--r--ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Upgrade_1710_to_2_1_Common.sql36
-rw-r--r--ecomp-sdk/epsdk-app-common/pom.xml7
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java2
-rw-r--r--ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FuncMenuController.java2
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularAdminControllerTest.java (renamed from ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/ProfileServiceTest.java)68
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java63
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapTest.java56
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/BootstrapSampleControllerTest.java (renamed from ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/SanityTest.java)33
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleControllerTest.java311
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleFunctionListControllerTest.java249
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleListControllerTest.java209
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SingleSignOnControllerTest.java297
-rw-r--r--ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/framework/MockitoTestSuite.java (renamed from ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/workflow/services/WorkflowScheduleServiceTest.java)82
-rw-r--r--ecomp-sdk/epsdk-app-os/README.md8
-rw-r--r--ecomp-sdk/epsdk-app-os/db-scripts/EcompSdkDMLMySql_2_1_OS.sql12
-rw-r--r--ecomp-sdk/epsdk-app-os/pom.xml73
-rw-r--r--ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java2
-rw-r--r--ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/fusion/jsp/ds2/left-menu.jsp9
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp7
-rw-r--r--ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/directives/header.js24
-rw-r--r--ecomp-sdk/epsdk-core/pom.xml7
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java2
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/interceptor/ResourceInterceptor.java2
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java4
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RestApiRequestBuilder.java6
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UrlAccessImpl.java2
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/WebServiceCallServiceImpl.java2
-rw-r--r--ecomp-sdk/epsdk-fw/pom.xml8
-rw-r--r--ecomp-sdk/epsdk-workflow/pom.xml7
-rw-r--r--ecomp-sdk/pom.xml75
34 files changed, 1505 insertions, 238 deletions
diff --git a/ecomp-sdk/epsdk-analytics/pom.xml b/ecomp-sdk/epsdk-analytics/pom.xml
index 9d433363..57dbdc0a 100644
--- a/ecomp-sdk/epsdk-analytics/pom.xml
+++ b/ecomp-sdk/epsdk-analytics/pom.xml
@@ -19,7 +19,31 @@
<!-- properties are inherited from parent -->
<!-- repositories are inherited from parent -->
-
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <!-- version managed by oparent ${jacocoVersion}</version> -->
+ <executions>
+ <execution>
+ <id>portal-offline-instrument</id>
+ <phase>none</phase>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>portal-restore-instrumented-classes</id>
+ <phase>none</phase>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+</build>
<dependencies>
<!-- sdk-core -->
@@ -160,6 +184,13 @@
</exclusion>
</exclusions>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacoco.version}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-app-common/README.md b/ecomp-sdk/epsdk-app-common/README.md
index e72d9420..2ba60d3b 100644
--- a/ecomp-sdk/epsdk-app-common/README.md
+++ b/ecomp-sdk/epsdk-app-common/README.md
@@ -24,6 +24,11 @@ AngularJS version 1.5.0.
### ONAP Distributions
+Version 2.1.0
+- PORTAL 161 Add the JUNIT plumbing for PortalSDK
+- PORTAL 160 Prevent unauthorized access to SamplePages, Report Pages, Role
+- PORTAL 159 Change the encryption algorithm to PKCS5PADDING
+
Version 1.4.0
- PORTAL-19 Rename Java package base to org.onap
- PORTAL-42 Use OParent as parent POM
diff --git a/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkDMLMySql_2_1_Common.sql b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkDMLMySql_2_1_Common.sql
index 18de88fd..7617e4e8 100644
--- a/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkDMLMySql_2_1_Common.sql
+++ b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkDMLMySql_2_1_Common.sql
@@ -136,6 +136,36 @@ INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab3.htm','
INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('tab4.htm','menu_tab');
INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor.htm','view_reports');
INSERT INTO fn_restricted_url (restricted_url, function_cd) VALUES ('raptor_blob_extract.htm','view_reports');
+INSERT INTO fn_restricted_url VALUES('admin','menu_admin');
+INSERT INTO fn_restricted_url VALUES('get_role','menu_admin');
+INSERT INTO fn_restricted_url VALUES('get_role_functions','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role_list/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role_function_list/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('addRole','menu_admin');
+INSERT INTO fn_restricted_url VALUES('addRoleFunction','menu_admin');
+INSERT INTO fn_restricted_url VALUES('removeRole','menu_admin');
+INSERT INTO fn_restricted_url VALUES('removeRoleFunction','menu_admin');
+INSERT INTO fn_restricted_url VALUES('profile/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('samplePage','menu_sample');
+INSERT INTO fn_restricted_url VALUES('workflows','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/list','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/addWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/saveCronJob','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/editWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/removeWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/removeAllWorkflows','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role/saveRole.htm','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/process','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/search','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/search','menu_profile');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_def_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_form_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_sql_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/security/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/copy_report/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/save_def_tab_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_data/true','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/security/*','menu_reports');
-- fn_role
Insert into fn_role (ROLE_ID,ROLE_NAME,ACTIVE_YN,PRIORITY) values (16,'Standard User','Y',5);
diff --git a/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Rollback_2_1_to_1710_Common.sql b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Rollback_2_1_to_1710_Common.sql
new file mode 100644
index 00000000..14ef6f1e
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Rollback_2_1_to_1710_Common.sql
@@ -0,0 +1,10 @@
+use ecomp_sdk;
+
+DELETE FROM fn_restricted_url
+where RESTRICTED_URL in('admin', 'get_role', 'get_role_functions', 'role_list/*', 'role_function_list/*', 'addRole', 'addRoleFunction', 'removeRole',
+ 'removeRoleFunction', 'profile/*', 'samplePage','workflows', 'workflows/list', 'workflows/addWorkflow', 'workflows/saveCronJob',
+ 'workflows/editWorkflow', 'workflows/removeWorkflow', 'workflows/removeAllWorkflows','role/saveRole.htm','post_search/process', 'post_search/search', 'report/wizard/retrieve_def_tab_wise_data/*',
+ 'report/wizard/retrieve_form_tab_wise_data/*', 'report/wizard/retrieve_sql_tab_wise_data/*', 'report/wizard/security/*', 'report/wizard/copy_report/*', 'report/wizard/save_def_tab_data/*', 'report/wizard/retrieve_data/true',
+ 'report/security/*');
+
+commit; \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Upgrade_1710_to_2_1_Common.sql b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Upgrade_1710_to_2_1_Common.sql
new file mode 100644
index 00000000..08f0d38f
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/db-scripts/EcompSdkMySql_Upgrade_1710_to_2_1_Common.sql
@@ -0,0 +1,36 @@
+use ecomp_sdk;
+
+SET FOREIGN_KEY_CHECKS=0;
+
+INSERT INTO fn_restricted_url VALUES('admin','menu_admin');
+INSERT INTO fn_restricted_url VALUES('get_role','menu_admin');
+INSERT INTO fn_restricted_url VALUES('get_role_functions','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role_list/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role_function_list/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('addRole','menu_admin');
+INSERT INTO fn_restricted_url VALUES('addRoleFunction','menu_admin');
+INSERT INTO fn_restricted_url VALUES('removeRole','menu_admin');
+INSERT INTO fn_restricted_url VALUES('removeRoleFunction','menu_admin');
+INSERT INTO fn_restricted_url VALUES('profile/*','menu_admin');
+INSERT INTO fn_restricted_url VALUES('samplePage','menu_sample');
+INSERT INTO fn_restricted_url VALUES('workflows','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/list','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/addWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/saveCronJob','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/editWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/removeWorkflow','menu_admin');
+INSERT INTO fn_restricted_url VALUES('workflows/removeAllWorkflows','menu_admin');
+INSERT INTO fn_restricted_url VALUES('role/saveRole.htm','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/process','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/search','menu_admin');
+INSERT INTO fn_restricted_url VALUES('post_search/search','menu_profile');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_def_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_form_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_sql_tab_wise_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/security/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/copy_report/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/save_def_tab_data/*','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/wizard/retrieve_data/true','menu_reports');
+INSERT INTO fn_restricted_url VALUES('report/security/*','menu_reports');
+
+commit; \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-app-common/pom.xml b/ecomp-sdk/epsdk-app-common/pom.xml
index cb14aec0..a017ea0d 100644
--- a/ecomp-sdk/epsdk-app-common/pom.xml
+++ b/ecomp-sdk/epsdk-app-common/pom.xml
@@ -237,5 +237,12 @@
<artifactId>esapi</artifactId>
<version>2.1.0</version>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacoco.version}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
index da26fe69..82c13f10 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FavoritesController.java
@@ -109,7 +109,7 @@ public class FavoritesController extends RestrictedBaseController {
appName = app.getName();
appUserName = app.getUsername();
try {
- decryptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,
diff --git a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FuncMenuController.java b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FuncMenuController.java
index 3ad49860..716f8e03 100644
--- a/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FuncMenuController.java
+++ b/ecomp-sdk/epsdk-app-common/src/main/java/org/onap/portalapp/controller/core/FuncMenuController.java
@@ -172,7 +172,7 @@ public class FuncMenuController extends RestrictedBaseController {
appName = app.getName();
appUserName = app.getUsername();
try {
- decryptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/ProfileServiceTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularAdminControllerTest.java
index 36d54ba6..02755b4a 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/service/ProfileServiceTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularAdminControllerTest.java
@@ -35,39 +35,59 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.portalapp.service;
+package org.onap.portalapp.controller.core;
-import java.util.List;
+import static org.junit.Assert.*;
-import org.junit.Assert;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
import org.junit.Test;
-import org.onap.portalapp.core.MockApplicationContextTestSuite;
-import org.onap.portalsdk.core.domain.Profile;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.framework.MockitoTestSuite;
import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.service.ProfileService;
-import org.onap.portalsdk.core.service.UserProfileService;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.web.servlet.ModelAndView;
-public class ProfileServiceTest extends MockApplicationContextTestSuite {
+public class AngularAdminControllerTest {
- @Autowired
- ProfileService service;
-
- @Autowired
- UserProfileService userProfileService;
+ @InjectMocks
+ AngularAdminController angularAdminController = new AngularAdminController();
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+
+ NullPointerException nullPointerException = new NullPointerException();
+
+ User user = new User();
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
@Test
- public void testFindAll() throws Exception {
-
- List<Profile> profiles = service.findAll();
- Assert.assertTrue(profiles.size() > 0);
+ public void viewTest() {
+ ModelAndView modelandView = new ModelAndView("user_profile_list");
+ ModelAndView expectedModelandView = angularAdminController.view();
+ assertEquals(expectedModelandView.getViewName(), modelandView.getViewName());
}
-
+
@Test
- public void testFindAllActive() {
-
- List<User> users = userProfileService.findAllActive();
- List<User> activeUsers = userProfileService.findAllActive();
- Assert.assertTrue(users.size() - activeUsers.size() >= 0);
+ public void adminViewTest() {
+ ModelAndView expectedModelandView = angularAdminController.adminView();
+ assertNull(expectedModelandView.getViewName());
}
}
+
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java
deleted file mode 100644
index e6e604cb..00000000
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software 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.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * 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============================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.portalapp.controller;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.portalapp.core.MockApplicationContextTestSuite;
-import org.onap.portalsdk.core.domain.User;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.springframework.test.web.servlet.ResultActions;
-import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-
-public class CollaborationControllerTest extends MockApplicationContextTestSuite {
-
- @Test
- public void testGetAvailableRoles() throws Exception {
- MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/collaborate_list");
- User user = new User();
- user.setId(1l);
- // user.setOrgUserId("abc");
- requestBuilder.sessionAttr(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME), user);
-
- ResultActions ra = getMockMvc().perform(requestBuilder);
- Assert.assertEquals(2, ra.andReturn().getModelAndView().getModelMap().size());
- }
-
-}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapTest.java
deleted file mode 100644
index 61973f64..00000000
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ============LICENSE_START==========================================
- * ONAP Portal SDK
- * ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software 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.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * 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============================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-package org.onap.portalapp.controller;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.onap.portalapp.core.MockApplicationContextTestSuite;
-import org.springframework.test.web.servlet.ResultActions;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
-
-public class NetMapTest extends MockApplicationContextTestSuite {
-
- @Test
- public void testGetNetMap() throws Exception {
- ResultActions ra =getMockMvc().perform(MockMvcRequestBuilders.get("/net_map"));
- //Assert.assertEquals(UrlAccessRestrictedException.class,ra.andReturn().getResolvedException().getClass());
- Assert.assertEquals("net_map_int",ra.andReturn().getModelAndView().getModel().get("frame_int"));
- }
-
-
-}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/SanityTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/BootstrapSampleControllerTest.java
index 479f83e0..2980c7ce 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/SanityTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/BootstrapSampleControllerTest.java
@@ -35,23 +35,30 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.portalapp;
+package org.onap.portalapp.controller.core;
-import org.junit.Assert;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Before;
import org.junit.Test;
-import org.onap.portalapp.core.MockApplicationContextTestSuite;
-import org.springframework.test.web.servlet.ResultActions;
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.springframework.web.servlet.ModelAndView;
+
+public class BootstrapSampleControllerTest {
+
+ @InjectMocks
+ BootstrapSampleController bootstrapSampleController = new BootstrapSampleController();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
-public class SanityTest extends MockApplicationContextTestSuite {
-
@Test
- public void testGetAvailableRoles() throws Exception {
-
- ResultActions ra =getMockMvc().perform(MockMvcRequestBuilders.get("/api/roles"));
- //Assert.assertEquals(UrlAccessRestrictedException.class,ra.andReturn().getResolvedException().getClass());
- Assert.assertEquals("application/json",ra.andReturn().getResponse().getContentType());
+ public void welcomeTest() {
+ ModelAndView expectedResluts = bootstrapSampleController.welcome();
+ assertNull(expectedResluts.getViewName());
}
-
}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleControllerTest.java
new file mode 100644
index 00000000..81bbaee2
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleControllerTest.java
@@ -0,0 +1,311 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.controller.core;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.framework.MockitoTestSuite;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.service.RoleService;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.web.bind.ServletRequestUtils;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class RoleControllerTest {
+
+ @InjectMocks
+ RoleController roleController = new RoleController();
+
+ @Mock
+ RoleService roleService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
+ @Mock
+ ServletRequestUtils servletRequestUtils;
+
+ @Mock
+ ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void roleTest() throws IOException {
+ roleController.setViewName("Test");
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>();
+ List<Role> roleList = new ArrayList<Role>();
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunctionList);
+ Mockito.when(roleService.getAvailableChildRoles(Matchers.anyString(), Matchers.anyLong())).thenReturn(roleList);
+ ModelAndView expectedResult = roleController.role(mockedRequest);
+ assertEquals(expectedResult.getViewName(), "Test");
+ }
+
+ @Test
+ public void roleExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenThrow(nullPointerException);
+ ModelAndView expectedResult = roleController.role(mockedRequest);
+ assertNull(expectedResult.getViewName(), null);
+ }
+
+ @Test
+ public void getRoleTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>();
+ List<Role> roleList = new ArrayList<Role>();
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunctionList);
+ Mockito.when(roleService.getAvailableChildRoles(Matchers.anyString(), Matchers.anyLong())).thenReturn(roleList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleController.getRole(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void getRoleExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>();
+ List<Role> roleList = new ArrayList<Role>();
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunctionList);
+ Mockito.when(roleService.getAvailableChildRoles(Matchers.anyString(), Matchers.anyLong())).thenReturn(roleList);
+ roleController.getRole(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void saveRoleTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setId((long) 1);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), role.getId())).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.saveRole(mockedRequest, mockedResponse));
+
+ }
+
+ @Test
+ public void saveRoleWithRoleFunctionsTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test role modified test\",\"active\":true,\"priority\":null,\"roleFunctions\":[{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=9356\",\"toggleActiveImage\":\"/static/fusion/images/active.png\",\"toggleActiveAltText\":\"Click to Deactivate Role\"},\"childRoles\":[],\"roleFunctions\":[{\"id\":9356,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setId((long) 1);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), role.getId())).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.saveRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void saveNewRoleTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":null,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setId((long) 1);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), role.getId())).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ List<Role> roleList = new ArrayList<Role>();
+ Role role1 = new Role();
+ role1.setName("TestRole1");
+ Role role2 = new Role();
+ role2.setName("TestRole2");
+ roleList.add(role1);
+ roleList.add(role2);
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenReturn(roleList);
+ assertNull(roleController.saveRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void saveNewRoleExceptionTestIfRoleNameExistsTest() throws IOException {
+
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":null,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"TestRole1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setId((long) 1);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), role.getId())).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ List<Role> roleList = new ArrayList<Role>();
+ Role role1 = new Role();
+ role1.setName("TestRole1");
+ Role role2 = new Role();
+ role2.setName("TestRole2");
+ roleList.add(role1);
+ roleList.add(role2);
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenReturn(roleList);
+ assertNull(roleController.saveRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void removeRoleFunctionTest() throws IOException
+ {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"roleFunction\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.removeRoleFunction(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void removeRoleFunctionExceptionTest() throws IOException
+ {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"roleFunction\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.removeRoleFunction(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void saveRoleFunctionTest() throws IOException
+ {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"roleFunction\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenReturn(expectedRole);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.addRoleFunction(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void saveRoleFunctionExceptionTest() throws IOException
+ {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"roleFunction\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"code\":\"menu_test\",\"name\":\"Test Menu\",\"editUrl\":\"/role_function.htm?role_function_id=menu_test\",\"$$hashKey\":\"object:1476\"}}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role expectedRole = new Role();
+ expectedRole.setId((long) 1);
+ Mockito.when(roleService.getRole(Matchers.anyString(), Matchers.anyLong())).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleController.addRoleFunction(mockedRequest, mockedResponse));
+ }
+}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleFunctionListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleFunctionListControllerTest.java
new file mode 100644
index 00000000..d30dc1d6
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleFunctionListControllerTest.java
@@ -0,0 +1,249 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.controller.core;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.framework.MockitoTestSuite;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.service.RoleService;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.web.bind.ServletRequestUtils;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class RoleFunctionListControllerTest {
+
+ @InjectMocks
+ RoleFunctionListController roleFunctionListController = new RoleFunctionListController();
+
+ @Mock
+ RoleService roleService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
+ @Mock
+ ServletRequestUtils servletRequestUtils;
+
+ @Mock
+ ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void welcomeTest() throws IOException {
+ roleFunctionListController.setViewName("Test");
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>();
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunctionList);
+ ModelAndView expectedResult = roleFunctionListController.welcome(mockedRequest);
+ assertEquals(expectedResult.getViewName(), "Test");
+ }
+
+ @Test
+ public void welcomeExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenThrow(nullPointerException);
+ ModelAndView expectedResult = roleFunctionListController.welcome(mockedRequest);
+ assertNull(expectedResult.getViewName());
+ }
+
+ @Test
+ public void getRoleFunctionListTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>();
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunctionList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.getRoleFunctionList(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void getRoleFunctionListExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenThrow(nullPointerException);
+ roleFunctionListController.getRoleFunctionList(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void saveRoleFunctionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ RoleFunction roleFunction = new RoleFunction();
+ Mockito.when(roleService.getRoleFunction(user.getOrgUserId(), "Test")).thenReturn(roleFunction);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.saveRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+
+ @Test(expected = java.io.IOException.class)
+ public void saveRoleFunctionExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ Mockito.when(roleService.getRoleFunction(user.getOrgUserId(), "Test")).thenThrow(nullPointerException);
+ roleFunctionListController.saveRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+
+ @Test
+ public void addRoleFunctionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ List<RoleFunction> roleFunList = new ArrayList<>();
+ RoleFunction roleFun1 = new RoleFunction();
+ roleFun1.setName("TestRoleFun1");
+ roleFun1.setCode("TestRoleFunCode1");
+ roleFunList.add(roleFun1);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.addRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+
+ @Test
+ public void addRoleFunctionExsistsTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ List<RoleFunction> roleFunList = new ArrayList<>();
+ RoleFunction roleFun1 = new RoleFunction();
+ roleFun1.setName("Test");
+ roleFun1.setCode("Test");
+ roleFunList.add(roleFun1);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenReturn(roleFunList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.addRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+
+ @Test(expected = java.io.IOException.class)
+ public void addRoleFunctionExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ List<RoleFunction> roleFunList = new ArrayList<>();
+ RoleFunction roleFun1 = new RoleFunction();
+ roleFun1.setName("Test");
+ roleFun1.setCode("Test");
+ roleFunList.add(roleFun1);
+ Mockito.when(roleService.getRoleFunctions(user.getOrgUserId())).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.addRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+
+ @Test
+ public void removeRoleFunctionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ RoleFunction roleFun1 = new RoleFunction();
+ roleFun1.setName("Test");
+ roleFun1.setCode("Test");
+ Mockito.when((roleService.getRoleFunction(user.getOrgUserId(), "Test"))).thenReturn(roleFun1);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.removeRoleFunction(mockedRequest, mockedResponse, roleFun);
+
+ }
+
+ @Test(expected = java.io.IOException.class)
+ public void removeRoleFunctionExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
+ RoleFunction roleFun1 = new RoleFunction();
+ roleFun1.setName("Test");
+ roleFun1.setCode("Test");
+ Mockito.when((roleService.getRoleFunction(user.getOrgUserId(), "Test"))).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleFunctionListController.removeRoleFunction(mockedRequest, mockedResponse, roleFun);
+ }
+}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleListControllerTest.java
new file mode 100644
index 00000000..9a576761
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/RoleListControllerTest.java
@@ -0,0 +1,209 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.portalapp.controller.core;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.framework.MockitoTestSuite;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.service.RoleService;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.springframework.web.bind.ServletRequestUtils;
+import org.springframework.web.servlet.ModelAndView;
+import org.onap.portalapp.controller.core.RoleListController;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class RoleListControllerTest {
+
+ @InjectMocks
+ RoleListController roleListController = new RoleListController();
+
+ @Mock
+ RoleService roleService;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Mock
+ UserUtils userUtils = new UserUtils();
+
+ @Mock
+ ServletRequestUtils servletRequestUtils;
+
+ @Mock
+ ObjectMapper mapper = new ObjectMapper();
+
+ @Test
+ public void getRoleListTest() throws IOException {
+ roleListController.setViewName("Test");
+ User user = new User();
+ user.setOrgUserId("test12");
+ List<Role> roleList = new ArrayList<>();
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenReturn(roleList);
+ ModelAndView expectedResult = roleListController.getRoleList(mockedRequest);
+ assertEquals(expectedResult.getViewName(), "Test");
+ }
+
+ @Test
+ public void getRoleListExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenThrow(nullPointerException);
+ ModelAndView expectedResult = roleListController.getRoleList(mockedRequest);
+ assertNull(expectedResult.getViewName());
+ }
+
+ @Test
+ public void getRolesTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ List<Role> roleList = new ArrayList<>();
+ Role role = new Role();
+ role.setId((long) 1);
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenReturn(roleList);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ roleListController.getRoles(mockedRequest, mockedResponse);
+
+ }
+
+ @Test
+ public void getRolesExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenThrow(nullPointerException);
+ roleListController.getRoles(mockedRequest, mockedResponse);
+ }
+
+ @Test
+ public void toggleRoleTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setActive(true);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), (long) 1)).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleListController.toggleRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void toggleRoleExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setActive(true);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), (long) 1)).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleListController.toggleRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void removeRoleTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setActive(true);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), (long) 1)).thenReturn(role);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ List<Role> roleList = new ArrayList<>();
+ Mockito.when(roleService.getAvailableRoles(user.getOrgUserId())).thenReturn(roleList);
+ assertNull(roleListController.removeRole(mockedRequest, mockedResponse));
+ }
+
+ @Test
+ public void removeRoleExceptionTest() throws IOException {
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}";
+ Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json)));
+ Role role = new Role();
+ role.setActive(true);
+ Mockito.when(roleService.getRole(user.getOrgUserId(), (long) 1)).thenThrow(nullPointerException);
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+ Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
+ assertNull(roleListController.removeRole(mockedRequest, mockedResponse));
+ }
+}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SingleSignOnControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SingleSignOnControllerTest.java
new file mode 100644
index 00000000..f1d4aa05
--- /dev/null
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SingleSignOnControllerTest.java
@@ -0,0 +1,297 @@
+/*
+ * ============LICENSE_START==========================================
+ * ONAP Portal SDK
+ * ===================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.controller.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.framework.MockitoTestSuite;
+import org.onap.portalsdk.core.auth.LoginStrategy;
+import org.onap.portalsdk.core.command.LoginBean;
+import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
+import org.onap.portalsdk.core.menu.MenuProperties;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.portalsdk.core.service.LoginService;
+import org.onap.portalsdk.core.service.RoleService;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.util.WebUtils;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ URLDecoder.class, SystemProperties.class, URLEncoder.class, PortalApiProperties.class, WebUtils.class,
+ UserUtils.class })
+public class SingleSignOnControllerTest {
+
+ @InjectMocks
+ SingleSignOnController singleSignOnController = new SingleSignOnController();
+
+ @Mock
+ RoleService roleService;
+
+ @Mock
+ LoginService loginService;
+
+ @Mock
+ LoginStrategy loginStrategy;
+
+ @Mock
+ URLDecoder uRLDecoder;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
+
+ HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
+ HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
+ NullPointerException nullPointerException = new NullPointerException();
+
+ @Test(expected = java.lang.SecurityException.class)
+ public void singleSignOnLoginExceptionTest() throws Exception {
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("Test");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("Test");
+ Mockito.when(SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.APP_BASE_URL)).thenReturn("http://TestUrl");
+ Mockito.when(SystemProperties.getProperty(SystemProperties.COOKIE_DOMAIN)).thenReturn("te");
+ singleSignOnController.singleSignOnLogin(mockedRequest);
+
+ }
+
+ @Test
+ public void singleSignOnLoginTest() throws Exception {
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("Test");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(URLEncoder.class);
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("Test");
+ Mockito.when(SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.APP_BASE_URL)).thenReturn("http://TestUrl");
+ Mockito.when(SystemProperties.getProperty(SystemProperties.COOKIE_DOMAIN)).thenReturn("TestUrl");
+ Mockito.when(URLEncoder.encode("http://TestUrl/Test", "UTF-8")).thenReturn("encodeTestUrl");
+ Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("uebkey");
+ Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL))
+ .thenReturn("http://test.com/roles");
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(),
+ "redirect:http://test.com/process_csp?uebAppKey=uebkey&redirectUrl=http%3A%2F%2FTestUrl%2FTest");
+ }
+
+ @Test
+ public void singleSignOnLoginIfUrlIsNotAppBasedTest() throws Exception {
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("Test");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(URLEncoder.class);
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("Test");
+ Mockito.when(SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)).thenReturn(false);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.COOKIE_DOMAIN)).thenReturn("test.com");
+ Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("uebkey");
+ Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REDIRECT_URL))
+ .thenReturn("http://test.com/roles");
+ StringBuffer stringBuffer = new StringBuffer("http://test.com/testSDK");
+ Mockito.when(mockedRequest.getRequestURL()).thenReturn(stringBuffer);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(),
+ "redirect:http://test.com/process_csp?uebAppKey=uebkey&redirectUrl=http%3A%2F%2Ftest.com%2FtestSDK");
+ }
+
+ @Test
+ public void singleSignOnTest() throws Exception {
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("http://Test.com");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(WebUtils.class);
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("http://Test.com");
+ Mockito.when(mockedRequest.getParameter("redirectToPortal")).thenReturn(null);
+ Mockito.when(SystemProperties.containsProperty(SystemProperties.APP_BASE_URL)).thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.APP_BASE_URL)).thenReturn("http://TestUrl");
+ Mockito.when(SystemProperties.getProperty(SystemProperties.COOKIE_DOMAIN)).thenReturn("Test.com");
+ Mockito.when(WebUtils.getCookie(mockedRequest, "EPService")).thenReturn(new Cookie("test", "test"));
+ User user = new User();
+ user.setOrgUserId("test12");
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(), "redirect:http://Test.com");
+
+ }
+
+ @Test
+ public void singleSignOnIfUserNullTest() throws Exception {
+ User user = null;
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("http://Test.com");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(WebUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("http://Test.com");
+ Mockito.when(WebUtils.getCookie(mockedRequest, "EPService")).thenReturn(new Cookie("test", "test"));
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("testauth");
+ Mockito.when(loginStrategy.getUserId(mockedRequest)).thenReturn("test1234");
+ Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)).thenReturn("test");
+ LoginBean commandBean = new LoginBean();
+ commandBean.setUserid("test1234");
+ commandBean.setUser(null);
+ Mockito.when(loginService.findUser(Matchers.any(), Matchers.anyString(), Matchers.anyMap()))
+ .thenReturn(commandBean);
+ List<RoleFunction> roleFunctionList = new ArrayList<>();
+ Mockito.when(roleService.getRoleFunctions("test1234")).thenReturn(roleFunctionList);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(), "redirect:null?noUserError=Yes");
+ }
+
+ @Test
+ public void singleSignOnIfUserNotNullTest() throws Exception {
+ User user = null;
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("http://Test.com");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(WebUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(UserUtils.class);
+
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("http://Test.com");
+ Mockito.when(WebUtils.getCookie(mockedRequest, "EPService")).thenReturn(new Cookie("test", "test"));
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("testauth");
+ Mockito.when(loginStrategy.getUserId(mockedRequest)).thenReturn("test1234");
+ Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)).thenReturn("test");
+ LoginBean commandBean = new LoginBean();
+ commandBean.setUserid("test1234");
+ User user1 = new User();
+ user1.setId((long) 1);
+ commandBean.setUser(user1);
+ Mockito.when(loginService.findUser(Matchers.any(), Matchers.anyString(), Matchers.anyMap()))
+ .thenReturn(commandBean);
+ List<RoleFunction> roleFunctionList = new ArrayList<>();
+ Mockito.when(roleService.getRoleFunctions("test1234")).thenReturn(roleFunctionList);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(), "redirect:http://Test.com");
+ }
+
+ @Test
+ public void singleSignOnIfUserNotNullAndAuthNullTest() throws Exception {
+ User user = null;
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("http://Test.com");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(WebUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(UserUtils.class);
+
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("http://Test.com");
+ Mockito.when(WebUtils.getCookie(mockedRequest, "EPService")).thenReturn(new Cookie("test", "test"));
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn(null);
+ Mockito.when(loginStrategy.getUserId(mockedRequest)).thenReturn("test1234");
+ Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)).thenReturn("test");
+ LoginBean commandBean = new LoginBean();
+ commandBean.setUserid("test1234");
+ User user1 = new User();
+ user1.setId((long) 1);
+ commandBean.setUser(user1);
+ Mockito.when(loginService.findUser(Matchers.any(), Matchers.anyString(), Matchers.anyMap()))
+ .thenReturn(commandBean);
+ List<RoleFunction> roleFunctionList = new ArrayList<>();
+ Mockito.when(roleService.getRoleFunctions("test1234")).thenReturn(roleFunctionList);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(), "redirect:http://Test.com");
+ }
+
+ @Test
+ public void singleSignOnIfUserNotNullAndAuthCSPTest() throws Exception {
+ singleSignOnController.setViewName("test");
+ singleSignOnController.setWelcomeView("welcome");
+ assertEquals(singleSignOnController.getViewName(), "test");
+ assertEquals(singleSignOnController.getWelcomeView(), "welcome");
+ User user = null;
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(mockedRequest.getParameter("forwardURL")).thenReturn("http://Test.com");
+ PowerMockito.mockStatic(URLDecoder.class);
+ PowerMockito.mockStatic(WebUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(UserUtils.class);
+ Mockito.when(URLDecoder.decode(null, "UTF-8")).thenReturn("http://Test.com");
+ Mockito.when(WebUtils.getCookie(mockedRequest, "EPService")).thenReturn(new Cookie("test", "test"));
+ Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
+ Mockito.when(SystemProperties.getProperty(SystemProperties.AUTHENTICATION_MECHANISM)).thenReturn("CSP");
+ Mockito.when(loginStrategy.getUserId(mockedRequest)).thenReturn("test1234");
+ Mockito.when(mockedRequest.getAttribute(MenuProperties.MENU_PROPERTIES_FILENAME_KEY)).thenReturn("test");
+ LoginBean commandBean = new LoginBean();
+ commandBean.setUserid("test1234");
+ User user1 = new User();
+ user1.setId((long) 1);
+ commandBean.setUser(user1);
+ Mockito.when(loginService.findUser(Matchers.any(), Matchers.anyString(), Matchers.anyMap()))
+ .thenReturn(commandBean);
+ List<RoleFunction> roleFunctionList = new ArrayList<>();
+ Mockito.when(roleService.getRoleFunctions("test1234")).thenReturn(roleFunctionList);
+ ModelAndView expectedResults = singleSignOnController.singleSignOnLogin(mockedRequest);
+ assertEquals(expectedResults.getViewName(), "redirect:http://Test.com");
+ }
+
+}
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/workflow/services/WorkflowScheduleServiceTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/framework/MockitoTestSuite.java
index e26c35ab..baac323e 100644
--- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/workflow/services/WorkflowScheduleServiceTest.java
+++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/framework/MockitoTestSuite.java
@@ -1,8 +1,8 @@
-/*
+/*-
* ============LICENSE_START==========================================
- * ONAP Portal SDK
+ * ONAP Portal
* ===================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
@@ -35,41 +35,55 @@
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.portalapp.workflow.services;
+package org.onap.portalapp.framework;
-import java.util.Calendar;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
-import org.junit.Assert;
import org.junit.Test;
-import org.onap.portalapp.core.MockApplicationContextTestSuite;
-import org.onap.portalsdk.workflow.domain.WorkflowSchedule;
-import org.onap.portalsdk.workflow.services.WorkflowScheduleService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public class WorkflowScheduleServiceTest extends MockApplicationContextTestSuite {
-
- @Autowired
- WorkflowScheduleService service;
-
- @Test
- public void testFire() {
-
- final WorkflowSchedule ws = new WorkflowSchedule();
- ws.setId(999L);
- ws.setWorkflowKey("test");
- ws.setCronDetails("0 38 13 3 5 ? 2016");
- final Calendar instance = Calendar.getInstance();
- instance.add(Calendar.YEAR, 3);
- ws.setEndDateTime(instance.getTime());
-
- ws.setStartDateTime(Calendar.getInstance().getTime());
- try {
- service.saveWorkflowSchedule(ws);
- Assert.assertTrue(true);
- } catch (Exception e) {
- Assert.fail(e.getMessage());
- }
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+public class MockitoTestSuite {
+
+ public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper(
+ Mockito.mock(HttpServletRequest.class));
+ public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class);
+
+ public MockHttpServletRequestWrapper getMockedRequest() {
+ return mockedRequest;
}
+ public HttpServletResponse getMockedResponse() {
+ return mockedResponse;
+ }
+
+ public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper {
+
+ HttpSession session = Mockito.mock(HttpSession.class);
+
+ public MockHttpServletRequestWrapper(HttpServletRequest request) {
+ super(request);
+
+ }
+
+ @Override
+ public HttpSession getSession() {
+
+ return session;
+ }
+
+ @Override
+ public HttpSession getSession(boolean create) {
+
+ return session;
+ }
+
+ }
+
}
diff --git a/ecomp-sdk/epsdk-app-os/README.md b/ecomp-sdk/epsdk-app-os/README.md
index daf03237..f74d043f 100644
--- a/ecomp-sdk/epsdk-app-os/README.md
+++ b/ecomp-sdk/epsdk-app-os/README.md
@@ -13,7 +13,13 @@ https://www.eclipse.org/m2e-wtp/
## Release Notes
-Version 1.4.0, <?day> <?month> 2017
+Version 2.1.0
+- PORTAL 161 Refer epsdk-app-common
+- PORTAL 160 Refer epsdk-app-common
+- PORTAL 159 Refer epsdk-app-common
+- PORTAL 136 Junits for SDK
+
+Version 1.4.0
- PORTAL-19 Rename Java package base to org.onap
- PORTAL-42 Use OParent as parent POM
- PORTAL-72 Address Sonar Scan code issues
diff --git a/ecomp-sdk/epsdk-app-os/db-scripts/EcompSdkDMLMySql_2_1_OS.sql b/ecomp-sdk/epsdk-app-os/db-scripts/EcompSdkDMLMySql_2_1_OS.sql
index 91402fb0..cb4a3085 100644
--- a/ecomp-sdk/epsdk-app-os/db-scripts/EcompSdkDMLMySql_2_1_OS.sql
+++ b/ecomp-sdk/epsdk-app-os/db-scripts/EcompSdkDMLMySql_2_1_OS.sql
@@ -36,16 +36,4 @@ Insert into fn_app (APP_ID,APP_NAME,APP_IMAGE_URL,APP_DESCRIPTION,APP_NOTES,APP_
-- fn_user_role
Insert into fn_user_role (USER_ID,ROLE_ID,PRIORITY,APP_ID) values (1,1,null,1);
--- fn_restricted_url
-insert into fn_restricted_url values('admin','menu_admin');
-insert into fn_restricted_url values('get_role','menu_admin');
-insert into fn_restricted_url values('get_role_functions','menu_admin');
-insert into fn_restricted_url values('role_list/*','menu_admin');
-insert into fn_restricted_url values('role_function_list/*','menu_admin');
-insert into fn_restricted_url values('addRole','menu_admin');
-insert into fn_restricted_url values('addRoleFunction','menu_admin');
-insert into fn_restricted_url values('removeRole','menu_admin');
-insert into fn_restricted_url values('removeRoleFunction','menu_admin');
-insert into fn_restricted_url values('profile/*','menu_admin');
-
commit;
diff --git a/ecomp-sdk/epsdk-app-os/pom.xml b/ecomp-sdk/epsdk-app-os/pom.xml
index db0a455f..de941b35 100644
--- a/ecomp-sdk/epsdk-app-os/pom.xml
+++ b/ecomp-sdk/epsdk-app-os/pom.xml
@@ -26,7 +26,8 @@
<!-- Skip assembling the zip; assemble via mvn -Dskipassembly=false .. -->
<skipassembly>true</skipassembly>
<!-- Tests usually require some setup that maven cannot do, so skip. -->
- <skiptests>true</skiptests>
+ <skiptests>false</skiptests>
+ <jacoco.version>0.7.9</jacoco.version>
<!-- Version number gets stored only here -->
<tomcat.download.path>http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.37/bin</tomcat.download.path>
<tomcat.download.name>apache-tomcat-8.0.37</tomcat.download.name>
@@ -60,7 +61,68 @@
</systemPropertyVariables>
</configuration>
</plugin>
-
+
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <!-- version managed by oparent ${jacocoVersion}</version> -->
+ <executions>
+ <!-- disable jacoco executions from oparent -->
+ <execution>
+ <id>pre-unit-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>post-unit-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>pre-integration-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>post-integration-test</id>
+ <phase>none</phase>
+ </execution>
+ <!-- Order matters -->
+ <execution>
+ <id>portal-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${sonar.jacoco.reportPath}</destFile>
+ </configuration>
+ </execution>
+ <!-- offline instrumentation for PowerMock -->
+ <execution>
+ <id>portal-offline-instrument</id>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>portal-restore-instrumented-classes</id>
+ <phase>test</phase>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>portal-post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${sonar.jacoco.reportPath}</dataFile>
+ <outputDirectory>${project.basedir}/target/site/jacoco</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+
<!-- add version number to manifest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -293,5 +355,12 @@
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacoco.version}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java b/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
index 729cfd1f..b0826f68 100644
--- a/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
+++ b/ecomp-sdk/epsdk-app-os/src/main/java/org/onap/portalapp/login/LoginStrategyImpl.java
@@ -103,7 +103,7 @@ public class LoginStrategyImpl extends LoginStrategy {
if (!SystemProperties.containsProperty(SystemProperties.Decryption_Key))
throw new IllegalStateException("Failed to find property " + SystemProperties.Decryption_Key);
final String decryptionKey = SystemProperties.getProperty(SystemProperties.Decryption_Key);
- userId = CipherUtil.decrypt(cookieValue, decryptionKey);
+ userId = CipherUtil.decryptPKC(cookieValue, decryptionKey);
logger.debug(EELFLoggerDelegate.debugLogger, "getUserIdFromCookie: decrypted as {}", userId);
}
return userId;
diff --git a/ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/fusion/jsp/ds2/left-menu.jsp b/ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/fusion/jsp/ds2/left-menu.jsp
index c0e1b6e3..5cafe15c 100644
--- a/ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/fusion/jsp/ds2/left-menu.jsp
+++ b/ecomp-sdk/epsdk-app-os/src/main/webapp/WEB-INF/fusion/jsp/ds2/left-menu.jsp
@@ -298,8 +298,11 @@
$scope.getUserNameFromSession = function(){
UserInfoService.getFunctionalMenuStaticDetailSession()
.then(function (res) {
- $scope.userProfile.firstName = res.firstName;
- $scope.redirectUrl = res.portalUrl;
+ $scope.userProfile.firstName = res.firstName;
+ $scope.userProfile.lastName = res.lastName;
+ $scope.userProfile.email = res.email;
+ $scope.userProfile.fullName = res.userName;
+ $scope.redirectUrl = res.portalUrl;
});
}
$scope.getTopMenuStaticInfo=function() {
@@ -389,7 +392,7 @@
console.log('getAppName failed', error);
});
- $scope.getTopMenuStaticInfo();
+ $scope.getUserNameFromSession();
$scope.getMenu=function() {
$http({
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp
index a1128ede..0b986555 100644
--- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/WEB-INF/fusion/jsp/ebz/ebz_header.jsp
@@ -341,7 +341,10 @@
UserInfoService.getFunctionalMenuStaticDetailSession()
.then(function (res) {
$scope.userProfile.firstName = res.firstName;
- $scope.redirectUrl = res.portalUrl;
+ $scope.userProfile.lastName = res.lastName;
+ $scope.userProfile.email = res.email;
+ $scope.userProfile.fullName = res.userName;
+ $scope.redirectUrl = res.portalUrl;
});
}
$scope.getTopMenuStaticInfo=function() {
@@ -431,7 +434,7 @@
console.log('getAppName failed', error);
});
- $scope.getTopMenuStaticInfo();
+ $scope.getUserNameFromSession();
$scope.getMenu=function() {
$http({
diff --git a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/directives/header.js b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/directives/header.js
index ef0a8fd2..32024aaf 100644
--- a/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/directives/header.js
+++ b/ecomp-sdk/epsdk-app-overlay/src/main/webapp/app/fusion/scripts/directives/header.js
@@ -74,19 +74,17 @@ app.directive('qHeader', function () {
});
}
$scope.getTopMenuStaticInfo=function() {
- var promise = UserInfoService.getFunctionalMenuStaticDetailShareContext();
+ var promise = UserInfoService.getFunctionalMenuStaticDetailSession();
promise.then(
- function(res) {
- if(res==null || res==''){
- $log.error('failed to get static User information');
- $scope.getUserNameFromSession();
- }else{
- // $log.info('Received static User information');
- var resData = res;
- // console.log(resData);
- $scope.inputUserInfo(resData);
- $scope.userName = $scope.firstName+ ' '+ $scope.lastName;
- }
+ function(res) {
+ $scope.contactUsUrl=res.contactUsLink;
+ $scope.userName = res.userName;
+ $scope.userId = res.userid;
+ $scope.userEmail = res.email;
+ $scope.userFirstName = res.firstName;
+ $scope.redirectUrl = res.portalUrl;
+ $scope.getAccessUrl = res.getAccessUrl;
+ $scope.isAppCentralized = res.isAppCentralized;
},
function(err) {
$log.error('getFunctionalMenuStaticDetailShareContext failed', err);
@@ -114,7 +112,7 @@ app.directive('qHeader', function () {
}
$scope.getMenu=function() {
- $scope.getTopMenuStaticInfo();
+ $scope.getUserNameFromSession();
$http({
method: "GET",
url: 'get_functional_menu',
diff --git a/ecomp-sdk/epsdk-core/pom.xml b/ecomp-sdk/epsdk-core/pom.xml
index 49b8f901..1032c707 100644
--- a/ecomp-sdk/epsdk-core/pom.xml
+++ b/ecomp-sdk/epsdk-core/pom.xml
@@ -348,6 +348,13 @@
</exclusion>
</exclusions>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacoco.version}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java
index 60888b6d..0620945f 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/AppConfig.java
@@ -211,7 +211,7 @@ public class AppConfig extends WebMvcConfigurerAdapter implements Configurable,
if (SystemProperties.containsProperty(SystemProperties.DB_ENCRYPT_FLAG)) {
String encryptFlag = SystemProperties.getProperty(SystemProperties.DB_ENCRYPT_FLAG);
if (encryptFlag != null && "true".equalsIgnoreCase(encryptFlag)) {
- password = CipherUtil.decrypt(password);
+ password = CipherUtil.decryptPKC(password);
}
}
dataSource.setPassword(password);
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/interceptor/ResourceInterceptor.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/interceptor/ResourceInterceptor.java
index 4b4d721c..de65775b 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/interceptor/ResourceInterceptor.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/interceptor/ResourceInterceptor.java
@@ -144,7 +144,7 @@ public class ResourceInterceptor extends HandlerInterceptorAdapter {
String ecompRestURL = PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL);
String decreptedPwd = null;
try {
- decreptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decreptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "handleSessionUpdates failed to decrypt password", e);
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
index 2c4da43d..5f9cbdc9 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java
@@ -98,7 +98,7 @@ public class PortalRestClientBase {
if (uebKey == null || app == null || app.getUsername() == null || app.getAppPassword() == null)
throw new IllegalArgumentException(
"getRestWithCredentials: Missing one or more required properties and/or database entries");
- String decryptedPassword = CipherUtil.decrypt(app.getAppPassword());
+ String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword());
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader("uebkey", uebKey);
@@ -150,7 +150,7 @@ public class PortalRestClientBase {
if (uebKey == null || app == null || app.getUsername() == null || app.getAppPassword() == null)
throw new IllegalArgumentException(
"postRestWithCredentials: missing one or more required properties and/or database entries");
- String decryptedPassword = CipherUtil.decrypt(app.getAppPassword());
+ String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword());
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(uri);
httpPost.setHeader("uebkey", uebKey);
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RestApiRequestBuilder.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RestApiRequestBuilder.java
index c6c40b70..1b3e82cd 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RestApiRequestBuilder.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/RestApiRequestBuilder.java
@@ -77,7 +77,7 @@ public class RestApiRequestBuilder {
appName = app.getName();
appUserName = app.getUsername();
try {
- decryptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (CipherUtilException e) {
logger.error(EELFLoggerDelegate.errorLogger, "getViaREST failed", e);
@@ -115,7 +115,7 @@ public class RestApiRequestBuilder {
appName = app.getName();
appUserName = app.getUsername();
try {
- decryptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (CipherUtilException e) {
logger.error(EELFLoggerDelegate.errorLogger, "postViaREST failed", e);
@@ -152,7 +152,7 @@ public class RestApiRequestBuilder {
appName = app.getName();
appUserName = app.getUsername();
try {
- decryptedPwd = CipherUtil.decrypt(app.getAppPassword(),
+ decryptedPwd = CipherUtil.decryptPKC(app.getAppPassword(),
SystemProperties.getProperty(SystemProperties.Decryption_Key));
} catch (CipherUtilException e) {
logger.error(EELFLoggerDelegate.errorLogger, "deleteViaRest failed", e);
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UrlAccessImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UrlAccessImpl.java
index ddadc101..06073be4 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UrlAccessImpl.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/UrlAccessImpl.java
@@ -127,7 +127,7 @@ public class UrlAccessImpl implements UrlAccessService {
for (int i = 0; i < roleFunctionArray.length; i++) {
if (match) {
if (!roleFunctionArray[i].equals("*")) {
- Pattern p = Pattern.compile(path[i], Pattern.CASE_INSENSITIVE);
+ Pattern p = Pattern.compile(Pattern.quote(path[i]), Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(roleFunctionArray[i]);
match = m.matches();
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/WebServiceCallServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/WebServiceCallServiceImpl.java
index 71479820..f0a17913 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/WebServiceCallServiceImpl.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/WebServiceCallServiceImpl.java
@@ -69,7 +69,7 @@ public class WebServiceCallServiceImpl implements WebServiceCallService {
if (app != null) {
String encriptedPwdDB = app.getAppPassword();
String appUserName = app.getUsername();
- String decreptedPwd = CipherUtil.decrypt(encriptedPwdDB,
+ String decreptedPwd = CipherUtil.decryptPKC(encriptedPwdDB,
secretKey == null ? SystemProperties.getProperty(SystemProperties.Decryption_Key) : secretKey);
if (decreptedPwd.equals(requestPassword) && appUserName.equals(requestAppName)) {
return true;
diff --git a/ecomp-sdk/epsdk-fw/pom.xml b/ecomp-sdk/epsdk-fw/pom.xml
index 73283ee8..a61209e0 100644
--- a/ecomp-sdk/epsdk-fw/pom.xml
+++ b/ecomp-sdk/epsdk-fw/pom.xml
@@ -154,7 +154,13 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <classifier>runtime</classifier>
+ <scope>test</scope>
+ <version>${jacoco.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/epsdk-workflow/pom.xml b/ecomp-sdk/epsdk-workflow/pom.xml
index 077aa328..99420d30 100644
--- a/ecomp-sdk/epsdk-workflow/pom.xml
+++ b/ecomp-sdk/epsdk-workflow/pom.xml
@@ -111,6 +111,13 @@
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
+ <!-- Jacoco for offline instrumentation -->
+ <dependency>
+ <groupId>org.jacoco</groupId>
+ <artifactId>org.jacoco.agent</artifactId>
+ <version>${jacoco.version}</version>
+ <classifier>runtime</classifier>
+ </dependency>
</dependencies>
</project>
diff --git a/ecomp-sdk/pom.xml b/ecomp-sdk/pom.xml
index 788f63e0..e58f129c 100644
--- a/ecomp-sdk/pom.xml
+++ b/ecomp-sdk/pom.xml
@@ -33,11 +33,24 @@
<encoding>UTF-8</encoding>
<springframework.version>4.2.0.RELEASE</springframework.version>
<hibernate.version>4.3.11.Final</hibernate.version>
- <skiptests>true</skiptests>
+ <skiptests>false</skiptests>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<snapshotNexusPath>content/repositories/snapshots/</snapshotNexusPath>
<stagingNexusPath>content/repositories/staging/</stagingNexusPath>
<releaseNexusPath>content/repositories/releases/</releaseNexusPath>
+ <jacoco.version>0.7.7.201606060606</jacoco.version>
+ <sonar.exclusions>**/scripts/**/*,**.js</sonar.exclusions>
+ <sonar.test.exclusions>**/test/**/*,**/tests/**/*</sonar.test.exclusions>
+ <sonar.language>java</sonar.language>
+ <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
+ <sonar.skipDesign>true</sonar.skipDesign>
+ <sonar.surefire.reportsPath>${project.build.directory}/surefire-reports</sonar.surefire.reportsPath>
+ <sonar.jacoco.reportPath>${project.basedir}/jacoco.exec</sonar.jacoco.reportPath>
+ <sonar.jacoco.itReportPath>${project.basedir}/target/it-jacoco.exec</sonar.jacoco.itReportPath>
+ <sonar.jacoco.reportMissing.force.zero>true</sonar.jacoco.reportMissing.force.zero>
+ <sonar.projectVersion>${project.version}</sonar.projectVersion>
+ <sonar.skipDesign>true</sonar.skipDesign>
+ <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
</properties>
<!-- Specify the repositories here to avoid coordination of ~/.m2/settings.xml
@@ -147,6 +160,66 @@
</dependency>
</dependencies>
</plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <!-- version managed by oparent ${jacocoVersion}</version> -->
+ <executions>
+ <!-- disable jacoco executions from oparent -->
+ <execution>
+ <id>pre-unit-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>post-unit-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>pre-integration-test</id>
+ <phase>none</phase>
+ </execution>
+ <execution>
+ <id>post-integration-test</id>
+ <phase>none</phase>
+ </execution>
+ <!-- Order matters -->
+ <execution>
+ <id>portal-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${sonar.jacoco.reportPath}</destFile>
+ </configuration>
+ </execution>
+ <!-- offline instrumentation for PowerMock -->
+ <execution>
+ <id>portal-offline-instrument</id>
+ <goals>
+ <goal>instrument</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>portal-restore-instrumented-classes</id>
+ <phase>test</phase>
+ <goals>
+ <goal>restore-instrumented-classes</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>portal-post-unit-test</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${sonar.jacoco.reportPath}</dataFile>
+ <outputDirectory>${project.basedir}/target/site/jacoco</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</pluginManagement>