diff options
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service')
21 files changed, 3607 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AppServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AppServiceImplTest.java new file mode 100644 index 00000000..c16e9493 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AppServiceImplTest.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.domain.App; + +@RunWith(MockitoJUnitRunner.class) +public class AppServiceImplTest { + + @Mock + private DataAccessService dataAccessService; + + @InjectMocks + private AppServiceImpl appServiceImpl; + + @Test + public void getAppsTest() { + App app = new App(); + List<App> appList = new ArrayList<>(); + appList.add(app); + when(dataAccessService.getList(App.class, null)).thenReturn(appList); + List<App> list = appServiceImpl.getApps(); + Assert.assertTrue(list.size() > 0); + } + + @Test + public void getAppTest() { + Long appId = 1l; + when(dataAccessService.getDomainObject(App.class, appId, null)).thenReturn(new App()); + App app = appServiceImpl.getApp(appId); + Assert.assertNotNull(app); + } + + @Test + public void getDefaultAppTest() { + Long appId = 1l; + when(dataAccessService.getDomainObject(App.class, appId, null)).thenReturn(new App()); + App app = appServiceImpl.getDefaultApp(); + Assert.assertNotNull(app); + } + + @Test + public void getDefaultAppNameTest() { + Long appId = 1l; + App app = new App(); + app.setName("Default App"); + when(dataAccessService.getDomainObject(App.class, appId, null)).thenReturn(app); + String defaultAppname = appServiceImpl.getDefaultAppName(); + Assert.assertEquals(app.getName(), defaultAppname); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AuditServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AuditServiceImplTest.java new file mode 100644 index 00000000..ade19911 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AuditServiceImplTest.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class AuditServiceImplTest { + + @Mock + private DataAccessService dataAccessService; + + @InjectMocks + private AuditServiceImpl auditServiceImpl; + + @Test + public void logActivityTest(){ + auditServiceImpl.logActivity(null, null); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/BroadcastServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/BroadcastServiceImplTest.java new file mode 100644 index 00000000..83ae5a42 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/BroadcastServiceImplTest.java @@ -0,0 +1,182 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +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.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.domain.BroadcastMessage; +import org.onap.portalsdk.core.domain.Lookup; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.test.util.ReflectionTestUtils; + +@RunWith(MockitoJUnitRunner.class) +public class BroadcastServiceImplTest { + @Mock + private DataAccessService dataAccessService; + + @InjectMocks + private BroadcastServiceImpl broadcastServiceImpl; + + @Test + public void getBcModelTest(){ + Lookup lookup = new Lookup(); + lookup.setValue("123"); + List<Lookup> lookupList = new ArrayList<>(); + lookupList.add(lookup); + + BroadcastMessage broadcastMessage = new BroadcastMessage(); + broadcastMessage.setActive(false); + ReflectionTestUtils.invokeSetterMethod(new AppUtils(), "dataAccessService", dataAccessService); + + List<BroadcastMessage> messagesList = new ArrayList<>(); + BroadcastMessage message1 = new BroadcastMessage(); + message1.setLocationId(123); + message1.setSortOrder(1); + message1.setId(1L); + BroadcastMessage message2 = new BroadcastMessage(); + message2.setLocationId(456); + message2.setSortOrder(2); + message2.setId(2L); + messagesList.add(message1); + messagesList.add(message2); + Mockito.when(dataAccessService.getList(BroadcastMessage.class,null)).thenReturn(messagesList); + Mockito.when(dataAccessService.getDomainObject(BroadcastMessage.class, 5L, null)).thenReturn(broadcastMessage); + + Mockito.when(dataAccessService.getLookupList("fn_lu_message_location", "message_location_id", + "message_location_descr", "", "message_location_id",null)).thenReturn(lookupList); + System.setProperty(SystemProperties.CLUSTERED,"true"); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + request.addParameter("task", "toggleActive"); + Map bcModel = broadcastServiceImpl.getBcModel(request); + Assert.assertTrue(bcModel.size() > 0); + } + + @Test + public void displayMessagesTest(){ + Lookup lookup = new Lookup(); + lookup.setValue("123"); + List<Lookup> lookupList = new ArrayList<>(); + lookupList.add(lookup); + + List<BroadcastMessage> messagesList = new ArrayList<>(); + BroadcastMessage message1 = new BroadcastMessage(); + message1.setLocationId(123); + message1.setSortOrder(1); + message1.setId(1L); + message1.setMessageText("Hello1"); + BroadcastMessage message2 = new BroadcastMessage(); + message2.setLocationId(456); + message2.setSortOrder(2); + message2.setId(2L); + message2.setMessageText("Hello2"); + messagesList.add(message1); + messagesList.add(message2); + + ReflectionTestUtils.invokeSetterMethod(new AppUtils(), "dataAccessService", dataAccessService); + + Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenReturn(messagesList); + Mockito.when(dataAccessService.getLookupList("fn_lu_message_location", "message_location_id", + "message_location_descr", "", "message_location_id",null)).thenReturn(lookupList); + broadcastServiceImpl.loadMessages(); + String message = broadcastServiceImpl.displayMessages("123"); + Assert.assertTrue(message.contains(message1.getMessageText())); + } + + @Test + public void hasServerMessagesTest(){ + + Lookup lookup = new Lookup(); + lookup.setValue("123"); + List<Lookup> lookupList = new ArrayList<>(); + lookupList.add(lookup); + + List<BroadcastMessage> messagesList = new ArrayList<>(); + BroadcastMessage message1 = new BroadcastMessage(); + message1.setLocationId(123); + message1.setSortOrder(1); + message1.setId(1L); + message1.setMessageText("Hello1"); + BroadcastMessage message2 = new BroadcastMessage(); + message2.setLocationId(456); + message2.setSortOrder(2); + message2.setId(2L); + message2.setMessageText("Hello2"); + messagesList.add(message1); + messagesList.add(message2); + + ReflectionTestUtils.invokeSetterMethod(new AppUtils(), "dataAccessService", dataAccessService); + + Mockito.when(dataAccessService.executeNamedQuery(Matchers.anyString(), Matchers.anyMap(), Matchers.anyMap())).thenReturn(messagesList); + Mockito.when(dataAccessService.getLookupList("fn_lu_message_location", "message_location_id", + "message_location_descr", "", "message_location_id",null)).thenReturn(lookupList); + broadcastServiceImpl.loadMessages(); + boolean messageExist = broadcastServiceImpl.hasServerMessages("123","123"); + Assert.assertTrue(messageExist); + } + + @Test + public void getBroadcastMessageTest(){ + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + request.addParameter("message_location_id", "123"); + Mockito.when(dataAccessService.getDomainObject(BroadcastMessage.class, 5L, null)).thenReturn(new BroadcastMessage()); + broadcastServiceImpl.getBroadcastMessage(request); + } + + @Test + public void getBroadcastMessageWithoutLocIdTest(){ + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + Mockito.when(dataAccessService.getDomainObject(BroadcastMessage.class, 5L, null)).thenReturn(new BroadcastMessage()); + broadcastServiceImpl.getBroadcastMessage(request); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/DataAccessServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/DataAccessServiceImplTest.java new file mode 100644 index 00000000..7f179f66 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/DataAccessServiceImplTest.java @@ -0,0 +1,350 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.SQLQuery; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; +import org.junit.Assert; +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.FusionObject.Parameters; +import org.onap.portalsdk.core.domain.support.DomainVo; +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({ SystemProperties.class }) +public class DataAccessServiceImplTest { + + @Mock + private SessionFactory sessionFactory; + + @InjectMocks + private DataAccessServiceImpl dataAccessServiceImpl; + + @Test + public void getDomainObjectTest() { + Session mockedSession = Mockito.mock(Session.class); + Long id = 1L; + DomainVo domainVo = new DomainVo(); + domainVo.setId(id); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.get(DomainVo.class, id)).thenReturn(domainVo); + DomainVo returnDomainVo = dataAccessServiceImpl.getDomainObject(DomainVo.class, id, null); + Assert.assertEquals(id, returnDomainVo.getId()); + } + + @Test + public void deleteDomainObjectTest() { + Session mockedSession = Mockito.mock(Session.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + dataAccessServiceImpl.deleteDomainObject(new DomainVo(), new HashMap<>()); + Assert.assertTrue(true); + } + + @Test + public void deleteDomainObjectsTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + String whereClause = "id = 1"; + dataAccessServiceImpl.deleteDomainObjects(DomainVo.class, whereClause, new HashMap<>()); + Assert.assertTrue(true); + } + + @Test + public void saveDomainObjectWithNewTest() { + Session mockedSession = Mockito.mock(Session.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Map params = new HashMap(); + params.put(Parameters.PARAM_USERID, 1); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("123"); + DomainVo domainVo = new DomainVo(); + domainVo.setId(0L); + dataAccessServiceImpl.saveDomainObject(domainVo, params); + Assert.assertTrue(true); + } + + @Test + public void saveDomainObjectWithUpdateTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Map params = new HashMap(); + params.put(Parameters.PARAM_USERID, 1L); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_USER_ID)).thenReturn("123"); + DomainVo domainVo = new DomainVo(); + domainVo.setId(10L); + dataAccessServiceImpl.saveDomainObject(domainVo, params); + Assert.assertTrue(true); + } + + @Test + public void getListWithOnlyClassTest() { + + DomainVo domainVo1 = new DomainVo(); + domainVo1.setId(1L); + DomainVo domainVo2 = new DomainVo(); + domainVo2.setId(1L); + + List<DomainVo> domainVoList = new ArrayList<>(); + domainVoList.add(domainVo1); + domainVoList.add(domainVo2); + + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + Mockito.when(mockQuery.list()).thenReturn(domainVoList); + List list = dataAccessServiceImpl.getList(DomainVo.class, new HashMap()); + Assert.assertEquals(2, list.size()); + + } + + @Test + public void getListWithOrderAndFilterTest() { + + DomainVo domainVo1 = new DomainVo(); + domainVo1.setId(1L); + DomainVo domainVo2 = new DomainVo(); + domainVo2.setId(1L); + + List<DomainVo> domainVoList = new ArrayList<>(); + domainVoList.add(domainVo1); + domainVoList.add(domainVo2); + + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + Mockito.when(mockQuery.list()).thenReturn(domainVoList); + List list = dataAccessServiceImpl.getList(DomainVo.class, "", "", new HashMap()); + Assert.assertEquals(2, list.size()); + + } + + @Test + public void getListTest() { + String filterClause = " where id = '1' "; + + DomainVo domainVo1 = new DomainVo(); + domainVo1.setId(1L); + DomainVo domainVo2 = new DomainVo(); + domainVo2.setId(1L); + + List<DomainVo> domainVoList = new ArrayList<>(); + domainVoList.add(domainVo1); + domainVoList.add(domainVo2); + + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + Mockito.when(mockQuery.list()).thenReturn(domainVoList); + List list = dataAccessServiceImpl.getList(DomainVo.class, filterClause, "id", new HashMap()); + Assert.assertEquals(2, list.size()); + } + + @Test + public void getListGenericTest() { + + List<Criterion> restrictionsList = new ArrayList<>(); + List<Order> orderList = new ArrayList<>(); + orderList.add(Order.asc("id")); + Criterion criterion1 = Restrictions.like("urlsAccessibleKey.url", "URL%"); + restrictionsList.add(criterion1); + Session mockedSession = Mockito.mock(Session.class); + Criteria criteria = Mockito.mock(Criteria.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createCriteria(DomainVo.class)).thenReturn(criteria); + List list = dataAccessServiceImpl.getList(DomainVo.class, null, restrictionsList, orderList); + Assert.assertNotNull(list); + } + + @Test + public void getLookupListTest() { + Session mockedSession = Mockito.mock(Session.class); + SQLQuery mockSQLQuery = Mockito.mock(SQLQuery.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createSQLQuery(Mockito.anyString())).thenReturn(mockSQLQuery); + Mockito.when(mockSQLQuery.list()).thenReturn(new ArrayList()); + List list = dataAccessServiceImpl.getLookupList("User ", "1", "id", "id", "", null); + Assert.assertNull(list); + } + + @Test + public void executeSQLQueryWithoutRangeTest() { + Session mockedSession = Mockito.mock(Session.class); + SQLQuery mockSQLQuery = Mockito.mock(SQLQuery.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createSQLQuery(Mockito.anyString())).thenReturn(mockSQLQuery); + Mockito.when(mockSQLQuery.addEntity("org.onap.portalsdk.core.domain.support.domainvo", DomainVo.class)) + .thenReturn(mockSQLQuery); + List list = dataAccessServiceImpl.executeSQLQuery("select * ", DomainVo.class, null); + Assert.assertNotNull(list); + } + + @Test + public void executeSQLQueryTest() { + Session mockedSession = Mockito.mock(Session.class); + SQLQuery mockSQLQuery = Mockito.mock(SQLQuery.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createSQLQuery(Mockito.anyString())).thenReturn(mockSQLQuery); + Mockito.when(mockSQLQuery.addEntity("org.onap.portalsdk.core.domain.support.domainvo", DomainVo.class)) + .thenReturn(mockSQLQuery); + List list = dataAccessServiceImpl.executeSQLQuery("select * ", DomainVo.class, 1, 3, null); + Assert.assertNotNull(list); + } + + @Test + public void executeQueryWithoutRangeTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + List list = dataAccessServiceImpl.executeQuery("select * ", null); + Assert.assertNotNull(list); + } + + @Test + public void executeQueryTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.createQuery(Mockito.anyString())).thenReturn(mockQuery); + List list = dataAccessServiceImpl.executeQuery("select * ", 1, 3, null); + Assert.assertNotNull(list); + } + + @Test + public void executeNamedQueryWithoutRangeTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.getNamedQuery(Mockito.anyString())).thenReturn(mockQuery); + Map params = new HashMap(); + params.put("map", new HashMap()); + params.put("list", new ArrayList()); + String[] args = { "abc" }; + params.put("obj", args); + + List list = dataAccessServiceImpl.executeNamedQuery("select * ", params, null); + Assert.assertNotNull(list); + } + + @Test + public void executeNamedQueryTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.getNamedQuery(Mockito.anyString())).thenReturn(mockQuery); + Map params = new HashMap(); + params.put("map", new HashMap()); + params.put("list", new ArrayList()); + String[] args = { "abc" }; + params.put("obj", args); + + List list = dataAccessServiceImpl.executeNamedQuery("select * ", params, 1, 3, null); + Assert.assertNotNull(list); + } + + @Test(expected = UnsupportedOperationException.class) + public void executeNamedQueryWithOrderByTest() { + dataAccessServiceImpl.executeNamedQueryWithOrderBy(DomainVo.class, "", null, "", false, 0, 3, null); + } + + @Test(expected = UnsupportedOperationException.class) + public void executeNamedCountQueryTest() { + dataAccessServiceImpl.executeNamedCountQuery(DomainVo.class, "select * ", " ", null); + } + + @Test(expected = UnsupportedOperationException.class) + public void executeNamedQueryExceptionTest() { + dataAccessServiceImpl.executeNamedQuery(DomainVo.class, "select * ", "", null, 1, 3, null); + } + + @Test(expected = UnsupportedOperationException.class) + public void executeNamedQueryWithOrderByExceptionTest() { + dataAccessServiceImpl.executeNamedQueryWithOrderBy(DomainVo.class, "", "", null, "", false, 0, 3, null); + } + + @Test(expected = UnsupportedOperationException.class) + public void getListExceptionTest() { + dataAccessServiceImpl.getList(DomainVo.class, null, null, null, null); + } + + @Test(expected = UnsupportedOperationException.class) + public void executeUpdateQueryTest() { + dataAccessServiceImpl.executeUpdateQuery("", null); + } + + @Test + public void executeNamedUpdateQueryTest() { + Session mockedSession = Mockito.mock(Session.class); + Query mockQuery = Mockito.mock(Query.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(mockedSession); + Mockito.when(mockedSession.getNamedQuery(Mockito.anyString())).thenReturn(mockQuery); + Mockito.when(mockQuery.executeUpdate()).thenReturn(1); + int result = dataAccessServiceImpl.executeNamedUpdateQuery("", null, null); + Assert.assertEquals(1, result); + } + + @Test(expected = UnsupportedOperationException.class) + public void synchronizeTest() { + dataAccessServiceImpl.synchronize(null); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementLinkServiceTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementLinkServiceTest.java new file mode 100644 index 00000000..87e668b8 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementLinkServiceTest.java @@ -0,0 +1,204 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FilenameUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.util.YamlUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, FilenameUtils.class , YamlUtils.class}) +public class ElementLinkServiceTest { + + @Test + public void buildElementLinkYamlTest() throws IOException{ + String stepName = "firstStep"; + String[] args = {"file", "custom", stepName}; + String modleYaml = "myYaml.yaml"; + + + Map<String, Object> callFlowBs = new HashMap<>(); + List<Map<String, Object>> callSteps = new ArrayList<>(); + Map<String, Object> callStep = new HashMap<>(); + + List<Map<String, Object>> subSteps = new ArrayList<>(); + Map<String, Object> subStep = new HashMap<>(); + subStep.put("source_tosca_id", "SOURCE"); + subStep.put("destination_tosca_id", "DESTINATION"); + subSteps.add(subStep); + + callStep.put("name", stepName); + callStep.put("subSteps", subSteps); + + callSteps.add(callStep); + callFlowBs.put("callSequenceSteps", callSteps); + callFlowBs.put("shortName", "test step"); + + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(YamlUtils.class); + Mockito.when(SystemProperties.getProperty("customCallFlow_path")).thenReturn("xyzPath"); + Mockito.when(YamlUtils.readYamlFile(Mockito.anyString(), Mockito.anyString())).thenReturn(callFlowBs); + Mockito.when(YamlUtils.returnYaml(Mockito.anyObject())).thenReturn(modleYaml); + + ElementLinkService elementLinkService = new ElementLinkService(); + String linkYaml = elementLinkService.buildElementLinkYaml(args); + Assert.assertEquals(modleYaml, linkYaml); + } + + @Test + public void addActiveNodesTest(){ + String step ="STEP1"; + Map<String, Object> callStep = new HashMap<>(); + List<String> activeIds = new ArrayList<>(); + activeIds.add(step); + callStep.put("activeIds", activeIds); + ElementLinkService elementLinkService = new ElementLinkService(); + List<String> steps = elementLinkService.addActiveNodes(callStep); + Assert.assertTrue(steps.contains(step)); + } + + @Test + public void addDisconnectLinksTest(){ + Map<String, Object> callStep = new HashMap<>(); + List<Map<String, Object>> disconnectLinks = new ArrayList<>(); + Map<String, Object> disconLink = new HashMap<>(); + disconLink.put("DummyStep", "DummyYaml"); + disconnectLinks.add(disconLink); + callStep.put("disconnectLinks", disconnectLinks); + + ElementLinkService elementLinkService = new ElementLinkService(); + List<Map<String, Object>> returnDisconnectLinks = elementLinkService.addDisconnectLinks(callStep); + Assert.assertTrue(returnDisconnectLinks.size() > 0); + } + + @Test + public void addLinkVerticesTest(){ + Map<String, Object> callStep = new HashMap<>(); + List<Map<String, Object>> vertices = new ArrayList<>(); + Map<String, Object> vertices1 = new HashMap<>(); + vertices1.put("x", 10); + vertices1.put("y", 20); + vertices1.put("D", "D"); + vertices1.put("L", "L"); + + Map<String, Object> vertices2 = new HashMap<>(); + vertices2.put("x", 30); + vertices2.put("y", 40); + vertices2.put("D", "D"); + vertices2.put("L", "L"); + + vertices.add(vertices1); + vertices.add(vertices2); + callStep.put("vertices", vertices); + ElementLinkService elementLinkService = new ElementLinkService(); + List<Map<String, Object>> returnVertices = elementLinkService.addLinkVertices(callStep); + Assert.assertTrue(returnVertices.size() > 0); + } + + @Test + public void mainTest() throws Exception{ + String[] args = {"file", "custom",}; + String stepName = "Step_2"; + Map<String, Object> callFlowBs = new HashMap<>(); + List<Map<String, Object>> callSteps = new ArrayList<>(); + Map<String, Object> callStep = new HashMap<>(); + + List<Map<String, Object>> subSteps = new ArrayList<>(); + Map<String, Object> subStep = new HashMap<>(); + subStep.put("source_tosca_id", "SOURCE"); + subStep.put("destination_tosca_id", "DESTINATION"); + subSteps.add(subStep); + + callStep.put("name", stepName); + callStep.put("subSteps", subSteps); + + callSteps.add(callStep); + callFlowBs.put("callSequenceSteps", callSteps); + callFlowBs.put("shortName", "teststep"); + + PowerMockito.mockStatic(YamlUtils.class); + Mockito.when(YamlUtils.readYamlFile(Mockito.anyString(), Mockito.anyString())).thenReturn(callFlowBs); + Mockito.when(YamlUtils.returnYaml(Mockito.anyObject())).thenReturn("modleYaml"); + ElementLinkService.main(args); + Assert.assertTrue(true); + } + + @Test + public void mainExceptionLogTest() throws Exception{ + String[] args = {"file", "custom",}; + String stepName = "Step_2"; + Map<String, Object> callFlowBs = new HashMap<>(); + List<Map<String, Object>> callSteps = new ArrayList<>(); + Map<String, Object> callStep = new HashMap<>(); + + List<Map<String, Object>> subSteps = new ArrayList<>(); + Map<String, Object> subStep = new HashMap<>(); + subStep.put("source_tosca_id", "SOURCE"); + subStep.put("destination_tosca_id", "DESTINATION"); + subSteps.add(subStep); + + callStep.put("name", stepName); + callStep.put("subSteps", subSteps); + + callSteps.add(callStep); + callFlowBs.put("callSequenceSteps", callSteps); + callFlowBs.put("shortName", "teststep"); + callStep.put("activeIds", "activeIds"); + callStep.put("disconnectLinks", "disconnectLinks"); + + PowerMockito.mockStatic(YamlUtils.class); + Mockito.when(YamlUtils.readYamlFile(Mockito.anyString(), Mockito.anyString())).thenReturn(callFlowBs); + Mockito.when(YamlUtils.returnYaml(Mockito.anyObject())).thenReturn("modleYaml"); + ElementLinkService.main(args); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java new file mode 100644 index 00000000..18771c63 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ElementMapServiceTest.java @@ -0,0 +1,481 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.io.FilenameUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.core.domain.support.Container; +import org.onap.portalsdk.core.domain.support.Domain; +import org.onap.portalsdk.core.domain.support.Element; +import org.onap.portalsdk.core.domain.support.ElementDetails; +import org.onap.portalsdk.core.domain.support.Layout; +import org.onap.portalsdk.core.domain.support.Position; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.util.YamlUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, FilenameUtils.class , YamlUtils.class}) +public class ElementMapServiceTest { + + @Test + public void buildElementMapYamlTest() throws IOException{ + String rootDir = "rootDir"; + String networkToscaYml ="networksca"; + String networkLayoutYml ="networkLayoutYml"; + String[] args = {"", "", rootDir, networkToscaYml, networkLayoutYml, "layout"}; + + Map<String, Object> toscaYaml = new HashMap<>(); + Map<String, Object> networkMapLayoutYaml = new HashMap<>(); + + List<Object> toscaNetEleList = new ArrayList<>(); + networkMapLayoutYaml.put("toscaNetworkMapElementStyleList", toscaNetEleList); + Map<String, String> elementDetails = new HashMap<>(); + elementDetails.put("tosca_id", "TO_SCA_ID"); + elementDetails.put("id", "ID"); + elementDetails.put("row", "ROW"); + elementDetails.put("column", "COLUMN"); + elementDetails.put("icon", "ICON"); + + toscaNetEleList.add(elementDetails); + + List<Object> containerStyleList = new ArrayList<>(); + + Map<String, String> containerDetails = new HashMap<>(); + containerDetails.put("logical_group_name", "/TO_SCA_ID"); + containerDetails.put("id", "ID"); + containerDetails.put("domain", "DOMAIN"); + containerDetails.put("row", "ROW"); + containerDetails.put("column", "COLUMN"); + containerStyleList.add(containerDetails); + networkMapLayoutYaml.put("containerStyleList", containerStyleList); + + List<Object> domainList = new ArrayList<>(); + + Map<String, String> domainDetails = new HashMap<>(); + domainDetails.put("name", "/TO_SCA_ID"); + domainDetails.put("id", "ID"); + domainDetails.put("row", "ROW"); + domainDetails.put("column", "COLUMN"); + domainList.add(domainDetails); + networkMapLayoutYaml.put("domainList", domainList); + + + PowerMockito.mockStatic(YamlUtils.class); + + Map<String, Object> topologyMap = new HashMap<>(); + toscaYaml.put("topology_template", topologyMap); + + Map<String, Object> nodeTemplateMap = new HashMap<>(); + topologyMap.put("node_templates", nodeTemplateMap); + + Mockito.when(YamlUtils.readYamlFile(rootDir, networkToscaYml+".yml")).thenReturn(toscaYaml); + Mockito.when(YamlUtils.readYamlFile(rootDir, networkLayoutYml+".yml")).thenReturn(networkMapLayoutYaml); + + ElementMapService elementMapService = new ElementMapService(); + elementMapService.buildElementMapYaml(args); + } + + + @Test + public void convertToYAMLTest() throws Exception { + ElementMapService elementMapService = new ElementMapService(); + + String contextRealPath = "element_map_icon_path"; + Layout layout = new Layout(null, 0, 0, 2, 2); + + Map<String, Domain> domainRowCol = new HashMap<>(); + Domain domain = new Domain("test", "XYZ", 0, 0, 0, 0, 0, 2, 2); + + Position position = new Position(); + position.setX(10); + position.setY(10); + domain.setP(position); + domainRowCol.put("00", domain); + domainRowCol.put("01", domain); + domainRowCol.put("10", domain); + layout.setDomainRowCol(domainRowCol); + + Map<String, Element> elementRowcol = new HashMap<>(); + Element element = new Element("12", "ue6"); + element.setP(position); + element.setBorderType("V"); + Element element2 = new Element("22", "ue6"); + element2.setP(position); + element2.setBorderType("U"); + elementRowcol.put("12", element); + elementRowcol.put("22", element2); + + Map<String, Container> containerRowCol = new HashMap<>(); + Container container00 = new Container("test","test",1,1,10,10,10,10,10,10); + container00.setElements(elementRowcol); + + container00.setP(position); + + Map<String, Container> innerContainer = new HashMap<>(); + Container container01 = new Container("test","test",1,1,10,10,10,10,10,10); + Map<String, Element> elementRowcolInner = new HashMap<>(); + Element elementInner = new Element("12", "dashed"); + elementInner.setP(position); + elementInner.setBorderType("V"); + + Element elementInner2 = new Element("22", "test"); + elementInner2.setP(position); + elementInner2.setBorderType("U"); + + elementRowcolInner.put("12", elementInner); + elementRowcolInner.put("22", elementInner2); + + container01.setP(position); + container01.setElements(elementRowcolInner); + innerContainer.put("01", container01); + + container00.setInnerContainer(innerContainer); + containerRowCol.put("00", container00); + + domain.setContainers(containerRowCol); + + List<Domain> domainList = new ArrayList<>(); + domainList.add(domain); + layout.setCollapsedDomainsNewList(domainList); + + Method method = elementMapService.getClass().getDeclaredMethod("convertToYAML", String.class, Layout.class ); + method.setAccessible(true); + String output = (String) method.invoke(elementMapService, contextRealPath,layout); + Assert.assertNotNull(output); + } + + @Test + public void computeRowsTest() throws Exception { + Set<String> rows = new HashSet<>(); + rows.add("2"); + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("computeRows", Set.class); + method.setAccessible(true); + int returnValue = (int) method.invoke(elementMapService, rows); + Assert.assertEquals(3, returnValue); + returnValue = (int) method.invoke(elementMapService, new HashSet<String>()); + Assert.assertEquals(1, returnValue); + } + + @Test + public void computeColumnsTest() throws Exception { + Set<String> columns = new HashSet<>(); + columns.add("02"); + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("computeColumns", Set.class); + method.setAccessible(true); + int returnValue = (int) method.invoke(elementMapService, columns); + Assert.assertEquals(3, returnValue); + returnValue = (int) method.invoke(elementMapService, new HashSet<String>()); + Assert.assertEquals(1, returnValue); + } + + @Test + public void fetchContainerObjectTest() throws Exception { + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchContainerObject", String.class, String.class, boolean.class, String.class, String.class) ; + method.setAccessible(true); + + + HashMap<String, Element> elementMap = new HashMap<>(); + String elementId = "234"; + Element element = new Element(elementId, "test"); + Position position = new Position(); + position.setX(10); + position.setY(10); + element.setP(position); + element.setBorderType("U"); + elementMap.put("241", element); + + String logicalName = "Test Logical Name"; + String domain = "Test Domain"; + String name = "Test Container"; + + ElementDetails elementDetails = new ElementDetails(logicalName,"test","test","test","test","test","test","test","test","test"); + element.setDetails(elementDetails); + + Field field = elementMapService.getClass().getDeclaredField("elementMap"); + field.setAccessible(true); + field.set(elementMapService, elementMap); + + HashMap<String, Object> toscaElementsMap = new HashMap<>(); + HashMap<String, Object> innertoscaElementsMap = new HashMap<>(); + + + HashMap<String, String> properties = new HashMap<>(); + properties.put("domain", domain); + innertoscaElementsMap.put("properties", properties); + toscaElementsMap.put(elementId, innertoscaElementsMap); + + Field toscalEleMap = elementMapService.getClass().getDeclaredField("toscaElementsMap"); + toscalEleMap.setAccessible(true); + toscalEleMap.set(elementMapService, toscaElementsMap); + + Container container = (Container) method.invoke(elementMapService, elementId, name , true, logicalName, domain); + Assert.assertEquals(name, container.getName()); + } + + @Test + public void fetchContainerObjectWithFalseTest() throws Exception{ + + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchContainerObject", String.class, String.class, boolean.class, String.class, String.class) ; + method.setAccessible(true); + + HashMap<String, Element> elementMap = new HashMap<>(); + String elementId = "278"; + Element element = new Element(elementId, "test"); + Position position = new Position(); + position.setX(10); + position.setY(10); + element.setP(position); + element.setBorderType("U"); + elementMap.put("285", element); + + String logicalName = "Test Logical Name"; + String domain = "Test Domain"; + String name = "Test Container"; + + ElementDetails elementDetails = new ElementDetails(logicalName,"test","test","test","test","test","test","test","test","test"); + element.setDetails(elementDetails); + + Field field = elementMapService.getClass().getDeclaredField("elementMap"); + field.setAccessible(true); + field.set(elementMapService, elementMap); + + HashMap<String, Object> toscaElementsMap = new HashMap<>(); + HashMap<String, Object> innertoscaElementsMap = new HashMap<>(); + + + HashMap<String, String> properties = new HashMap<>(); + properties.put("domain", domain); + innertoscaElementsMap.put("properties", properties); + toscaElementsMap.put(elementId, innertoscaElementsMap); + + Field toscalEleMap = elementMapService.getClass().getDeclaredField("toscaElementsMap"); + toscalEleMap.setAccessible(true); + toscalEleMap.set(elementMapService, toscaElementsMap); + + HashMap<String, Container> innercontainerMap = new HashMap<>(); + Container container00 = new Container("test","test",1,1,10,10,10,10,10,10); + innercontainerMap.put(domain + ":" + name, container00); + Field innercontainers = elementMapService.getClass().getDeclaredField("innercontainers"); + innercontainers.setAccessible(true); + innercontainers.set(elementMapService, innercontainerMap); + + Container container = (Container) method.invoke(elementMapService, elementId, name , false, logicalName, domain); + Assert.assertEquals(name, container.getName()); + + } + + @Test + public void fetchContainerObjectWithFalse2Test() throws Exception{ + + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchContainerObject", String.class, String.class, boolean.class, String.class, String.class) ; + method.setAccessible(true); + + HashMap<String, Element> elementMap = new HashMap<>(); + String elementId = "278"; + + String logicalName = "Test Logical Name"; + String domain = "Test Domain"; + String name = "Test Container"; + + Field field = elementMapService.getClass().getDeclaredField("elementMap"); + field.setAccessible(true); + field.set(elementMapService, elementMap); + + HashMap<String, Object> toscaElementsMap = new HashMap<>(); + HashMap<String, Object> innertoscaElementsMap = new HashMap<>(); + + HashMap<String, String> properties = new HashMap<>(); + properties.put("domain", domain); + innertoscaElementsMap.put("properties", properties); + toscaElementsMap.put(elementId, innertoscaElementsMap); + + Field toscalEleMap = elementMapService.getClass().getDeclaredField("toscaElementsMap"); + toscalEleMap.setAccessible(true); + toscalEleMap.set(elementMapService, toscaElementsMap); + + HashMap<String, Container> innercontainerMap = new HashMap<>(); + Container container00 = new Container("test","test",1,1,10,10,10,10,10,10); + innercontainerMap.put(domain + ":" + name, container00); + Field innercontainers = elementMapService.getClass().getDeclaredField("innercontainers"); + innercontainers.setAccessible(true); + innercontainers.set(elementMapService, innercontainerMap); + + Container container = (Container) method.invoke(elementMapService, elementId, name , false, logicalName, domain); + Assert.assertEquals(name, container.getName()); + + } + + @Test + public void fetchDomainObjectTest() throws Exception { + String id = "Domain Id"; + String name = "D-Name"; + + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchDomainObject", String.class, String.class) ; + method.setAccessible(true); + + Map<String, Element> elementRowCol = new HashMap<>(); + Element element = new Element("374", "test"); + Element element2 = new Element("375", "test"); + Position position = new Position(); + position.setX(10); + position.setY(10); + element.setP(position); + element.setBorderType("U"); + elementRowCol.put("285", element); + elementRowCol.put("382", element2); + + Map<String, Container> containerRowCol = new HashMap<>(); + Container container023 = new Container("test","test",1,1,10,10,10,10,10,10); + containerRowCol.put("00", container023); + + + HashMap<String, Container> outercontainerMap = new HashMap<>(); + Container container00 = new Container("test","test",1,1,10,10,10,10,10,10); + container00.setInnerContainer(containerRowCol); + container00.setElements(elementRowCol); + Container container01 = new Container("test","test",1,1,10,10,10,10,10,10); + container01.setElements(elementRowCol); + outercontainerMap.put(name+":", container00); + outercontainerMap.put(name+":/Test", container01); + + Field outercontainers = elementMapService.getClass().getDeclaredField("outercontainers"); + outercontainers.setAccessible(true); + outercontainers.set(elementMapService, outercontainerMap); + Domain domain = (Domain)method.invoke(elementMapService, id, name); + Assert.assertEquals(domain.getName(), name); + + } + + @Test + public void fetchElementObjectTest() throws Exception { + + String domain = "Test Domain"; + + String id = "420"; + String name = "ELEMENT"; + String imagePath = "src/images/"; + + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchElementObject", String.class, String.class, String.class); + method.setAccessible(true); + + HashMap<String, Object> toscaElementsMap = new HashMap<>(); + HashMap<String, Object> innertoscaElementsMap = new HashMap<>(); + + + HashMap<String, String> properties = new HashMap<>(); + String network_function = "NETWORK_FUNCTION"; + properties.put("domain", domain); + + properties.put("logical_group", "logical/group"); + properties.put("display_longname", "display_longname"); + properties.put("display_shortname", "display_shortname"); + properties.put("description", "description"); + properties.put("primary_function", "primary_function"); + properties.put("key_interfaces", "key_interfaces"); + properties.put("location", "location"); + properties.put("vendor", "vendor"); + properties.put("vendor_shortname", "vendor_shortname"); + properties.put("network_function", network_function); + properties.put("background_color", "background_color"); + + + innertoscaElementsMap.put("properties", properties); + toscaElementsMap.put(name, innertoscaElementsMap); + + Field toscalEleMap = elementMapService.getClass().getDeclaredField("toscaElementsMap"); + toscalEleMap.setAccessible(true); + toscalEleMap.set(elementMapService, toscaElementsMap); + Element element= (Element)method.invoke(elementMapService, id, name, imagePath); + Assert.assertEquals(element.getImgFileName(), imagePath); + } + + @Test + public void fetchElementObjectWithEmptyTest() throws Exception { + + String domain = "Test Domain"; + + String id = "420"; + String name = "ELEMENT"; + String imagePath = "src/images/"; + + ElementMapService elementMapService = new ElementMapService(); + Method method = elementMapService.getClass().getDeclaredMethod("fetchElementObject", String.class, String.class, String.class); + method.setAccessible(true); + + HashMap<String, Object> toscaElementsMap = new HashMap<>(); + HashMap<String, Object> innertoscaElementsMap = new HashMap<>(); + + + HashMap<String, String> properties = new HashMap<>(); + properties.put("domain", domain); + + properties.put("logical_group", "logical/group"); + + innertoscaElementsMap.put("properties", properties); + toscaElementsMap.put(name, innertoscaElementsMap); + + Field toscalEleMap = elementMapService.getClass().getDeclaredField("toscaElementsMap"); + toscalEleMap.setAccessible(true); + toscalEleMap.set(elementMapService, toscaElementsMap); + Element element= (Element)method.invoke(elementMapService, id, name, imagePath); + Assert.assertEquals(element.getImgFileName(), imagePath); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FnMenuServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FnMenuServiceImplTest.java new file mode 100644 index 00000000..2cf13d3a --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FnMenuServiceImplTest.java @@ -0,0 +1,181 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.portalsdk.core.domain.Menu; +import org.onap.portalsdk.core.domain.MenuData; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class FnMenuServiceImplTest { + @Mock + private DataAccessService dataAccessService; + + @InjectMocks + private FnMenuServiceImpl fnMenuServiceImpl; + + @Test + public void getFnMenuItemsTest() { + Long menuId = 1L; + List<MenuData> menuDataList = new ArrayList<>(); + MenuData menuData = new MenuData(); + menuData.setId(menuId); + menuDataList.add(menuData); + when(dataAccessService.getList(MenuData.class, null, "1", null)).thenReturn(menuDataList); + List<MenuData> returnList = fnMenuServiceImpl.getFnMenuItems(); + Assert.assertTrue(returnList.size() > 0); + } + + @Test + public void saveFnMenuDataTest() { + Long menuId = 1L; + MenuData menuData = new MenuData(); + menuData.setId(menuId); + fnMenuServiceImpl.saveFnMenuData(menuData); + Assert.assertTrue(true); + } + + @Test + public void getParentIdTest() { + String label = "XYZ"; + + List<Long> longValues = new ArrayList<>(); + longValues.add(1L); + longValues.add(2L); + + Map<String, String> params = new HashMap<>(); + params.put("paramLabel", label); + when(dataAccessService.executeNamedQuery("IdForLabelList", params, null)).thenReturn(longValues); + List<Long> returnList = fnMenuServiceImpl.getParentId(label); + Assert.assertTrue(returnList.size() > 0); + + } + + @Test + public void getParentListTest() { + List<List> parentList = new ArrayList<>(); + List<Long> longValues = new ArrayList<>(); + longValues.add(1L); + longValues.add(2L); + parentList.add(longValues); + when(dataAccessService.executeNamedQuery("parentList", null, null)).thenReturn(parentList); + List<List> returnParentList = fnMenuServiceImpl.getParentList(); + Assert.assertTrue(returnParentList.size() > 0); + } + + @Test + public void removeMenuItemDataTest() { + MenuData domainFnMenu = new MenuData(); + domainFnMenu.setId(1L); + fnMenuServiceImpl.removeMenuItem(domainFnMenu); + Assert.assertTrue(true); + } + + @Test + public void removeMenuItemTest() { + Menu menu = new Menu(); + menu.setId(1L); + fnMenuServiceImpl.removeMenuItem(menu); + Assert.assertTrue(true); + } + + @Test + public void getMenuItemRowTest() { + Long id = 1L; + MenuData domainFnMenu = new MenuData(); + domainFnMenu.setId(id); + when(dataAccessService.getDomainObject(MenuData.class, id, null)).thenReturn(domainFnMenu); + MenuData menuData = fnMenuServiceImpl.getMenuItemRow(id); + Assert.assertEquals(id, menuData.getId()); + } + + @Test + public void getMenuItemTest() { + Long id = 1L; + Menu menu = new Menu(); + menu.setId(id); + when(dataAccessService.getDomainObject(Menu.class, id, null)).thenReturn(menu); + Menu returnMenu = fnMenuServiceImpl.getMenuItem(id); + Assert.assertEquals(id, returnMenu.getId()); + } + + @Test + public void saveFnMenuTest() { + Long id = 1L; + Menu menu = new Menu(); + menu.setId(id); + fnMenuServiceImpl.saveFnMenu(menu); + Assert.assertTrue(true); + } + + @Test + public void setMenuDataStructureTest() { + Set<MenuData> menuResult = new HashSet<>(); + + MenuData parentMenu = new MenuData(); + parentMenu.setId(1L); + + MenuData childMenu = new MenuData(); + childMenu.setId(1L); + + Set<MenuData> childSet = new HashSet<>(); + childSet.add(childMenu); + parentMenu.setChildMenus(childSet); + menuResult.add(parentMenu); + + List<List<MenuData>> childItemList = new ArrayList<>(); + List<MenuData> parentList = new ArrayList<>(); + fnMenuServiceImpl.setMenuDataStructure(childItemList, parentList, menuResult); + Assert.assertTrue(childItemList.size() > 0); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceCentralizedImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceCentralizedImplTest.java new file mode 100644 index 00000000..b589c50b --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceCentralizedImplTest.java @@ -0,0 +1,77 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; + +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.domain.User; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ UserUtils.class }) +public class FunctionalMenuListServiceCentralizedImplTest { + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @InjectMocks + private FunctionalMenuListServiceCentralizedImpl fmServiceCentralizedImpl; + + @Test(expected = IOException.class) + public void getFunctionCDListTest() throws IOException { + + HttpServletRequest mockedRequest = Mockito.mock(HttpServletRequest.class); + User user = new User(); + user.setOrgId(123L); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(restApiRequestBuilder.getViaREST("/menuFunctions", true, user.getOrgUserId())).thenReturn(""); + + fmServiceCentralizedImpl.getFunctionCDList(mockedRequest); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceImplTest.java new file mode 100644 index 00000000..2cbedf97 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/FunctionalMenuListServiceImplTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Assert; +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.domain.RoleFunction; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class FunctionalMenuListServiceImplTest { + + @InjectMocks + private FunctionalMenuListServiceImpl fmListServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getFunctionCDListTest() throws IOException { + + HttpServletRequest mockedRequest = Mockito.mock(HttpServletRequest.class); + List<RoleFunction> roleFunctionList = new ArrayList<>(); + RoleFunction roleFunction = new RoleFunction(); + roleFunction.setId(1L); + roleFunction.setName("Test"); + roleFunctionList.add(roleFunction); + Mockito.when(dataAccessService.executeNamedQuery("functionCDlist", null, null)).thenReturn(roleFunctionList); + List<RoleFunction> returnData = fmListServiceImpl.getFunctionCDList(mockedRequest); + Assert.assertTrue(returnData.size() > 0); + + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LdapServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LdapServiceImplTest.java new file mode 100644 index 00000000..87e507cd --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LdapServiceImplTest.java @@ -0,0 +1,156 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.lang.reflect.Method; + +import javax.naming.NamingEnumeration; +import javax.naming.directory.Attributes; +import javax.naming.directory.BasicAttributes; +import javax.naming.directory.InitialDirContext; +import javax.naming.directory.SearchControls; +import javax.naming.directory.SearchResult; + +import org.junit.Assert; +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.domain.User; +import org.onap.portalsdk.core.service.support.ServiceLocator; +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({ SystemProperties.class }) +public class LdapServiceImplTest { + + @InjectMocks + private LdapServiceImpl ldapServiceImpl; + + @Mock + private ServiceLocator serviceLocator; + + @Test + public void searchPostTest() throws Exception { + User user = new User(); + user.setFirstName("First Name"); + user.setLastName("Last Name"); + user.setHrid("HRID1"); + user.setOrgManagerUserId("M123"); + user.setOrgCode("ORG"); + user.setEmail("xyz@xyz.com"); + user.setOrgUserId("U123"); + + String sortBy1 = "sortBy1"; + String sortBy2 = "sortBy2"; + String sortBy3 = "sortBy3"; + int pageNo = 10; + int dataSize = 20; + int userId = 123; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_INITIAL_CONTEXT_FACTORY)).thenReturn("FACTORY"); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_PROVIDER_URL)).thenReturn("URL"); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_SECURITY_PRINCIPAL)).thenReturn("PRINCIPAL"); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_MAX_RESULT_SIZE)).thenReturn("1"); + + InitialDirContext dirContext = Mockito.mock(InitialDirContext.class); + SearchResult mockSearchResult = Mockito.mock(SearchResult.class); + + Mockito.when(serviceLocator.getDirContext(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(dirContext); + + NamingEnumeration mockSearchResults = Mockito.mock(NamingEnumeration.class); + Mockito.when(dirContext.search(Mockito.anyString(), Mockito.anyString(), Mockito.any(SearchControls.class))) + .thenReturn(mockSearchResults); + Mockito.when(mockSearchResults.hasMore()).thenReturn(true); + Mockito.when(mockSearchResults.next()).thenReturn(mockSearchResult); + org.onap.portalsdk.core.command.support.SearchResult searchResult = (org.onap.portalsdk.core.command.support.SearchResult) ldapServiceImpl + .searchPost(user, sortBy1, sortBy2, sortBy3, pageNo, dataSize, userId); + Assert.assertNotNull(searchResult); + } + + @Test + public void processAttributesTest() throws Exception { + BasicAttributes attributes = new BasicAttributes(); + + attributes.put("nickname", "FirstName"); + attributes.put("initials", "Mr"); + + attributes.put("sn", "sn"); + attributes.put("employeeNumber", "employeeNumber"); + attributes.put("nickname", "FirstName"); + attributes.put("mail", "mail"); + attributes.put("telephoneNumber", "telephoneNumber"); + attributes.put("departmentNumber", "departmentNumber"); + attributes.put("a1", "a1"); + attributes.put("street", "street"); + attributes.put("roomNumber", "roomNumber"); + attributes.put("l", "l"); + attributes.put("st", "st"); + attributes.put("postalCode", "postalCode"); + attributes.put("zip4", "zip4"); + attributes.put("physicalDeliveryOfficeName", "physicalDeliveryOfficeName"); + attributes.put("bc", "bc"); + attributes.put("friendlyCountryName", "friendlyCountryName"); + attributes.put("bd", "bd"); + attributes.put("bdname", "bdname"); + attributes.put("jtname", "jtname"); + attributes.put("mgrid", "mgrid"); + attributes.put("a2", "a2"); + attributes.put("compcode", "compcode"); + attributes.put("compdesc", "compdesc"); + attributes.put("bu", "bu"); + attributes.put("buname", "buname"); + attributes.put("silo", "silo"); + attributes.put("costcenter", "costcenter"); + attributes.put("b2", "b2"); + attributes.put("test", "test"); + + Method method = ldapServiceImpl.getClass().getDeclaredMethod("processAttributes", Attributes.class); + method.setAccessible(true); + + User user = (User)method.invoke(ldapServiceImpl, attributes); + Assert.assertNotNull(user); + + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LocalAccessConditionTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LocalAccessConditionTest.java new file mode 100644 index 00000000..c78e46cc --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LocalAccessConditionTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ PortalApiProperties.class }) +public class LocalAccessConditionTest { + + @InjectMocks + private LocalAccessCondition localAccessCondition; + + @Test + public void matchesTest(){ + ConditionContext context = Mockito.mock(ConditionContext.class); + AnnotatedTypeMetadata metadata = Mockito.mock(AnnotatedTypeMetadata.class); + boolean matches = localAccessCondition.matches(context, metadata); + Assert.assertTrue(matches); + } + + @Test + public void matchesWithAccessTest(){ + ConditionContext context = Mockito.mock(ConditionContext.class); + AnnotatedTypeMetadata metadata = Mockito.mock(AnnotatedTypeMetadata.class); + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED)).thenReturn("LOCAL"); + boolean matches = localAccessCondition.matches(context, metadata); + Assert.assertTrue(matches); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImplTest.java new file mode 100644 index 00000000..2f827bd9 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceCentralizedImplTest.java @@ -0,0 +1,200 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +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.junit.Assert; +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.onboarding.util.PortalApiProperties; +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.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ PortalApiProperties.class, AppUtils.class, UserUtils.class, SystemProperties.class }) +public class LoginServiceCentralizedImplTest { + + @InjectMocks + private LoginServiceCentralizedImpl loginServiceCentrImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @Mock + private UserService userService; + + @Test + public void findUserTest() throws Exception { + String userId = "S1234"; + LoginBean bean = new LoginBean(); + bean.setUserid(userId); + String menuPropertiesFilename =""; + Map additionalParams = new HashMap(); + + User mockUser = new User(); + mockUser.setOrgUserId("G1234"); + mockUser.setLoginId(userId); + + 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(); + + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + userApp.setUserId(1L); + userApp.setApp(app); + userApp.setRole(role); + userApps.add(userApp); + mockUser.setUserApps(userApps); + + mockUser.setActive(true); + + Mockito.when(restApiRequestBuilder.getViaREST("/user/" + bean.getUserid(), true, bean.getUserid())).thenReturn("Dummy Response"); + Mockito.when(userService.userMapper(Mockito.anyString())).thenReturn(mockUser); + + Map<String, String> params = new HashMap<>(); + params.put("orgUserId", mockUser.getOrgUserId()); + + List idList = new ArrayList(); + idList.add(1L); + Mockito.when(dataAccessService.executeNamedQuery("getUserIdByorgUserId", params, null)).thenReturn(idList); + + LoginBean loginBean = loginServiceCentrImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertEquals(loginBean.getUserid(), userId); + } + + + @Test + public void findUserWithErroMsgTest() throws Exception { + String userId = "S1234"; + LoginBean bean = new LoginBean(); + bean.setUserid(userId); + String menuPropertiesFilename =""; + Map additionalParams = new HashMap(); + + User mockUser = new User(); + mockUser.setOrgUserId("G1234"); + mockUser.setLoginId(userId); + + mockUser.setActive(false); + + Mockito.when(restApiRequestBuilder.getViaREST("/user/" + bean.getUserid(), true, bean.getUserid())).thenReturn("Dummy Response"); + Mockito.when(userService.userMapper(Mockito.anyString())).thenReturn(mockUser); + + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.isApplicationLocked()).thenReturn(true); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID)).thenReturn("SYSTEMS"); + + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.hasRole(Mockito.any(User.class), Mockito.any(String.class))).thenReturn(false); + + LoginBean loginBean = loginServiceCentrImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertEquals(loginBean.getUserid(), userId); + } + + @Test + public void findUserWihtoutUserIdTest() throws Exception { + LoginBean bean = new LoginBean(); + String menuPropertiesFilename =""; + Map additionalParams = new HashMap(); + + User mockUser = new User(); + mockUser.setOrgUserId("G1234"); + mockUser.setLoginId("L1234"); + + LoginBean loginBean = loginServiceCentrImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertNull(loginBean.getLoginId()); + + } + + @Test + public void findUserWithoutUserIdTest() throws Exception { + LoginBean bean = new LoginBean(); + String menuPropertiesFilename =""; + Map additionalParams = new HashMap(); + LoginBean loginBean = loginServiceCentrImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertNull(loginBean.getLoginId()); + } + + @Test + public void findUserWithoutUserIdAndPasswordTest() throws Exception { + LoginBean bean = new LoginBean(); + String menuPropertiesFilename =""; + Map additionalParams = new HashMap(); + LoginBean loginBean = loginServiceCentrImpl.findUser(bean, menuPropertiesFilename, additionalParams, false); + Assert.assertNull(loginBean.getLoginId()); + + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceImplTest.java new file mode 100644 index 00000000..ecaec1cb --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/LoginServiceImplTest.java @@ -0,0 +1,185 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +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.junit.Assert; +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.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, AppUtils.class, UserUtils.class }) +public class LoginServiceImplTest { + + @InjectMocks + private LoginServiceImpl loginServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void findUserTest() throws Exception { + String userId = "S1234"; + LoginBean bean = new LoginBean(); + bean.setUserid(userId); + String menuPropertiesFilename = ""; + Map additionalParams = new HashMap(); + + 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(); + + App app = new App(); + app.setId(new Long(1)); + app.setName("Default"); + userApp.setUserId(1L); + userApp.setApp(app); + userApp.setRole(role); + userApps.add(userApp); + + User mockUser = new User(); + mockUser.setOrgUserId("G1234"); + mockUser.setLoginId(userId); + mockUser.setUserApps(userApps); + mockUser.setActive(true); + + List users = new ArrayList(); + users.add(mockUser); + + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", bean.getUserid()); + + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params, new HashMap())) + .thenReturn(users); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME)).thenReturn("Menu"); + Mockito.when(SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME)).thenReturn("Menu"); + + LoginBean returnBean = loginServiceImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertNotNull(returnBean.getUser()); + } + + @Test + public void findUserWithErrorMsgTest() throws Exception { + String userId = "S1234"; + LoginBean bean = new LoginBean(); + bean.setUserid(userId); + String menuPropertiesFilename = ""; + Map additionalParams = new HashMap(); + + User mockUser = new User(); + mockUser.setOrgUserId("G1234"); + mockUser.setLoginId(userId); + + List users = new ArrayList(); + users.add(mockUser); + + Map<String, String> params = new HashMap<>(); + params.put("org_user_id", bean.getUserid()); + + Mockito.when(dataAccessService.executeNamedQuery("getUserByOrgUserId", params, new HashMap())) + .thenReturn(users); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_SET_NAME)).thenReturn("Menu"); + Mockito.when(SystemProperties.getProperty(SystemProperties.BUSINESS_DIRECT_MENU_SET_NAME)).thenReturn("Menu"); + Mockito.when(SystemProperties.getProperty(SystemProperties.SYS_ADMIN_ROLE_ID)).thenReturn("Role"); + + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.isApplicationLocked()).thenReturn(true); + + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.hasRole(Mockito.any(User.class), Mockito.anyString())).thenReturn(false); + + LoginBean returnBean = loginServiceImpl.findUser(bean, menuPropertiesFilename, additionalParams); + Assert.assertNull(returnBean.getUser()); + } + + @Test + public void findUserWithoutUseridAndPassTrueTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setLoginId("L1234"); + bean.setLoginPwd("L1234"); + String menuPropertiesFilename = ""; + Map additionalParams = new HashMap(); + LoginBean returnBean = loginServiceImpl.findUser(bean, menuPropertiesFilename, additionalParams, true); + Assert.assertNull(returnBean.getUser()); + } + + @Test + public void findUserWithoutUseridAndPassFalseTest() throws Exception { + LoginBean bean = new LoginBean(); + bean.setLoginId("L1234"); + bean.setLoginPwd("L1234"); + String menuPropertiesFilename = ""; + Map additionalParams = new HashMap(); + LoginBean returnBean = loginServiceImpl.findUser(bean, menuPropertiesFilename, additionalParams, false); + Assert.assertNull(returnBean.getUser()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/PostSearchServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/PostSearchServiceImplTest.java new file mode 100644 index 00000000..7e42c531 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/PostSearchServiceImplTest.java @@ -0,0 +1,188 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +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.PostSearchBean; +import org.onap.portalsdk.core.domain.Lookup; +import org.onap.portalsdk.core.domain.Role; +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.mock.web.MockHttpServletRequest; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class}) +public class PostSearchServiceImplTest { + + @InjectMocks + private PostSearchServiceImpl postSearchServiceImpl; + + + @Mock + private DataAccessService dataAccessService; + + @Test + public void processTest() throws Exception { + + PostSearchBean postSearch = new PostSearchBean(); + + String select[] = {"One", "Two"}; + String[] postOrgUserId = {"One", "Two"}; + String firstNames[] = {"One", "Two"}; + String[] lastNames = {"One", "Two"}; + postSearch.setSelected(select); + postSearch.setPostFirstName(firstNames); + postSearch.setPostLastName(lastNames); + + postSearch.setPostHrid(lastNames); + postSearch.setPostPhone(lastNames); + postSearch.setPostEmail(lastNames); + postSearch.setPostAddress1(lastNames); + postSearch.setPostAddress2(lastNames); + postSearch.setPostCity(firstNames); + postSearch.setPostState(lastNames); + postSearch.setPostZipCode(lastNames); + postSearch.setPostLocationClli(lastNames); + postSearch.setPostBusinessCountryCode(firstNames); + postSearch.setPostBusinessCountryName(lastNames); + postSearch.setPostOrgUserId(postOrgUserId); + postSearch.setPostDepartment(firstNames); + postSearch.setPostDepartmentName(firstNames); + postSearch.setPostBusinessUnit(firstNames); + postSearch.setPostBusinessUnitName(firstNames); + postSearch.setPostJobTitle(lastNames); + postSearch.setPostOrgManagerUserId(firstNames); + postSearch.setPostCommandChain(lastNames); + postSearch.setPostCompanyCode(firstNames); + postSearch.setPostCompany(firstNames); + postSearch.setPostCostCenter(firstNames); + postSearch.setPostSiloStatus(firstNames); + postSearch.setPostFinancialLocCode(firstNames); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + + Lookup lookup = new Lookup(); + lookup.setValue("Dummy Lookup"); + List list =new ArrayList<>(); + list.add(lookup); + + Mockito.when(dataAccessService.getLookupList("fn_lu_country", "country_cd", "country","country = 'One'", null, null)).thenReturn(list); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_DEFAULT_ROLE_ID)).thenReturn("2"); + + Role role = new Role(); + role.setId(2L); + Mockito.when(dataAccessService.getDomainObject(Role.class, Long.valueOf(SystemProperties.getProperty(SystemProperties.POST_DEFAULT_ROLE_ID)), + null)).thenReturn(role); + + int importedUser = postSearchServiceImpl.process(request, postSearch); + Assert.assertEquals(2, importedUser); + } + + @Test(expected = Exception.class) + public void processExceptionTest() throws Exception { + + PostSearchBean postSearch = new PostSearchBean(); + + String select[] = {"One", "Two"}; + String[] postOrgUserId = {"One", "Two"}; + String firstNames[] = {"One", "Two"}; + String[] lastNames = {"One", "Two"}; + postSearch.setSelected(select); + postSearch.setPostFirstName(firstNames); + postSearch.setPostLastName(lastNames); + + postSearch.setPostHrid(lastNames); + postSearch.setPostPhone(lastNames); + postSearch.setPostEmail(lastNames); + postSearch.setPostAddress1(lastNames); + postSearch.setPostAddress2(lastNames); + postSearch.setPostCity(firstNames); + postSearch.setPostState(lastNames); + postSearch.setPostZipCode(lastNames); + postSearch.setPostLocationClli(lastNames); + postSearch.setPostBusinessCountryCode(firstNames); + postSearch.setPostBusinessCountryName(lastNames); + postSearch.setPostOrgUserId(postOrgUserId); + postSearch.setPostDepartment(firstNames); + postSearch.setPostDepartmentName(firstNames); + postSearch.setPostBusinessUnit(firstNames); + postSearch.setPostBusinessUnitName(firstNames); + postSearch.setPostJobTitle(lastNames); + postSearch.setPostOrgManagerUserId(firstNames); + postSearch.setPostCommandChain(lastNames); + postSearch.setPostCompanyCode(firstNames); + postSearch.setPostCompany(firstNames); + postSearch.setPostCostCenter(firstNames); + postSearch.setPostSiloStatus(firstNames); + postSearch.setPostFinancialLocCode(firstNames); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + + Lookup lookup = new Lookup(); + lookup.setValue("Dummy Lookup"); + List list =new ArrayList<>(); + list.add(lookup); + + Mockito.when(dataAccessService.getLookupList("fn_lu_country", "country_cd", "country","country = 'One'", null, null)).thenReturn(list); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.POST_DEFAULT_ROLE_ID)).thenReturn("2"); + + Role role = new Role(); + Mockito.when(dataAccessService.getDomainObject(Role.class, Long.valueOf(SystemProperties.getProperty(SystemProperties.POST_DEFAULT_ROLE_ID)), + null)).thenReturn(role); + + postSearchServiceImpl.process(request, postSearch); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceCentralizedImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceCentralizedImplTest.java new file mode 100644 index 00000000..23b3f25f --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceCentralizedImplTest.java @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Assert; +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.domain.Profile; +import org.onap.portalsdk.core.domain.User; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ProfileServiceCentralizedImplTest { + + @InjectMocks + private ProfileServiceCentralizedImpl profileServiceCentrImpl ; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @Test + public void findAllTest() throws Exception { + profileServiceCentrImpl.findAll(); + } + + @Test + public void getProfileTest() throws Exception { + String json = "{ \"first_name\" : \"Mercedes\", \"last_name\" : \"Name\" }"; + Mockito.when(restApiRequestBuilder.getViaREST(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString())).thenReturn(json); + Profile profile = profileServiceCentrImpl.getProfile(12); + Assert.assertNotNull(profile); + } + + @Test + public void getUserTest() throws Exception { + String json = "{ \"firstName\" : \"Mercedes\"}"; + Mockito.when(restApiRequestBuilder.getViaREST(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString())).thenReturn(json); + User user = profileServiceCentrImpl.getUser("12"); + Assert.assertNotNull(user); + } + + @Test + public void saveUserTest() { + User user = new User(); + profileServiceCentrImpl.saveUser(user); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceImplTest.java new file mode 100644 index 00000000..fae7b75b --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/ProfileServiceImplTest.java @@ -0,0 +1,99 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Assert; +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.dao.ProfileDao; +import org.onap.portalsdk.core.domain.Profile; +import org.onap.portalsdk.core.domain.User; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ProfileServiceImplTest { + + @InjectMocks + private ProfileServiceImpl profileServiceImpl; + + @Mock + private ProfileDao profileDao; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void findAllTest(){ + profileServiceImpl.findAll(); + Assert.assertTrue(true); + } + + @Test + public void getUserTest(){ + String userId = "123"; + User user = new User(); + user.setOrgUserId(userId); + + Mockito.when(dataAccessService.getDomainObject(User.class, Long.parseLong(userId), null)).thenReturn(user); + + User returnuser = profileServiceImpl.getUser(userId); + Assert.assertEquals(userId, returnuser.getOrgUserId()); + } + + @Test + public void saveUserTest() { + String userId = "123"; + User user = new User(); + user.setOrgUserId(userId); + profileServiceImpl.saveUser(user); + Assert.assertTrue(true); + } + + @Test + public void getProfileTest() { + Profile profile = new Profile(); + Long id = 12L; + profile.setId(id); + Mockito.when(profileDao.getProfile(12)).thenReturn(profile); + Profile value = profileServiceImpl.getProfile(12); + Assert.assertEquals(id, value.getId()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RestApiRequestBuilderTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RestApiRequestBuilderTest.java new file mode 100644 index 00000000..21a0e797 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RestApiRequestBuilderTest.java @@ -0,0 +1,292 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; + +import org.junit.Assert; +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.domain.App; +import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, CipherUtil.class, RestWebServiceClient.class }) +public class RestApiRequestBuilderTest { + + @InjectMocks + private RestApiRequestBuilder restApiRequestBuilder; + + @Mock + private AppService appService; + + @Test + public void getViaRESTTest() throws Exception { + String restEndPoint = ""; + boolean isBasicAuth = false; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + String status = "SUCCESS"; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(app.getAppPassword()); + + PowerMockito.mockStatic(RestWebServiceClient.class); + + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + + Mockito.when(client.getPortalContent(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn(status); + + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + String response = restApiRequestBuilder.getViaREST(restEndPoint, isBasicAuth, userId); + Assert.assertEquals(status, response); + } + + @Test(expected=IOException.class) + public void getViaRESTTExceptionest() throws Exception { + String restEndPoint = ""; + boolean isBasicAuth = false; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + restApiRequestBuilder.getViaREST(restEndPoint, isBasicAuth, userId); + } + + @Test + public void getViaRESTWithoutAppTest() throws Exception { + + String restEndPoint = ""; + boolean isBasicAuth = false; + String userId = "123"; + + String status = "FAILURE"; + + PowerMockito.mockStatic(RestWebServiceClient.class); + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + + Mockito.when(client.getPortalContent(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn(status); + + Mockito.when(appService.getDefaultApp()).thenReturn(null); + + String response = restApiRequestBuilder.getViaREST(restEndPoint, isBasicAuth, userId); + Assert.assertEquals(status, response); + + } + + @Test + public void postViaRESTTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + String status = "SUCCESS"; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(app.getAppPassword()); + + PowerMockito.mockStatic(RestWebServiceClient.class); + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + Mockito.when(client.postPortalContent(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn(status); + + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + restApiRequestBuilder.postViaREST(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } + + @Test(expected = IOException.class) + public void postViaRESTExceptionTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + restApiRequestBuilder.postViaREST(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } + + @Test + public void postViaRESTWithoutAppTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + Mockito.when(appService.getDefaultApp()).thenReturn(null); + + PowerMockito.mockStatic(RestWebServiceClient.class); + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + Mockito.when(client.postPortalContent(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn("SUCCESS"); + + restApiRequestBuilder.postViaREST(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } + + @Test + public void deleteViaRestTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + String status = "SUCCESS"; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword(), + SystemProperties.getProperty(SystemProperties.Decryption_Key))).thenReturn(app.getAppPassword()); + + PowerMockito.mockStatic(RestWebServiceClient.class); + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + Mockito.when(client.postPortalContent(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn(status); + + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + restApiRequestBuilder.deleteViaRest(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } + + @Test(expected = IOException.class) + public void deleteViaRestExceptionTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + + App app = new App(); + app.setName("Test"); + app.setUsername("TestUser"); + app.setAppPassword("Password"); + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(app.getAppPassword()); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + restApiRequestBuilder.deleteViaRest(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } + + @Test + public void deleteViaRestWithoutAppTest() throws Exception { + String restEndPoint =""; + boolean isBasicAuth = false; + String content = "Data"; + String userId = "123"; + Mockito.when(appService.getDefaultApp()).thenReturn(null); + + PowerMockito.mockStatic(RestWebServiceClient.class); + RestWebServiceClient client = Mockito.mock(RestWebServiceClient.class); + Mockito.when(RestWebServiceClient.getInstance()).thenReturn(client); + Mockito.when(client.postPortalContent(Mockito.anyString(),Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), + Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn("SUCCESS"); + + restApiRequestBuilder.deleteViaRest(restEndPoint, isBasicAuth,content, userId); + + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceCentralizedAccessTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceCentralizedAccessTest.java new file mode 100644 index 00000000..0b61af8d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceCentralizedAccessTest.java @@ -0,0 +1,165 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.io.IOException; +import java.util.List; + +import org.junit.Assert; +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.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class RoleServiceCentralizedAccessTest { + + @InjectMocks + private RoleServiceCentralizedAccess roleServiceCntrlAccess; + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @Test + public void getRoleFunctionsTest() throws Exception { + String loginId ="1234"; + String response ="[ { \"code\" : \"abc\", \"name\" : \"xyz\" }, { \"code\" : \"pqr\", \"name\" : \"str\" } ]"; + Mockito.when(restApiRequestBuilder.getViaREST("/functions", true, loginId)).thenReturn(response); + List<RoleFunction> roleFunctions = roleServiceCntrlAccess.getRoleFunctions(loginId); + Assert.assertTrue(roleFunctions.size() > 0); + } + + @Test + public void getAvailableChildRolesWithEmptyRoleIdTest() throws Exception { + String loginId = "123"; + Long roleId = null; + String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]"; + Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response); + List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId); + Assert.assertNotNull(roles); + } + + @Test + public void getAvailableChildRolesWithZeroRoleIdTest() throws Exception { + String loginId = "123"; + Long roleId = 0L; + String response ="[ { \"active\" : true, \"name\" : \"xyz\" } ]"; + Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response); + List<Role> roles = roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId); + Assert.assertNotNull(roles); + } + + @Test + public void getAvailableChildRolesTest() throws Exception { + String loginId = "123"; + Long roleId = 123L; + String response ="[ { \"active\" : false, \"name\" : \"xyz\" } ]"; + Mockito.when(restApiRequestBuilder.getViaREST("/roles", true, loginId)).thenReturn(response); + String roleResponse =" { \"active\" : true, \"name\" : \"xyz\", \"roleFunctions\" : [ { \"code\" : \"abc\", \"name\" : \"RF1\" }, { \"code\" : \"pqr\", \"name\" : \"RF2\" } ] , \"parentRoles\": [ {\"active\" : false, \"name\" : \"XYZ-ABC\"}, {\"active\" : true, \"name\" : \"ABC\"} ] } "; + Mockito.when(restApiRequestBuilder.getViaREST("/role/" + roleId, true, loginId)).thenReturn(roleResponse); + roleServiceCntrlAccess.getAvailableChildRoles(loginId, roleId); + Assert.assertTrue(true); + } + + @Test + public void saveRoleTest() throws Exception { + Role role = new Role(); + role.setName("Role"); + roleServiceCntrlAccess.saveRole("123", role); + Assert.assertTrue(true); + } + + @Test + public void deleteRoleTest() throws Exception { + Role role = new Role(); + role.setName("Role"); + role.setId(123l); + roleServiceCntrlAccess.deleteRole("123", role); + Assert.assertTrue(true); + } + + @Test + public void getActiveRolesTest() throws Exception { + String requestedLoginId ="1234"; + String response ="[ { \"active\" : true, \"name\" : \"role1\" }, { \"active\" : false, \"name\" : \"role2\" } ]"; + Mockito.when(restApiRequestBuilder.getViaREST("/activeRoles", true, requestedLoginId)).thenReturn(response); + List<Role> roles = roleServiceCntrlAccess.getActiveRoles(requestedLoginId); + Assert.assertNotNull(roles); + } + + @Test + public void getRoleFunctionTest() throws IOException { + String requestedLoginId = "xyz"; + String code ="abc"; + + String responseString = " { \"code\" : \"abc\", \"name\" : \"xyz\" }"; + Mockito.when(restApiRequestBuilder.getViaREST("/function/" + code, true, requestedLoginId)).thenReturn(responseString); + RoleFunction roleFunction = roleServiceCntrlAccess.getRoleFunction(requestedLoginId, code); + Assert.assertNotNull(roleFunction); + } + + @Test + public void saveRoleFunctionTest() throws IOException { + String requestedLoginId ="123"; + RoleFunction domainRoleFunction = new RoleFunction(); + domainRoleFunction.setId(1234L); + roleServiceCntrlAccess.saveRoleFunction(requestedLoginId, domainRoleFunction); + Assert.assertTrue(true); + } + + @Test + public void deleteRoleFunctionTest() throws IOException { + String requestedLoginId ="123"; + RoleFunction domainRoleFunction = new RoleFunction(); + domainRoleFunction.setId(1234L); + roleServiceCntrlAccess.deleteRoleFunction(requestedLoginId, domainRoleFunction); + Assert.assertTrue(true); + } + + @Test + public void deleteDependcyRoleRecord() throws IOException { + String requestedLoginId = "123"; + Long id = 123L; + roleServiceCntrlAccess.deleteDependcyRoleRecord(requestedLoginId, id); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceImplTest.java new file mode 100644 index 00000000..3186b464 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/RoleServiceImplTest.java @@ -0,0 +1,256 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.sql.Connection; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import javax.sql.DataSource; + +import org.junit.Assert; +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.domain.Role; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class RoleServiceImplTest { + + @InjectMocks + private RoleServiceImpl roleServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private DataSource dataSource; + + @Test + public void getRoleFunctions() throws Exception { + String loginId = "123"; + roleServiceImpl.getRoleFunctions(loginId); + Assert.assertTrue(true); + } + + @Test + public void getAvailableChildRolesWithEmptyIdTest() throws Exception { + String loginId = "123"; + Long roleId = null; + Role child1 = new Role(); + child1.setName("Child1"); + + Role child2 = new Role(); + child1.setName("Child2"); + List<Role> childRoles = new ArrayList<>(); + childRoles.add(child1); + childRoles.add(child2); + Mockito.when(dataAccessService.getList(Role.class, null)).thenReturn(childRoles); + List<Role> list = roleServiceImpl.getAvailableChildRoles(loginId, roleId); + Assert.assertNotNull(list); + } + + @Test + public void getAvailableChildRolesWithZeroIdTest() throws Exception { + String loginId = "123"; + Long roleId = 0L; + Role child1 = new Role(); + child1.setName("Child1"); + + Role child2 = new Role(); + child1.setName("Child2"); + List<Role> childRoles = new ArrayList<>(); + childRoles.add(child1); + childRoles.add(child2); + Mockito.when(dataAccessService.getList(Role.class, null)).thenReturn(childRoles); + List<Role> list = roleServiceImpl.getAvailableChildRoles(loginId, roleId); + Assert.assertNotNull(list); + } + + @Test + public void getAvailableChildRolesTest() throws Exception { + String loginId = "123"; + Long roleId = 123L; + Role child1 = new Role(); + child1.setName("Child1"); + + Role child2 = new Role(); + child2.setName("Child2"); + + List<Role> childRoles = new ArrayList<>(); + childRoles.add(child1); + childRoles.add(child2); + Mockito.when(dataAccessService.getList(Role.class, null)).thenReturn(childRoles); + + Role parentRole = new Role(); + parentRole.setName("Parent"); + Set parentRoles = new TreeSet(); + parentRoles.add(parentRole); + + Role currentRole = new Role(); + currentRole.setName("Present Role"); + currentRole.setParentRoles(parentRoles); + Mockito.when(dataAccessService.getDomainObject(Role.class, roleId, null)).thenReturn(currentRole); + roleServiceImpl.getAvailableChildRoles(loginId, roleId); + Assert.assertTrue(true); + } + + @Test + public void getRoleFunctionTest() { + String code = "abc"; + String loginId ="123"; + Mockito.when(dataAccessService.getDomainObject(RoleFunction.class, code, null)).thenReturn(new RoleFunction()); + RoleFunction roleFunction = roleServiceImpl.getRoleFunction(loginId, code); + Assert.assertNotNull(roleFunction); + } + + @Test + public void saveRoleFunctionTest() { + String loginId = "123"; + RoleFunction domainRoleFunction = new RoleFunction(); + roleServiceImpl.saveRoleFunction(loginId, domainRoleFunction); + Assert.assertTrue(true); + } + + @Test + public void deleteRoleFunctionTest() { + String loginId = "123"; + RoleFunction domainRoleFunction = new RoleFunction(); + roleServiceImpl.deleteRoleFunction(loginId, domainRoleFunction); + Assert.assertTrue(true); + } + + @Test + public void getRoleTest() { + String loginId = "123"; + Long id = 123L; + Mockito.when(dataAccessService.getDomainObject(Role.class, id, null)).thenReturn(new Role()); + Role role = roleServiceImpl.getRole(loginId, id); + Assert.assertNotNull(role); + } + + @Test + public void saveRoleTest() { + String loginId = "123"; + Role domainRole = new Role(); + domainRole.setName("Test Role"); + roleServiceImpl.saveRole(loginId, domainRole); + Assert.assertTrue(true); + } + + @Test + public void deleteRoleTest() { + String loginId = "123"; + Role domainRole = new Role(); + domainRole.setName("Test Role"); + roleServiceImpl.deleteRole(loginId, domainRole); + Assert.assertTrue(true); + } + + + @Test + public void getAvailableRolesTest() { + + String loginId = "123"; + Role child1 = new Role(); + child1.setName("Child1"); + + Role child2 = new Role(); + child2.setName("Child2"); + + List<Role> childRoles = new ArrayList<>(); + childRoles.add(child1); + childRoles.add(child2); + Mockito.when(dataAccessService.getList(Role.class, null)).thenReturn(childRoles); + List<Role> list = roleServiceImpl.getAvailableRoles(loginId); + Assert.assertNotNull(list); + } + + @Test + public void getActiveRolesTest() { + + String loginId = "123"; + Long roleId = 123L; + Role child1 = new Role(); + child1.setName("Child1"); + + Role child2 = new Role(); + child2.setName("Child2"); + + List<Role> childRoles = new ArrayList<>(); + childRoles.add(child1); + childRoles.add(child2); + + String filter = " where active_yn = 'Y' "; + Mockito.when(dataAccessService.getList(Role.class, filter, null, null)).thenReturn(childRoles); + List<Role> list = roleServiceImpl.getActiveRoles(loginId); + Assert.assertNotNull(list); + } + + @Test + public void deleteDependcyRoleRecordTest() throws Exception { + Connection conn = Mockito.mock(Connection.class); + Statement stmt = Mockito.mock(Statement.class); + String loginId= "123"; + Long id = 123L; + + Mockito.when(dataSource.getConnection()).thenReturn(conn); + Mockito.when(conn.createStatement()).thenReturn(stmt); + roleServiceImpl.deleteDependcyRoleRecord(loginId, id); + Assert.assertTrue(true); + } + + @Test + public void deleteDependcyRoleRecordExcepTest() throws Exception { + Connection conn = Mockito.mock(Connection.class); + String loginId= "123"; + Long id = 123L; + + Mockito.when(dataSource.getConnection()).thenReturn(conn); + roleServiceImpl.deleteDependcyRoleRecord(loginId, id); + Assert.assertTrue(true); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UrlAccessImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UrlAccessImplTest.java new file mode 100644 index 00000000..f3cd7bbe --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UrlAccessImplTest.java @@ -0,0 +1,97 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.criterion.Criterion; +import org.hibernate.criterion.Restrictions; +import org.junit.Assert; +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.domain.UrlsAccessible; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.mock.web.MockHttpServletRequest; + +@RunWith(PowerMockRunner.class) +public class UrlAccessImplTest { + + @InjectMocks + private UrlAccessImpl urlAccessImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void isUrlAccessibleWithF1eTest() { + MockHttpServletRequest request = new MockHttpServletRequest(); + String currentUrl ="TestURL/content"; + boolean isAccessible = urlAccessImpl.isUrlAccessible(request, currentUrl); + Assert.assertTrue(isAccessible); + } + + @Test + public void isUrlAccessibleWithF2Test() { + MockHttpServletRequest request = new MockHttpServletRequest(); + request.addParameter("message_id", "5"); + request.addParameter("message_location_id", "123"); + String currentUrl ="TestURL*/content*"; + + UrlsAccessible url1= new UrlsAccessible(); + url1.setFunctionCd("F1"); + url1.setUrl("*/contentData"); + + UrlsAccessible url2= new UrlsAccessible(); + url2.setFunctionCd("F2"); + url2.setUrl("*/contentValue"); + + List list = new ArrayList<>(); + list.add(url1); + list.add(url2); + + Mockito.when(dataAccessService.getList(Mockito.any(), Mockito.any(), Mockito.anyList(), Mockito.any())).thenReturn(list); + + boolean isAccessible = urlAccessImpl.isUrlAccessible(request, currentUrl); + Assert.assertFalse(isAccessible); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java new file mode 100644 index 00000000..f7bb3108 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java @@ -0,0 +1,91 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.Assert; +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.domain.User; +import org.onap.portalsdk.core.domain.support.CollaborateList; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +public class UserProfileServiceImplTest { + + @InjectMocks + private UserProfileServiceImpl userProfileServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void findAllTest() { + userProfileServiceImpl.findAll(); + Assert.assertTrue(true); + } + + + + @Test + public void saveUserTest(){ + userProfileServiceImpl.saveUser(new User()); + Assert.assertTrue(true); + } + + /*@Test + public void findAllUserWithOnOfflineTest() throws Exception { + String originOrgUserId = "123"; + + Set<String> onlineUsers = new HashSet<>(); + onlineUsers.add("123"); + + CollaborateList mockClass = Mockito.mock(CollaborateList.class); + Mockito.when(CollaborateList.getInstance()).thenReturn(mockClass); + Mockito.when(mockClass.getAllUserName()).thenReturn(onlineUsers); + userProfileServiceImpl.findAllUserWithOnOffline(originOrgUserId); + }*/ +} |