diff options
author | 2018-06-08 16:40:16 -0400 | |
---|---|---|
committer | 2018-06-14 10:03:31 -0400 | |
commit | f51a3e2b128f0b96bc9ed67dfc3081f4b41d1303 (patch) | |
tree | db4f24c3bc4e70bcda2916d7fa7027e9ab984cf3 /ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk | |
parent | 1ffd6b689a0176875b401fb089bd33db96f07b62 (diff) |
Junit Test Cases & Raptors
Issue-ID: PORTAL-273. PORTAL-301
Covered JUNITS for sdk modules and RAPTOR reports fixes
Change-Id: Ifaf3bf06f0ec123051a791cc8e7f10662f97a525
Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk')
13 files changed, 1398 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java new file mode 100644 index 00000000..43dcc827 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsDetailTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessPermsDetailTest { + + public ExternalAccessPermsDetail mockExternalAccessPermsDetailTest() { + List<String> roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPermsDetail mockExtPermsDetailTest = new ExternalAccessPermsDetail(); + mockExtPermsDetailTest.setAction("*"); + mockExtPermsDetailTest.setDescription("test_name"); + mockExtPermsDetailTest.setType("test_type"); + mockExtPermsDetailTest.setInstance("test_instance"); + mockExtPermsDetailTest.setRoles(roles); + return mockExtPermsDetailTest; + } + + @Test + public void externalAccessPermsDetailTest() { + List<String> roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPermsDetail extPermsDetailTest = new ExternalAccessPermsDetail(); + ExternalAccessPermsDetail extPermsDetailTest2 = new ExternalAccessPermsDetail("test_type", "test_instance", "*", + "test_name"); + ExternalAccessPermsDetail extPermsDetailTest3 = new ExternalAccessPermsDetail("test_type", "test_instance", "*", + roles, "test_name"); + extPermsDetailTest.setAction("*"); + extPermsDetailTest.setDescription("test_name"); + extPermsDetailTest.setType("test_type"); + extPermsDetailTest.setInstance("test_instance"); + extPermsDetailTest.setRoles(roles); + assertEquals(extPermsDetailTest.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest.getRoles(), mockExternalAccessPermsDetailTest().getRoles()); + assertEquals(extPermsDetailTest2.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest2.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest2.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest2.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest2.getRoles(), null); + assertEquals(extPermsDetailTest3.getAction(), mockExternalAccessPermsDetailTest().getAction()); + assertEquals(extPermsDetailTest3.getType(), mockExternalAccessPermsDetailTest().getType()); + assertEquals(extPermsDetailTest3.getInstance(), mockExternalAccessPermsDetailTest().getInstance()); + assertEquals(extPermsDetailTest3.getDescription(), mockExternalAccessPermsDetailTest().getDescription()); + assertEquals(extPermsDetailTest3.getRoles(), mockExternalAccessPermsDetailTest().getRoles()); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java new file mode 100644 index 00000000..0f3a65a5 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessPermsTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessPermsTest { + + public ExternalAccessPerms mockExternalAccessPermsTest() { + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + return mockExtPermsTest; + } + + @Test + public void externalAccessPermsTest() { + List<String> roles = new ArrayList<>(); + roles.add("test_role"); + roles.add("test_role2"); + ExternalAccessPerms extPermsDetailTest = new ExternalAccessPerms(); + ExternalAccessPerms extPermsDetailTest2 = new ExternalAccessPerms("test_type", "test_instance", "*"); + ExternalAccessPerms extPermsDetailTest3 = new ExternalAccessPerms("test_type", "test_instance", "*", + "test_name"); + extPermsDetailTest.setAction("*"); + extPermsDetailTest.setDescription("test_name"); + extPermsDetailTest.setType("test_type"); + extPermsDetailTest.setInstance("test_instance"); + assertEquals(extPermsDetailTest.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(extPermsDetailTest.getDescription(), mockExternalAccessPermsTest().getDescription()); + assertEquals(extPermsDetailTest2.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest2.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest2.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(null, extPermsDetailTest2.getDescription()); + assertEquals(extPermsDetailTest3.getAction(), mockExternalAccessPermsTest().getAction()); + assertEquals(extPermsDetailTest3.getType(), mockExternalAccessPermsTest().getType()); + assertEquals(extPermsDetailTest3.getInstance(), mockExternalAccessPermsTest().getInstance()); + assertEquals(extPermsDetailTest3.getDescription(), mockExternalAccessPermsTest().getDescription()); + assertEquals(true, new ExternalAccessPerms("test_type", "test_instance", "*", "test_name") + .equals(new ExternalAccessPerms("test_type", "test_instance", "*", "test_name"))); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java new file mode 100644 index 00000000..acb14c65 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRolePermsTest.java @@ -0,0 +1,68 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessRolePermsTest { + + public ExternalAccessRolePerms mockExternalAccessRolePermsTest() { + ExternalAccessPerms mockPerm = new ExternalAccessPerms(); + mockPerm.setAction("*"); + mockPerm.setDescription("test_name"); + mockPerm.setType("test_type"); + mockPerm.setInstance("test_instance"); + ExternalAccessRolePerms mockExtRolePermsTest = new ExternalAccessRolePerms(mockPerm, "test_role"); + return mockExtRolePermsTest; + } + + @Test + public void externalAccessRolePermsTest() { + ExternalAccessPerms perm = new ExternalAccessPerms(); + perm.setAction("*"); + perm.setDescription("test_name"); + perm.setType("test_type"); + perm.setInstance("test_instance"); + ExternalAccessRolePerms mockExtRolePermsTest = new ExternalAccessRolePerms(perm, "test_role"); + assertEquals(mockExtRolePermsTest.getRole(), mockExternalAccessRolePermsTest().getRole()); + assertEquals(mockExtRolePermsTest.getPerm(), mockExternalAccessRolePermsTest().getPerm()); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java new file mode 100644 index 00000000..aa498aa0 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessRoleTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessRoleTest { + + public ExternalAccessRole mockExternalAccessRoleTest() { + ExternalAccessRole mockRole = new ExternalAccessRole(); + mockRole.setName("test_role"); + mockRole.setDescription("test_role_description"); + return mockRole; + } + + @Test + public void externalAccessRolePermsTest() { + ExternalAccessRole role = new ExternalAccessRole("test_role", "test_role_description"); + assertEquals(role.getName(), mockExternalAccessRoleTest().getName()); + assertEquals(role.getDescription(), mockExternalAccessRoleTest().getDescription()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java new file mode 100644 index 00000000..5e750543 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserRoleDetailTest.java @@ -0,0 +1,99 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalAccessUserRoleDetailTest { + + public ExternalAccessUserRoleDetail mockExternalAccessUserRoleDetailTest() { + List<ExternalAccessPerms> mockPerms = new ArrayList<>(); + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + mockPerms.add(mockExtPermsTest); + ExternalRoleDescription mockRoleDesc = new ExternalRoleDescription(); + mockRoleDesc.setActive("true"); + mockRoleDesc.setAppId("1"); + mockRoleDesc.setAppRoleId("1"); + mockRoleDesc.setId("1"); + mockRoleDesc.setPriority("1"); + mockRoleDesc.setName("test"); + mockRoleDesc.setPermissions(mockPerms); + ExternalAccessUserRoleDetail mockExtUserRoleDetailTest = new ExternalAccessUserRoleDetail(); + mockExtUserRoleDetailTest.setName("test"); + mockExtUserRoleDetailTest.setDescription(mockRoleDesc); + return mockExtUserRoleDetailTest; + } + + @Test + public void externalAccessPermsTest() { + List<ExternalAccessPerms> perms = new ArrayList<>(); + ExternalAccessPerms extPermsTest = new ExternalAccessPerms(); + extPermsTest.setAction("*"); + extPermsTest.setDescription("test_name"); + extPermsTest.setType("test_type"); + extPermsTest.setInstance("test_instance"); + perms.add(extPermsTest); + ExternalRoleDescription roleDesc = new ExternalRoleDescription(); + roleDesc.setActive("true"); + roleDesc.setAppId("1"); + roleDesc.setAppRoleId("1"); + roleDesc.setId("1"); + roleDesc.setPriority("1"); + roleDesc.setName("test"); + roleDesc.setPermissions(perms); + ExternalAccessUserRoleDetail extUserRoleDetailTest = new ExternalAccessUserRoleDetail(); + extUserRoleDetailTest.setName("test"); + extUserRoleDetailTest.setDescription(roleDesc); + ExternalAccessUserRoleDetail extUserRoleDetailTest2 = new ExternalAccessUserRoleDetail("test", roleDesc); + assertEquals(extUserRoleDetailTest.getName(), mockExternalAccessUserRoleDetailTest().getName()); + assertEquals(extUserRoleDetailTest.getDescription(), mockExternalAccessUserRoleDetailTest().getDescription()); + assertEquals(extUserRoleDetailTest2.getName(), mockExternalAccessUserRoleDetailTest().getName()); + assertEquals(extUserRoleDetailTest2.getDescription(), mockExternalAccessUserRoleDetailTest().getDescription()); + assertEquals(true, new ExternalAccessUserRoleDetail("test",roleDesc) + .equals(new ExternalAccessUserRoleDetail("test",roleDesc))); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java new file mode 100644 index 00000000..18909b74 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAccessUserTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAccessUserTest { + + public ExternalAccessUser mockExternalAccessUserTest() { + return new ExternalAccessUser("test", "test123"); + } + + @Test + public void externalAccessUserTest() { + ExternalAccessUser extUserTest = new ExternalAccessUser("test", "test123"); + assertEquals(extUserTest.getUser(), mockExternalAccessUserTest().getUser()); + assertEquals(extUserTest.getRole(), mockExternalAccessUserTest().getRole()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java new file mode 100644 index 00000000..c295a537 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalAuthUserRoleTest.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class ExternalAuthUserRoleTest { + + public ExternalAuthUserRole mockExternalAccessUserTest() { + ExternalAuthUserRole mockExtAuthUserRole = new ExternalAuthUserRole(); + mockExtAuthUserRole.setUser("test123"); + mockExtAuthUserRole.setRole("test"); + mockExtAuthUserRole.setExpiryDate("1/1/1111"); + return mockExtAuthUserRole; + } + + @Test + public void externalAuthUserRoleTest() { + ExternalAuthUserRole extAuthUserRole = new ExternalAuthUserRole(); + extAuthUserRole.setUser("test123"); + extAuthUserRole.setRole("test"); + extAuthUserRole.setExpiryDate("1/1/1111"); + assertEquals(extAuthUserRole.getRole(), mockExternalAccessUserTest().getRole()); + assertEquals(extAuthUserRole.getUser(), mockExternalAccessUserTest().getUser()); + assertEquals(extAuthUserRole.getExpiryDate(), mockExternalAccessUserTest().getExpiryDate()); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java new file mode 100644 index 00000000..251f8303 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/domain/ExternalRoleDescriptionTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.domain; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class ExternalRoleDescriptionTest { + + public ExternalRoleDescription mockExternalRoleDescriptionTest() { + List<ExternalAccessPerms> mockPerms = new ArrayList<>(); + ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms(); + mockExtPermsTest.setAction("*"); + mockExtPermsTest.setDescription("test_name"); + mockExtPermsTest.setType("test_type"); + mockExtPermsTest.setInstance("test_instance"); + mockPerms.add(mockExtPermsTest); + ExternalRoleDescription mockExtRoleDesc = new ExternalRoleDescription(); + mockExtRoleDesc.setActive("true"); + mockExtRoleDesc.setAppRoleId("1"); + mockExtRoleDesc.setAppId("1"); + mockExtRoleDesc.setId("1"); + mockExtRoleDesc.setName("test"); + mockExtRoleDesc.setPermissions(mockPerms); + mockExtRoleDesc.setPriority("1"); + return mockExtRoleDesc; + } + + @Test + public void externalRoleDescriptionTest() { + List<ExternalAccessPerms> perms = new ArrayList<>(); + ExternalAccessPerms extPermsTest = new ExternalAccessPerms(); + extPermsTest.setAction("*"); + extPermsTest.setDescription("test_name"); + extPermsTest.setType("test_type"); + extPermsTest.setInstance("test_instance"); + perms.add(extPermsTest); + ExternalRoleDescription extRoleDesc = new ExternalRoleDescription(); + extRoleDesc.setActive("true"); + extRoleDesc.setAppRoleId("1"); + extRoleDesc.setAppId("1"); + extRoleDesc.setId("1"); + extRoleDesc.setName("test"); + extRoleDesc.setPermissions(perms); + extRoleDesc.setPriority("1"); + assertEquals(extRoleDesc.getActive(), mockExternalRoleDescriptionTest().getActive()); + assertEquals(extRoleDesc.getAppId(), mockExternalRoleDescriptionTest().getAppId()); + assertEquals(extRoleDesc.getAppRoleId(), mockExternalRoleDescriptionTest().getAppRoleId()); + assertEquals(extRoleDesc.getId(), mockExternalRoleDescriptionTest().getId()); + assertEquals(extRoleDesc.getName(), mockExternalRoleDescriptionTest().getName()); + assertEquals(extRoleDesc.getPriority(), mockExternalRoleDescriptionTest().getPriority()); + assertEquals(extRoleDesc.getPermissions(), mockExternalRoleDescriptionTest().getPermissions()); + assertEquals(true, extRoleDesc.equals(mockExternalRoleDescriptionTest())); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java new file mode 100644 index 00000000..ae6eb975 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/LoginExternalAuthServiceImplTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.service; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +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.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.core.command.LoginBean; +import org.onap.portalsdk.core.domain.App; +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.domain.UserApp; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.onap.portalsdk.external.framework.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +@RunWith(PowerMockRunner.class) +@PrepareForTest({AppUtils.class, UserUtils.class, SystemProperties.class}) +public class LoginExternalAuthServiceImplTest { + + @InjectMocks + private LoginExternalAuthServiceImpl loginExternalAuthServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private UserApiService userApiService; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Before + public void setup() { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + } + + private User userObj() { + User user = new User(); + user.setEmail("test@mail.com"); + user.setFirstName("Test_firstname"); + user.setHrid("test_hrid"); + user.setJobTitle("test_jobtitle"); + user.setLastName("test_lastname"); + user.setLoginId("test123"); + user.setOrgManagerUserId("test456"); + user.setMiddleInitial("test_middlename"); + user.setOrgCode("testcode"); + user.setOrgId(1l); + user.setOrgUserId("test123"); + user.setActive(true); + user.setLastLoginDate(new Date()); + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setId(12L); + roleFunction.setName("Role Function"); + + Set roleFunctions = new TreeSet(); + roleFunctions.add(roleFunction); + + Role role = new Role(); + role.setName("Role"); + role.setActive(true); + role.setRoleFunctions(roleFunctions); + Set userApps = new TreeSet(); + UserApp userApp = new UserApp(); + userApp.setUserId(1L); + userApp.setApp(getApp()); + userApp.setRole(role); + userApps.add(userApp); + user.setUserApps(userApps); + return user; + } + + public App getApp() { + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + return app; + } + + @Test + public void findUserTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setUserid("test123"); + Map additionalParams = new HashMap<>(); + User user = userObj(); + user.setId(1l); + List usersId = new ArrayList<>(); + usersId.add(user.getId()); + List users = new ArrayList<>(); + users.add(user); + Mockito.when(userApiService.getUser(bean.getUserid(), mockedRequest)).thenReturn(user); + Map<String, String> params = new HashMap<>(); + params.put("orgUserId", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null)).thenReturn(usersId); + Map<String, String> params2 = new HashMap<>(); + params.put("org_user_id", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params2, new HashMap())).thenReturn(users); + LoginBean expected = loginExternalAuthServiceImpl.findUser(bean, "menu", additionalParams, mockedRequest); + assertNotNull(expected); + } + + @Test + public void findUserForNewUserTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setUserid("test123"); + Map additionalParams = new HashMap<>(); + User user = userObj(); + List usersId = new ArrayList<>(); + usersId.add(user.getId()); + List users = new ArrayList<>(); + users.add(user); + Mockito.when(userApiService.getUser(bean.getUserid(), mockedRequest)).thenReturn(user); + Map<String, String> params = new HashMap<>(); + params.put("orgUserId", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null)).thenReturn(usersId); + Map<String, String> params2 = new HashMap<>(); + params.put("org_user_id", "test123"); + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params2, new HashMap())).thenReturn(null); + LoginBean expected = loginExternalAuthServiceImpl.findUser(bean, "menu", additionalParams, mockedRequest); + assertNotNull(expected); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java new file mode 100644 index 00000000..d93b03c1 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/service/UserApiServiceImplTest.java @@ -0,0 +1,313 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.service; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.json.JSONObject; +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.portalsdk.core.command.PostSearchBean; +import org.onap.portalsdk.core.command.support.SearchResult; +import org.onap.portalsdk.core.domain.App; +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.domain.UserApp; +import org.onap.portalsdk.core.service.AppService; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.LdapService; +import org.onap.portalsdk.core.service.PostSearchService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.external.authorization.util.EcompExternalAuthProperties; +import org.onap.portalsdk.external.authorization.util.EcompExternalAuthUtils; +import org.onap.portalsdk.external.framework.MockitoTestSuite; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@SuppressWarnings({ "rawtypes", "unchecked" }) +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompExternalAuthProperties.class, EcompExternalAuthUtils.class }) +public class UserApiServiceImplTest { + + private static final String APP_ID = "appId"; + + private static final String PRIORITY = "priority"; + + private static final String ACTIVE = "active"; + + private static final String ROLE_NAME = "name"; + + private static final String APP_ROLE_ID = "appRoleId"; + + private static final String ID = "id"; + + @InjectMocks + private UserApiServiceImpl UserApiServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private LoginExternalAuthService loginAAFService; + + @Mock + private LdapService ldapService; + + @Mock + private PostSearchService postSearchService; + + @Mock + private AppService appService; + + @Mock + RestTemplate template = new RestTemplate(); + + @Before + public void setup() throws Exception { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + PowerMockito.mockStatic(EcompExternalAuthUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_NAMESPACE)) + .thenReturn("com.test.app2"); + Mockito.when(EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(new HttpHeaders()); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_DOMAIN)) + .thenReturn("@test.com"); + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + private User userObj() { + User user = new User(); + user.setEmail("test@mail.com"); + user.setFirstName("Test_firstname"); + user.setHrid("test_hrid"); + user.setJobTitle("test_jobtitle"); + user.setLastName("test_lastname"); + user.setLoginId("test123"); + user.setOrgManagerUserId("test456"); + user.setMiddleInitial("test_middlename"); + user.setOrgCode("testcode"); + user.setOrgId(1l); + user.setOrgUserId("test123"); + user.setActive(true); + user.setLastLoginDate(new Date()); + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setId(12L); + roleFunction.setName("Role Function"); + + Set roleFunctions = new TreeSet(); + roleFunctions.add(roleFunction); + + Role role = new Role(); + role.setName("Role"); + role.setActive(true); + role.setRoleFunctions(roleFunctions); + Set userApps = new TreeSet(); + UserApp userApp = new UserApp(); + userApp.setUserId(1L); + userApp.setApp(getApp()); + userApp.setRole(role); + userApps.add(userApp); + user.setUserApps(userApps); + return user; + } + + public App getApp() { + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + return app; + } + + @Test + public void getUserTest() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + Map<String, String> roleDesc = new LinkedHashMap<>(); + roleDesc.put(ID, "1"); + roleDesc.put(ROLE_NAME, "test_role"); + roleDesc.put(ACTIVE, String.valueOf(true)); + roleDesc.put(PRIORITY, String.valueOf(1)); + roleDesc.put(APP_ID, String.valueOf(1)); + roleDesc.put(APP_ROLE_ID, String.valueOf(1l)); + String addDesc = mapper.writeValueAsString(roleDesc); + JSONObject mockJsonObjectRole = new JSONObject(); + JSONObject mockJsonObjectRole2 = new JSONObject(); + JSONObject mockJsonObjectRole3 = new JSONObject(); + JSONObject mockJsonObjectRole4 = new JSONObject(); + JSONObject mockJsonObjectRole5 = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + List<JSONObject> permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectRole.put("name", "com.test.app2.test_role"); + mockJsonObjectRole2.put("name", "com.test.app2.test_role2"); + mockJsonObjectRole2.put("perms", permsList); + mockJsonObjectRole2.put("description", addDesc); + mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator"); + mockJsonObjectRole4.put("name", "com.test.app2.admin"); + mockJsonObjectRole5.put("name", "com.test.app2.owner"); + List<JSONObject> userRolesList = new ArrayList<>(); + JSONObject mockJsonObjectFinalUserRole = new JSONObject(); + userRolesList.add(mockJsonObjectRole); + userRolesList.add(mockJsonObjectRole2); + userRolesList.add(mockJsonObjectRole3); + userRolesList.add(mockJsonObjectRole4); + userRolesList.add(mockJsonObjectRole5); + mockJsonObjectFinalUserRole.put("role", userRolesList); + Mockito.when(EcompExternalAuthUtils.isJSONValid(addDesc)).thenReturn(true); + ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); + Mockito.when(EcompExternalAuthUtils.checkNameSpaceMatching(Matchers.anyString(), Matchers.anyString())) + .thenReturn(true); + Mockito.when(loginAAFService.findUserWithoutPwd("test123")).thenReturn(userObj()); + Mockito.when(appService.getApp(1l)).thenReturn(getApp()); + User actual = UserApiServiceImpl.getUser("test123", mockedRequest); + assertNotNull(actual); + } + + @Test + public void getNewUserNullExceptionTest() throws Exception { + JSONObject mockJsonObjectRole = new JSONObject(); + JSONObject mockJsonObjectRole2 = new JSONObject(); + JSONObject mockJsonObjectRole3 = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + List<JSONObject> permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectRole.put("name", "com.test.app2.test_role"); + mockJsonObjectRole2.put("name", "com.test.app2.test_role2"); + mockJsonObjectRole2.put("perms", permsList); + mockJsonObjectRole3.put("name", "com.test.app2.Account_Administrator"); + List<JSONObject> userRolesList = new ArrayList<>(); + JSONObject mockJsonObjectFinalUserRole = new JSONObject(); + userRolesList.add(mockJsonObjectRole); + userRolesList.add(mockJsonObjectRole2); + userRolesList.add(mockJsonObjectRole3); + mockJsonObjectFinalUserRole.put("role", userRolesList); + ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectFinalUserRole.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); + Mockito.when(EcompExternalAuthUtils.checkNameSpaceMatching(Matchers.anyString(), Matchers.anyString())) + .thenReturn(true); + Mockito.when(loginAAFService.findUserWithoutPwd("test123")).thenReturn(null); + Mockito.when(appService.getApp(1l)).thenReturn(getApp()); + PostSearchBean postSearchBean = new PostSearchBean(); + postSearchBean.setOrgUserId("test123"); + SearchResult result = new SearchResult(); + result.add(userObj()); + Mockito.when(ldapService.searchPost(postSearchBean.getUser(), postSearchBean.getSortBy1(), + postSearchBean.getSortBy2(), postSearchBean.getSortBy3(), postSearchBean.getPageNo(), + postSearchBean.getNewDataSize(), 1)).thenReturn(result); + User user = UserApiServiceImpl.getUser("test123", mockedRequest); + assertNull(user); + } + + @Test + public void getRoleFunctionsTest() throws Exception { + JSONObject mockJsonObjectPerms = new JSONObject(); + JSONObject mockJsonObjectPerm1 = new JSONObject(); + JSONObject mockJsonObjectPerm2 = new JSONObject(); + JSONObject mockJsonObjectPerm3 = new JSONObject(); + mockJsonObjectPerm1.put("type", "com.test.app2.test_type"); + mockJsonObjectPerm1.put("instance", "test_instance"); + mockJsonObjectPerm1.put("action", "*"); + mockJsonObjectPerm2.put("type", "com.test.app2.test_type2"); + mockJsonObjectPerm2.put("instance", "test_instance2"); + mockJsonObjectPerm2.put("action", "*"); + mockJsonObjectPerm2.put("description", "test_name"); + mockJsonObjectPerm3.put("type", "com.test.app3.test_type3"); + mockJsonObjectPerm3.put("instance", "test_instance3"); + mockJsonObjectPerm3.put("action", "*"); + List<JSONObject> permsList = new ArrayList<>(); + permsList.add(mockJsonObjectPerm1); + permsList.add(mockJsonObjectPerm2); + mockJsonObjectPerms.put("perm", permsList); + ResponseEntity<String> response = new ResponseEntity<>(mockJsonObjectPerms.toString(), HttpStatus.OK); + Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), + Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(response); + List<RoleFunction> actual = UserApiServiceImpl.getRoleFunctions("test123"); + assertNotNull(actual); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java new file mode 100644 index 00000000..24c19622 --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthPropertiesTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.util; + +import static org.junit.Assert.assertNull; + +import java.util.Properties; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ Properties.class }) +public class EcompExternalAuthPropertiesTest { + + @Test + public void getPropertyTest() { + String actual = EcompExternalAuthProperties.getProperty("test"); + assertNull(actual); + } + +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java new file mode 100644 index 00000000..b35a1cda --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/authorization/util/EcompExternalAuthUtilsTest.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.authorization.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpHeaders; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EcompExternalAuthProperties.class, CipherUtil.class }) +public class EcompExternalAuthUtilsTest { + + public static final String EXT_EMPTY_JSON_STRING = "{}"; + public static final String EXT_ROLE_FIELD = "role"; + public static final String EXT_PERM_FIELD = "perm"; + public static final String EXT_PERM_FIELD_TYPE = "type"; + public static final String EXT_PERM_ACCESS = ".access"; + public static final String EXT_ROLE_FIELD_NAME = "name"; + public static final String EXT_NULL_VALUE = "null"; + public static final String EXT_FIELD_DESCRIPTION = "description"; + public static final String EXT_FIELD_PERMS = "perms"; + public static final String EXT_ROLE_FIELD_OWNER = ".owner"; + public static final String EXT_ROLE_FIELD_ADMIN = ".admin"; + + @Before + public void setup() { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_USER_NAME)) + .thenReturn("test_username"); + Mockito.when(EcompExternalAuthProperties.getProperty(EcompExternalAuthProperties.EXTERNAL_AUTH_PASSWORD)) + .thenReturn("test_password"); + MockitoAnnotations.initMocks(this); + } + + @Test + public void base64encodeKeyForAAFBasicAuthTest() throws Exception { + Mockito.when( + CipherUtil.decryptPKC("test_password", SystemProperties.getProperty(SystemProperties.Decryption_Key))) + .thenReturn("test_decrypted_password"); + HttpHeaders actual = EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(); + assertNotNull(actual); + } + + @Test(expected = NullPointerException.class) + public void base64encodeKeyForAAFBasicAuthDecryptPassExceptionTest() throws Exception { + Mockito.when( + CipherUtil.decryptPKC("test_password", SystemProperties.getProperty(SystemProperties.Decryption_Key))) + .thenThrow(new NullPointerException()); + EcompExternalAuthUtils.base64encodeKeyForAAFBasicAuth(); + } + + @Test + public void checkNameSpaceMatchingTest() throws Exception { + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app.role.name", "com.test.app.role"); + } + + @Test + public void checkNameSpaceNotMatchingTest() throws Exception { + PowerMockito.mockStatic(EcompExternalAuthProperties.class); + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app2.role.name", "com.test.app.role"); + } + + @Test + public void checkNameSpaceMatchingLengthTest() throws Exception { + EcompExternalAuthUtils.checkNameSpaceMatching("com.test.app2.role", "com.test.app2.role.test"); + } + + @Test + public void isJsonValidTest() { + boolean actual = EcompExternalAuthUtils.isJSONValid("{\"test\":\"test\"}"); + assertTrue(actual); + } + + @Test + public void isJsonValidFailTest() { + boolean actual = EcompExternalAuthUtils.isJSONValid("{\"test\":\"test\""); + assertFalse(actual); + } +} diff --git a/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java new file mode 100644 index 00000000..adc1b27a --- /dev/null +++ b/ecomp-sdk/epsdk-aaf/src/test/java/org/onap/portalsdk/external/framework/MockitoTestSuite.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright (C) 2018 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============================================ + * + * + */ +package org.onap.portalsdk.external.framework; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Test; +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; + } + + } + + @Test + public void test() + { + assert(true); + } +} |