summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-app-common
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-sdk/epsdk-app-common')
-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
16 files changed, 1268 insertions, 192 deletions
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;
+ }
+
+ }
+
}