diff options
author | 2018-02-23 13:01:58 +0000 | |
---|---|---|
committer | 2018-02-23 13:01:58 +0000 | |
commit | a7a2fedb67c3607de80483749366681d339a4188 (patch) | |
tree | 0553278f3f68f7abae5659d821eb5facd918a169 /ecomp-portal-BE-common/src/test/java/org/onap | |
parent | 14401350d3a2551da2d918ffe9ec3b1df79d8cfc (diff) | |
parent | f59a56b7c12badbb41bb2155b6de47e9c9c48bcd (diff) |
Merge "Added Junits"
Diffstat (limited to 'ecomp-portal-BE-common/src/test/java/org/onap')
6 files changed, 573 insertions, 5 deletions
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java index e63ea438..a4970f82 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/RoleManageControllerTest.java @@ -332,7 +332,6 @@ public class RoleManageControllerTest { addNewFunc.setCode("Test"); addNewFunc.setName("Test"); Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp()); - String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}"; roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1); } diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java index ef9bda0c..d9beb4d1 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/AdminRolesServiceImplTest.java @@ -39,6 +39,7 @@ package org.onap.portalapp.portal.service; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.util.ArrayList; @@ -127,6 +128,8 @@ public class AdminRolesServiceImplTest { private Long ACCOUNT_ADMIN_ROLE_ID = 999L; + private Long ECOMP_APP_ID = 1L; + public EPApp mockApp() { EPApp app = new EPApp(); app.setName("Test"); @@ -178,7 +181,12 @@ public class AdminRolesServiceImplTest { userAppList.add(epUserApp); Mockito.when(dataAccessService.getList(EPUserApp.class, " where userId = " + user.getId() + " and role.id = " + 999, null, null)).thenReturn(userAppList); - adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId()); + List<EPApp> appsList = new ArrayList<>(); + appsList.add(app); + Mockito.when(dataAccessService.getList(EPApp.class, + " where ( enabled = 'Y' or id = " + ECOMP_APP_ID + ")", null, null)).thenReturn(appsList); + AppsListWithAdminRole actual = adminRolesServiceImpl.getAppsWithAdminRoleStateForUser(user.getOrgUserId()); + assertNotNull(actual); } @SuppressWarnings({ "deprecation", "unchecked" }) diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java new file mode 100644 index 00000000..3cc6762f --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 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.portal.service; + +import static org.junit.Assert.assertNotEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.json.JSONObject; +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.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.CentralizedApp; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalsdk.core.domain.MenuData; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; + +public class EPLeftMenuServiceImplTest { + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + + @Mock + ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + EPLeftMenuServiceImpl epLeftMenuServiceImpl = new EPLeftMenuServiceImpl(); + + + MockEPUser mockUser = new MockEPUser(); + + @Test + public void getLeftMenuItemsTest() { + EPUser user = mockUser.mockEPUser(); + Set<MenuData> fullMenuSet = new TreeSet<>(); + MenuData menuData = new MenuData(); + menuData.setAction("test"); + menuData.setFunctionCd("test_1"); + menuData.setActive(true); + menuData.setExternalUrl("test"); + menuData.setId(1l); + menuData.setMenuSetCode("test"); + menuData.setSortOrder((short) 1); + menuData.setSeparator(true); + fullMenuSet.add(menuData); + Set<String> roleFunctionSet = new TreeSet<>(); + roleFunctionSet.add("test"); + roleFunctionSet.add("test2"); + Map<String, String> params = new HashMap<>(); + params.put("userId", user.getOrgUserId()); + List<CentralizedApp> applicationsList = new ArrayList<>(); + List<CentralizedApp> applicationsList2 = new ArrayList<>(); + CentralizedApp centralizedApp = new CentralizedApp(); + centralizedApp.setAppId(1); + centralizedApp.setAppName("test"); + applicationsList.add(centralizedApp); + applicationsList2.add(centralizedApp); + Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenReturn(applicationsList); + Mockito.when(externalAccessRolesServiceImpl.getCentralizedAppsOfUser(Matchers.anyString())).thenReturn(applicationsList2); + String actual = epLeftMenuServiceImpl.getLeftMenuItems(user, fullMenuSet, roleFunctionSet); + JSONObject notExpected = new JSONObject(); + assertNotEquals(notExpected.toString(), actual); + } + + +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLoginServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLoginServiceImplTest.java new file mode 100644 index 00000000..5eaa40fd --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLoginServiceImplTest.java @@ -0,0 +1,239 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 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.portal.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.mockito.MockitoAnnotations; +import org.onap.portalapp.command.EPLoginBean; +import org.onap.portalapp.portal.core.MockEPUser; +import org.onap.portalapp.portal.domain.EPApp; +import org.onap.portalapp.portal.domain.EPUser; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalapp.portal.utils.EcompPortalUtils; +import org.onap.portalapp.util.EPUserUtils; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.client.RestTemplate; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ EPUserUtils.class, CipherUtil.class, AppUtils.class, SystemProperties.class, + EPCommonSystemProperties.class }) +public class EPLoginServiceImplTest { + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + + @Mock + EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl(); + + @Mock + SearchServiceImpl searchServiceImpl = new SearchServiceImpl(); + + @Mock + RestTemplate template = new RestTemplate(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + EPLoginServiceImpl epLoginServiceImpl = new EPLoginServiceImpl(); + + public EPApp mockApp() { + EPApp app = new EPApp(); + app.setName("Test"); + app.setImageUrl("test"); + app.setNameSpace("com.test.app"); + app.setCentralAuth(true); + app.setDescription("test"); + app.setNotes("test"); + app.setUrl("test"); + app.setId((long) 1); + app.setAppRestEndpoint("test"); + app.setAlternateUrl("test"); + app.setName("test"); + app.setMlAppName("test"); + app.setMlAppAdminId("test"); + app.setUsername("test"); + app.setAppPassword("test"); + app.setOpen(false); + app.setEnabled(true); + app.setUebKey("test"); + app.setUebSecret("test"); + app.setUebTopicName("test"); + app.setAppType(1); + return app; + } + + MockEPUser mockUser = new MockEPUser(); + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void findUserTest() throws Exception { + EPUser user = mockUser.mockEPUser(); + EPLoginBean expected = new EPLoginBean(); + expected.setOrgUserId("guestT"); + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", expected.getOrgUserId()); + List list = new ArrayList<>(); + list.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", params, new HashMap())).thenReturn(list); + EPLoginBean actual = epLoginServiceImpl.findUser(expected, "test", new HashMap<>()); + assertNotNull(actual); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void findUserPasswordMatchTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(CipherUtil.class); + EPUser user = mockUser.mockEPUser(); + user.setLoginId("guestT"); + user.setLoginPwd("abc"); + EPLoginBean expected = new EPLoginBean(); + expected.setLoginId(user.getLoginId()); + expected.setLoginPwd("xyz"); + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", user.getOrgUserId()); + List list = new ArrayList<>(); + list.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", params, new HashMap())).thenReturn(list); + Map<String, String> params2 = new HashMap<>(); + params2.put("login_id", user.getOrgUserId()); + List list2 = new ArrayList<>(); + list2.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByLoginId", params2, new HashMap())).thenReturn(list2); + Mockito.when(CipherUtil.decryptPKC(user.getLoginPwd())).thenReturn("xyz"); + EPLoginBean actual = epLoginServiceImpl.findUser(expected, "test", new HashMap<>()); + assertNotNull(actual); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void findUserExcpetionTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EcompPortalUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(CipherUtil.class); + EPUser user = mockUser.mockEPUser(); + user.setLoginId("guestT"); + user.setLoginPwd("abc"); + EPLoginBean expected = new EPLoginBean(); + expected.setLoginId(user.getLoginId()); + expected.setLoginPwd("xyz"); + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", user.getOrgUserId()); + List list = new ArrayList<>(); + list.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", params, new HashMap())).thenReturn(list); + Map<String, String> params2 = new HashMap<>(); + params2.put("login_id", user.getOrgUserId()); + List list2 = new ArrayList<>(); + list2.add(user); + Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery("getEPUserByLoginId", params2, new HashMap()); + Mockito.when(CipherUtil.decryptPKC(user.getLoginPwd())).thenReturn("xyz"); + EPLoginBean actual = epLoginServiceImpl.findUser(expected, "test", new HashMap<>()); + assertEquals(expected,actual); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void findUserAppUtilsExcpetionTest() throws Exception { + PowerMockito.mockStatic(EPCommonSystemProperties.class); + PowerMockito.mockStatic(EPUserUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(CipherUtil.class); + EPUser user = mockUser.mockEPUser(); + user.setLoginId("guestT"); + user.setLoginPwd("abc"); + user.setActive(false); + EPLoginBean expected = new EPLoginBean(); + expected.setOrgUserId(user.getOrgUserId()); + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", user.getOrgUserId()); + List list = new ArrayList<>(); + list.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", params, new HashMap())).thenReturn(list); + Mockito.when(EPUserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))).thenReturn(false); + Mockito.when(AppUtils.isApplicationLocked()).thenReturn(true); + Mockito.when(EPUserUtils.hasRole(user, SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID))).thenReturn(false); + Mockito.when(AppUtils.isApplicationLocked()).thenReturn(true); + EPLoginBean actual = epLoginServiceImpl.findUser(expected, "test", new HashMap<>()); + assertEquals(expected,actual); + } + + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void findUserWithoutPwdTest() { + EPUser user = mockUser.mockEPUser(); + Map<String, String> params = new HashMap<>(); + params.put("login_id", user.getOrgUserId()); + List list = new ArrayList<>(); + list.add(user); + Mockito.when(dataAccessService.executeNamedQuery("getEPUserByLoginId", params, new HashMap())).thenReturn(list); + EPUser actual = epLoginServiceImpl.findUserWithoutPwd(user.getOrgUserId()); + assertEquals(user.getOrgUserId(), actual.getOrgUserId()); + } +} diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java index 726a235f..172b9421 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java @@ -520,8 +520,6 @@ public class ExternalAccessRolesServiceImplTest { appUebkeyParams.put("appKey", app.getUebKey()); Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null)) .thenReturn(appList); - CentralV2RoleFunction expected = new CentralV2RoleFunction(null, "type_code", "test_name", null, "test_type", - "*", null); Mockito.when(EcompPortalUtils.getFunctionCode("test_type|type_code|*")).thenReturn("type_code"); Mockito.when(EcompPortalUtils.getFunctionType("test_type|type_code|*")).thenReturn("test_type"); Mockito.when(EcompPortalUtils.getFunctionAction("test_type|type_code|*")).thenReturn("*"); @@ -535,7 +533,7 @@ public class ExternalAccessRolesServiceImplTest { .thenReturn(getRoleFuncList); CentralV2RoleFunction actual = externalAccessRolesServiceImpl.getRoleFunction("test_type|type_code|*", app.getUebKey()); - assertEquals(expected.getCode(), actual.getCode()); + assertEquals(getCenRole.getCode(), actual.getCode()); } @Test diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java new file mode 100644 index 00000000..fba7e6d2 --- /dev/null +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/MicroserviceServiceImplTest.java @@ -0,0 +1,207 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 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.portal.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import javax.crypto.BadPaddingException; + +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +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.portal.domain.MicroserviceData; +import org.onap.portalapp.portal.domain.MicroserviceParameter; +import org.onap.portalapp.portal.utils.EPCommonSystemProperties; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.DataAccessServiceImpl; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Criterion.class, Restrictions.class, CipherUtil.class, EPCommonSystemProperties.class, SystemProperties.class, Restrictions.class}) +public class MicroserviceServiceImplTest { + + @Mock + DataAccessService dataAccessService = new DataAccessServiceImpl(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @InjectMocks + MicroserviceServiceImpl microserviceServiceImpl = new MicroserviceServiceImpl(); + + @Test + public void saveMicroserviceTest() throws Exception { + MicroserviceData microserviceData = new MicroserviceData(); + List<MicroserviceParameter> microserviceParameters = new ArrayList<>(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + microserviceParameters.add(microserviceParameter); + microserviceData.setActive("true"); + microserviceData.setAppId(1l); + microserviceData.setId(1l); + microserviceData.setParameterList(microserviceParameters); + Long actual = microserviceServiceImpl.saveMicroservice(microserviceData); + assertEquals((Long)1l, actual); + } + + @Test + public void saveServiceParametersTest() throws Exception { + MicroserviceData microserviceData = new MicroserviceData(); + List<MicroserviceParameter> microserviceParameters = new ArrayList<>(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + microserviceParameters.add(microserviceParameter); + microserviceData.setActive("true"); + microserviceData.setAppId(1l); + microserviceData.setId(1l); + microserviceData.setParameterList(microserviceParameters); + microserviceServiceImpl.saveServiceParameters(1l, microserviceParameters); + } + + @SuppressWarnings("unchecked") + @Test + public void getMicroserviceDataByIdTest() throws Exception { + PowerMockito.mockStatic(Restrictions.class); + PowerMockito.mockStatic(Criterion.class); + MicroserviceData microserviceData = new MicroserviceData(); + List<MicroserviceParameter> microserviceParameters = new ArrayList<>(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + microserviceParameters.add(microserviceParameter); + microserviceData.setActive("true"); + microserviceData.setAppId(1l); + microserviceData.setId(1l); + List<Criterion> restrictionsList = new ArrayList<Criterion>(); + Criterion idCriterion = Restrictions.eq("id", 1l); + restrictionsList.add(idCriterion); + List<MicroserviceData> microserviceDatas = new ArrayList<>(); + microserviceDatas.add(microserviceData); + Mockito.when((List<MicroserviceData>) dataAccessService.getList(MicroserviceData.class, null, restrictionsList, null)).thenReturn(microserviceDatas); + List<Criterion> restrictionsList2 = new ArrayList<Criterion>(); + Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); + restrictionsList2.add(serviceIdCriterion); + Mockito.when((List<MicroserviceParameter>) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); + MicroserviceData actual = microserviceServiceImpl.getMicroserviceDataById(1l); + assertNotNull(actual); + } + + @SuppressWarnings({ "unchecked", "deprecation" }) + @Test + public void getMicroserviceDataTest() throws Exception { + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(Restrictions.class); + PowerMockito.mockStatic(Criterion.class); + List<MicroserviceParameter> microserviceParameters = new ArrayList<>(); + MicroserviceData microserviceData = new MicroserviceData(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + microserviceParameters.add(microserviceParameter); + microserviceData.setActive("true"); + microserviceData.setAppId(1l); + microserviceData.setPassword("xyz"); + microserviceData.setId(1l); + List<MicroserviceData> microserviceDatas = new ArrayList<>(); + microserviceDatas.add(microserviceData); + Mockito.when((List<MicroserviceData>) dataAccessService.getList(MicroserviceData.class, null)).thenReturn(microserviceDatas); + List<Criterion> restrictionsList2 = new ArrayList<Criterion>(); + Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); + restrictionsList2.add(serviceIdCriterion); + Mockito.when((List<MicroserviceParameter>) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); + Mockito.when(CipherUtil.decryptPKC("xyz", + SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn("abc"); + List<MicroserviceData> actual = microserviceServiceImpl.getMicroserviceData(); + assertNotNull(actual); + } + + @SuppressWarnings({ "unchecked", "deprecation", "static-access" }) + @Test + public void getMicroserviceDataBadPaddingExceptionTest() throws Exception { + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(Restrictions.class); + PowerMockito.mockStatic(Criterion.class); + List<MicroserviceParameter> microserviceParameters = new ArrayList<>(); + MicroserviceData microserviceData = new MicroserviceData(); + MicroserviceParameter microserviceParameter = new MicroserviceParameter(); + microserviceParameter.setId(1l); + microserviceParameter.setPara_key("test"); + microserviceParameter.setPara_value("test"); + microserviceParameters.add(microserviceParameter); + microserviceData.setActive("true"); + microserviceData.setAppId(1l); + microserviceData.setPassword("xyz"); + microserviceData.setId(1l); + List<MicroserviceData> microserviceDatas = new ArrayList<>(); + microserviceDatas.add(microserviceData); + Mockito.when((List<MicroserviceData>) dataAccessService.getList(MicroserviceData.class, null)).thenReturn(microserviceDatas); + List<Criterion> restrictionsList2 = new ArrayList<Criterion>(); + Criterion serviceIdCriterion = Restrictions.eq("serviceId", 1l); + restrictionsList2.add(serviceIdCriterion); + Mockito.when((List<MicroserviceParameter>) dataAccessService.getList(MicroserviceParameter.class, null, restrictionsList2, null)).thenReturn(microserviceParameters); + Mockito.when(CipherUtil.decryptPKC("xyz", + SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenThrow(BadPaddingException.class); + List<MicroserviceData> actual = microserviceServiceImpl.getMicroserviceData(); + assertNotNull(actual); + } +} |