diff options
author | st782s <statta@research.att.com> | 2018-02-20 12:00:10 -0500 |
---|---|---|
committer | st782s <statta@research.att.com> | 2018-02-20 12:00:10 -0500 |
commit | 724ff8f8b22d6503ce5070ebc13f6f5fbc48c8cf (patch) | |
tree | 063414ae8d035fe9957cba3833661a915c1f8eff /ecomp-sdk/epsdk-core | |
parent | 20602aa99841048e65a36dc26d8bfc4d6a11fcc9 (diff) |
Increase JUNIT Coverage
Issue-ID: PORTAL-136
Change-Id: I2223003924f36043753bef401ed1d8ee87f4a65e
Signed-off-by: st782s <statta@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core')
39 files changed, 3905 insertions, 5 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandler.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandler.java index 71357f34..532bf706 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandler.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandler.java @@ -34,7 +34,7 @@ * ============LICENSE_END============================================ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ +*/ package org.onap.portalsdk.core.objectcache.jcs; import org.apache.jcs.engine.control.event.behavior.IElementEvent; diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/command/PostSearchBeanTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/command/PostSearchBeanTest.java index b5bc3477..905f1b93 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/command/PostSearchBeanTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/command/PostSearchBeanTest.java @@ -37,12 +37,16 @@ */ package org.onap.portalsdk.core.command; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import org.junit.Test; +import junit.framework.Assert; + public class PostSearchBeanTest { + PostSearchBean postSearchBean= new PostSearchBean(); public PostSearchBean mockPostSearchBean() { @@ -92,6 +96,24 @@ public class PostSearchBeanTest { postSearchBean.setEmailOrig("testEmailOrig"); postSearchBean.setOrgManagerUserIdOrig("testOrgManagerUserIdOrig"); + postSearchBean.setSortBy1(null); + postSearchBean.setSortBy2(null); + postSearchBean.setSortBy3(null); + postSearchBean.setSortBy1Orig(null); + postSearchBean.setSortBy2Orig(null); + postSearchBean.setSortBy3Orig(null); + postSearchBean.setAccessType(null); + postSearchBean.setSubmitAction(null); + postSearchBean.setMasterId(null); + postSearchBean.setDetailId(null); + postSearchBean.setShowResult(null); + postSearchBean.setSearchResult(null); + postSearchBean.setSortByModifier1(null); + postSearchBean.setSortByModifier1Orig(null); + postSearchBean.setSortByModifier2(null); + postSearchBean.setSortByModifier2Orig(null); + postSearchBean.setSortByModifier3(null); + postSearchBean.setSortByModifier3Orig(null); return postSearchBean; } @@ -145,6 +167,26 @@ public class PostSearchBeanTest { postSearchBean.setOrgCodeOrig("testOrgCodeOrig"); postSearchBean.setEmailOrig("testEmailOrig"); postSearchBean.setOrgManagerUserIdOrig("testOrgManagerUserIdOrig"); + + postSearchBean.setSortBy1(null); + postSearchBean.setSortBy2(null); + postSearchBean.setSortBy3(null); + postSearchBean.setSortBy1Orig(null); + postSearchBean.setSortBy2Orig(null); + postSearchBean.setSortBy3Orig(null); + postSearchBean.setAccessType(null); + postSearchBean.setSubmitAction(null); + postSearchBean.setMasterId(null); + postSearchBean.setDetailId(null); + postSearchBean.setShowResult(null); + postSearchBean.setSearchResult(null); + postSearchBean.setSortByModifier1(null); + postSearchBean.setSortByModifier1Orig(null); + postSearchBean.setSortByModifier2(null); + postSearchBean.setSortByModifier2Orig(null); + postSearchBean.setSortByModifier3(null); + postSearchBean.setSortByModifier3Orig(null); + assertNull(postSearchBean.getUser().getCity()); assertNull(postSearchBean.getUserOrig().getCity()); assertEquals(postSearchBean.getSelected().length, mockPostSearchBean.getSelected().length); @@ -189,5 +231,58 @@ public class PostSearchBeanTest { assertEquals(postSearchBean.getEmailOrig(),mockPostSearchBean.getEmailOrig()); assertEquals(postSearchBean.getOrgManagerUserIdOrig(),mockPostSearchBean.getOrgManagerUserIdOrig()); + assertEquals(postSearchBean.getSortBy1(),mockPostSearchBean.getSortBy1()); + assertEquals(postSearchBean.getSortBy2(),mockPostSearchBean.getSortBy2()); + assertEquals(postSearchBean.getSortBy3(),mockPostSearchBean.getSortBy3()); + assertEquals(postSearchBean.getSortBy1Orig(),mockPostSearchBean.getSortBy1Orig()); + assertEquals(postSearchBean.getSortBy2Orig(),mockPostSearchBean.getSortBy2Orig()); + assertEquals(postSearchBean.getSortBy3Orig(),mockPostSearchBean.getSortBy3Orig()); + assertEquals(postSearchBean.getAccessType(),mockPostSearchBean.getAccessType()); + assertEquals(postSearchBean.getSubmitAction(),mockPostSearchBean.getSubmitAction()); + assertEquals(postSearchBean.getMasterId(),mockPostSearchBean.getMasterId()); + assertEquals(postSearchBean.getDetailId(),mockPostSearchBean.getDetailId()); + assertEquals(postSearchBean.getShowResult(),mockPostSearchBean.getShowResult()); + assertEquals(postSearchBean.getSearchResult(),mockPostSearchBean.getSearchResult()); + assertEquals(postSearchBean.getSortByModifier1(),mockPostSearchBean.getSortByModifier1()); + assertEquals(postSearchBean.getSortByModifier1Orig(),mockPostSearchBean.getSortByModifier1Orig()); + assertEquals(postSearchBean.getSortByModifier2(),mockPostSearchBean.getSortByModifier2()); + assertEquals(postSearchBean.getSortByModifier2Orig(),mockPostSearchBean.getSortByModifier2Orig()); + assertEquals(postSearchBean.getSortByModifier3(),mockPostSearchBean.getSortByModifier3()); + assertEquals(postSearchBean.getSortByModifier3Orig(),mockPostSearchBean.getSortByModifier3Orig()); + } + + @Test + public void getPageNoTest(){ + postSearchBean.setPageNo(1); + postSearchBean.getPageNo(); + } + + @Test + public void getPageSizeTest(){ + postSearchBean.setPageSize(1); + postSearchBean.getPageSize(); + } + + @Test + public void getDataSizeTest(){ + postSearchBean.setDataSize(1); + postSearchBean.getDataSize(); + } + + @Test + public void getNewDataSizeTest(){ + postSearchBean.getNewDataSize(); } + + @SuppressWarnings("deprecation") + @Test + public void isSortingUpdatedTest(){ + Assert.assertEquals(false, postSearchBean.isSortingUpdated()); + } + + @Test + public void resetSearchTest(){ + postSearchBean.resetSearch(); + } + } diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedBaseControllerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedBaseControllerTest.java new file mode 100644 index 00000000..a8f0ba92 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedBaseControllerTest.java @@ -0,0 +1,81 @@ +/* + * ============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.controller; + +import org.junit.Assert; +import org.junit.Test; + +public class RestrictedBaseControllerTest { + + public RestrictedBaseController mockRestrictedBaseController() throws Exception{ + RestrictedBaseController restrictedBaseController = new RestrictedBaseController(); + + restrictedBaseController.setViewName("test"); + restrictedBaseController.setExceptionView("runtime_error_handler"); + restrictedBaseController.setDataAccessService(null); + restrictedBaseController.setMenu(null); + restrictedBaseController.setMenuBuilder(null); + + return restrictedBaseController; + } + + @Test + public void restrictedBaseControllerTest() throws Exception{ + RestrictedBaseController restrictedBaseController1 = mockRestrictedBaseController(); + + RestrictedBaseController restrictedBaseController = new RestrictedBaseController(); + restrictedBaseController.setViewName("test"); + restrictedBaseController.setExceptionView("runtime_error_handler"); + restrictedBaseController.setDataAccessService(null); + restrictedBaseController.setMenu(null); + restrictedBaseController.setMenuBuilder(null); + + Assert.assertEquals(restrictedBaseController1.getExceptionView(), restrictedBaseController.getExceptionView()); + Assert.assertEquals(restrictedBaseController1.getViewName(), restrictedBaseController.getViewName()); + Assert.assertEquals(restrictedBaseController1.getDataAccessService(), restrictedBaseController.getDataAccessService()); + Assert.assertEquals(restrictedBaseController1.getMenu(null), restrictedBaseController.getMenu(null)); + Assert.assertEquals(restrictedBaseController1.getMenuBuilder(), restrictedBaseController.getMenuBuilder()); + } + + @Test + public void isAccessibleTest(){ + RestrictedBaseController restrictedBaseController = new RestrictedBaseController(); + Assert.assertEquals(false, restrictedBaseController.isAccessible()); + Assert.assertEquals(false, restrictedBaseController.isRESTfulCall()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedRESTfulBaseControllerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedRESTfulBaseControllerTest.java new file mode 100644 index 00000000..4070a44a --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/RestrictedRESTfulBaseControllerTest.java @@ -0,0 +1,72 @@ +/* + * ============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.controller; + +import org.junit.Assert; +import org.junit.Test; + +public class RestrictedRESTfulBaseControllerTest { + + public RestrictedRESTfulBaseController mockRestrictedRESTfulBaseController(){ + RestrictedRESTfulBaseController restrictedRESTfulBaseController = new RestrictedRESTfulBaseController(); + + restrictedRESTfulBaseController.setViewName("test"); + restrictedRESTfulBaseController.setExceptionView("runtime_error_handler"); + + return restrictedRESTfulBaseController; + } + + @Test + public void RestrictedRESTfulBaseControllerTest(){ + RestrictedRESTfulBaseController restrictedRESTfulBaseController1 = mockRestrictedRESTfulBaseController(); + + RestrictedRESTfulBaseController restrictedRESTfulBaseController = new RestrictedRESTfulBaseController(); + restrictedRESTfulBaseController.setViewName("test"); + restrictedRESTfulBaseController.setExceptionView("runtime_error_handler"); + + Assert.assertEquals(restrictedRESTfulBaseController1.getExceptionView(), restrictedRESTfulBaseController.getExceptionView()); + Assert.assertEquals(restrictedRESTfulBaseController1.getViewName(), restrictedRESTfulBaseController.getViewName()); + } + + @Test + public void isAccessibleTest(){ + RestrictedRESTfulBaseController restrictedRESTfulBaseController = new RestrictedRESTfulBaseController(); + Assert.assertEquals(false, restrictedRESTfulBaseController.isAccessible()); + Assert.assertEquals(true, restrictedRESTfulBaseController.isRESTfulCall()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/UnRestrictedBaseControllerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/UnRestrictedBaseControllerTest.java new file mode 100644 index 00000000..9b291514 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/controller/UnRestrictedBaseControllerTest.java @@ -0,0 +1,68 @@ +/* + * ============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.controller; + +import org.junit.Assert; +import org.junit.Test; + +public class UnRestrictedBaseControllerTest { + + public UnRestrictedBaseController mockUnRestrictedBaseController(){ + UnRestrictedBaseController unRestrictedBaseController = new UnRestrictedBaseController(); + + unRestrictedBaseController.setViewName("test"); + return unRestrictedBaseController; + } + + @Test + public void unRestrictedBaseControllerTest(){ + UnRestrictedBaseController unRestrictedBaseController1 = mockUnRestrictedBaseController(); + + UnRestrictedBaseController unRestrictedBaseController = new UnRestrictedBaseController(); + unRestrictedBaseController.setViewName("test"); + + Assert.assertEquals(unRestrictedBaseController1.getViewName(), unRestrictedBaseController.getViewName()); + } + + @Test + public void isAccessibleTest(){ + UnRestrictedBaseController unRestrictedBaseController = new UnRestrictedBaseController(); + Assert.assertEquals(true, unRestrictedBaseController.isAccessible()); + Assert.assertEquals(false, unRestrictedBaseController.isRESTfulCall()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/ProfileDaoImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/ProfileDaoImplTest.java new file mode 100644 index 00000000..3de08cb4 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/ProfileDaoImplTest.java @@ -0,0 +1,90 @@ +/* + * ============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.dao; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +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.Profile; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ProfileDaoImplTest { + + @InjectMocks + private ProfileDaoImpl profileDaoImpl; + + @Mock + private SessionFactory sessionFactory; + + @Test + public void findAllTest() { + Session session = Mockito.mock(Session.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(session); + Criteria crit = Mockito.mock(Criteria.class); + Mockito.when(session.createCriteria(Profile.class)).thenReturn(crit); + List<Profile> list = new ArrayList<>(); + Profile profile = new Profile(); + list.add(profile); + Mockito.when(crit.list()).thenReturn(list); + List<Profile> returnList = profileDaoImpl.findAll(); + Assert.assertTrue(returnList.size() > 0); + } + + @Test + public void getProfileTest() { + Session session = Mockito.mock(Session.class); + Mockito.when(sessionFactory.getCurrentSession()).thenReturn(session); + Criteria crit = Mockito.mock(Criteria.class); + Mockito.when(session.createCriteria(Profile.class)).thenReturn(crit); + Mockito.when(crit.uniqueResult()).thenReturn(new Profile()); + Profile profile = profileDaoImpl.getProfile(123); + Assert.assertNotNull(profile); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/support/FusionDaoTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/support/FusionDaoTest.java new file mode 100644 index 00000000..4bae6af5 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/dao/support/FusionDaoTest.java @@ -0,0 +1,63 @@ +/* + * ============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.dao.support; + +import org.junit.Test; + +import junit.framework.Assert; + +public class FusionDaoTest { + + public FusionDao mockFusionDao(){ + FusionDao fusionDao = new FusionDao(); + + fusionDao.setSessionFactory(null); + return fusionDao; + } + + @SuppressWarnings("deprecation") + @Test + public void fusionDaoTest(){ + FusionDao fusionDao = mockFusionDao(); + + FusionDao fusionDao1 = new FusionDao(); + fusionDao.setSessionFactory(null); + + Assert.assertEquals(fusionDao1.getSessionFactory(), fusionDao1.getSessionFactory());; + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/drools/DroolsRuleServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/drools/DroolsRuleServiceImplTest.java new file mode 100644 index 00000000..1ab907c5 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/drools/DroolsRuleServiceImplTest.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.drools; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import junit.framework.Assert; + +public class DroolsRuleServiceImplTest { + + public DroolsRuleServiceImpl mockDroolsRuleServiceImpl(){ + DroolsRuleServiceImpl droolsRuleServiceImpl = new DroolsRuleServiceImpl(); + + droolsRuleServiceImpl.setResultsString("test"); + + return droolsRuleServiceImpl; + } + + @SuppressWarnings("deprecation") + @Test + public void droolsRuleServiceImplTest(){ + DroolsRuleServiceImpl droolsRuleServiceImpl1 = mockDroolsRuleServiceImpl(); + + DroolsRuleServiceImpl droolsRuleServiceImpl = new DroolsRuleServiceImpl(); + droolsRuleServiceImpl.setResultsString("test"); + + Assert.assertEquals(droolsRuleServiceImpl1.getResultsString(), droolsRuleServiceImpl.getResultsString()); + } + + @Test + public void getStateTest(){ + DroolsRuleServiceImpl droolsRuleServiceImpl = new DroolsRuleServiceImpl(); + assertNull(droolsRuleServiceImpl.getState()); + } + + @SuppressWarnings("deprecation") + @Test + public void accessLabelTest(){ + DroolsRuleServiceImpl droolsRuleServiceImpl = new DroolsRuleServiceImpl(); + Assert.assertEquals("Drools POC Test", droolsRuleServiceImpl.accessLabel()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/exception/FusionExceptionResolverTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/exception/FusionExceptionResolverTest.java new file mode 100644 index 00000000..03bb8448 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/exception/FusionExceptionResolverTest.java @@ -0,0 +1,75 @@ +/* + * ============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.exception; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.servlet.ModelAndView; + +@RunWith(PowerMockRunner.class) +public class FusionExceptionResolverTest { + + @InjectMocks + FusionExceptionResolver fusionExceptionResolver; + + Exception exception = new Exception(); + UrlAccessRestrictedException urlAccessRestrictedException = new UrlAccessRestrictedException(); + SessionExpiredException sessionExpiredException = new SessionExpiredException(); + + @Test + public void handleUrlAccessExceptionTest() throws Exception{ + ModelAndView expectedModelAndView = fusionExceptionResolver.handleUrlAccessException(urlAccessRestrictedException); + Assert.assertNotNull(expectedModelAndView); + } + + @Test + public void handleSessionExceptionTest() throws Exception{ + ModelAndView expectedModelAndView = fusionExceptionResolver.handleSessionException(new SessionExpiredException()); + Assert.assertNotNull(expectedModelAndView); + } + + @Test + public void handleAllExceptionTest() throws Exception{ + ModelAndView expectedModelAndView = fusionExceptionResolver.handleAllException(exception); + Assert.assertNotNull(expectedModelAndView); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/ResourceInterceptorTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/ResourceInterceptorTest.java new file mode 100644 index 00000000..ddd465cf --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/ResourceInterceptorTest.java @@ -0,0 +1,171 @@ +/* + * ============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.interceptor; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletResponse; + +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.controller.FusionBaseController; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.exception.UrlAccessRestrictedException; +import org.onap.portalsdk.core.objectcache.AbstractCacheManager; +import org.onap.portalsdk.core.service.DataAccessService; +import org.onap.portalsdk.core.service.LoginService; +import org.onap.portalsdk.core.service.UrlAccessService; +import org.onap.portalsdk.core.service.WebServiceCallService; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.method.HandlerMethod; + +@RunWith(PowerMockRunner.class) +public class ResourceInterceptorTest { + + @InjectMocks + private ResourceInterceptor resourceInterceptor; + + @Mock + private DataAccessService dataAccessService; + @Mock + private LoginService loginService; + @Mock + private WebServiceCallService webServiceCallService; + @Mock + private AbstractCacheManager cacheManager; + @Mock + private UrlAccessService urlAccessService; + + @Test + public void preHandleFalseTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(false); + Mockito.when(controller.isRESTfulCall()).thenReturn(true); + Mockito.when(webServiceCallService.verifyRESTCredential(Mockito.anyString(), Mockito.anyString(), + Mockito.anyString())).thenReturn(false); + + boolean status = resourceInterceptor.preHandle(request, response, handler); + Assert.assertFalse(status); + } + + @Test(expected = UrlAccessRestrictedException.class) + public void preHandleExceptionTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(false); + Mockito.when(controller.isRESTfulCall()).thenReturn(false); + Mockito.when(urlAccessService.isUrlAccessible(Mockito.any(), Mockito.anyString())).thenReturn(false); + resourceInterceptor.preHandle(request, response, handler); + } + + @Test + public void preHandleTrueTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + App app = new App(); + app.setUsername("USER"); + Mockito.when(cacheManager.getObject("APP.METADATA")).thenReturn(app); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(true); + boolean status = resourceInterceptor.preHandle(request, response, handler); + Assert.assertTrue(status); + } + + @Test + public void preHandleTrueWithoutAppTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + App app = new App(); + app.setUsername("USER"); + + List list = new ArrayList<>(); + list.add(app); + StringBuilder criteria = new StringBuilder(); + criteria.append(" where id = 1"); + Mockito.when(dataAccessService.getList(App.class, criteria.toString(), null, null)).thenReturn(list); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(true); + boolean status = resourceInterceptor.preHandle(request, response, handler); + Assert.assertTrue(status); + } + + @Test + public void findAppTest() { + List list = new ArrayList<>(); + App app = new App(); + list.add(app); + StringBuilder criteria = new StringBuilder(); + criteria.append(" where id = 1"); + Mockito.when(dataAccessService.getList(App.class, criteria.toString(), null, null)).thenReturn(list); + App returnApp = resourceInterceptor.findApp(); + Assert.assertNotNull(returnApp); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/SessionTimeoutInterceptorTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/SessionTimeoutInterceptorTest.java new file mode 100644 index 00000000..d92f10bb --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/interceptor/SessionTimeoutInterceptorTest.java @@ -0,0 +1,147 @@ +/* + * ============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.interceptor; + +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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.controller.FusionBaseController; +import org.onap.portalsdk.core.domain.User; +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; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.web.method.HandlerMethod; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ AppUtils.class, UserUtils.class, SystemProperties.class }) +public class SessionTimeoutInterceptorTest { + + @InjectMocks + private SessionTimeoutInterceptor sessionTimeoutInterceptor; + + @Test + public void preHandleTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(false); + Mockito.when(controller.isRESTfulCall()).thenReturn(false); + + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + HttpSession session = PowerMockito.mock(HttpSession.class); + Mockito.when(AppUtils.getSession(request)).thenReturn(session); + Mockito.when(UserUtils.getUserSession(request)).thenReturn(new User()); + + boolean status = sessionTimeoutInterceptor.preHandle(request, response, handler); + Assert.assertTrue(status); + } + + @Test + public void preHandleSecurityExceptionTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource/logout.htm"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(false); + Mockito.when(controller.isRESTfulCall()).thenReturn(false); + + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + HttpSession session = PowerMockito.mock(HttpSession.class); + Mockito.when(AppUtils.getSession(request)).thenReturn(session); + Mockito.when(UserUtils.getUserSession(request)).thenReturn(new User()); + + boolean status = sessionTimeoutInterceptor.preHandle(request, response, handler); + Assert.assertFalse(status); + } + + @Test + public void preHandleExceptionTest() throws Exception { + MockHttpServletRequest request = new MockHttpServletRequest(); + HttpServletResponse response = new MockHttpServletResponse(); + + request.setRequestURI("xyz/resource"); + HandlerMethod handler = PowerMockito.mock(HandlerMethod.class); + FusionBaseController controller = PowerMockito.mock(FusionBaseController.class); + + Mockito.when(handler.getBean()).thenReturn(controller); + Mockito.when(controller.isAccessible()).thenReturn(false); + Mockito.when(controller.isRESTfulCall()).thenReturn(false); + + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + HttpSession session = PowerMockito.mock(HttpSession.class); + Mockito.when(AppUtils.getSession(request)).thenReturn(session); + Mockito.when(UserUtils.getUserSession(request)).thenReturn(null); + + boolean status = sessionTimeoutInterceptor.preHandle(request, response, handler); + Assert.assertFalse(status); + } + + @Test(expected = SecurityException.class) + public void validateDomainTest() throws Exception { + String relativePath = "testUrl"; + String redirectUrl = "http://www.xyz.com/" + relativePath; + + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.COOKIE_DOMAIN)).thenReturn(relativePath); + + sessionTimeoutInterceptor.validateDomain(redirectUrl); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/CollaborateListBindingListenerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/CollaborateListBindingListenerTest.java new file mode 100644 index 00000000..3e0d045f --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/CollaborateListBindingListenerTest.java @@ -0,0 +1,74 @@ +/* + * ============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.listener; + +import javax.servlet.http.HttpSessionBindingEvent; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class CollaborateListBindingListenerTest { + + @InjectMocks + private CollaborateListBindingListener collabBindingListener; + + @Test + public void valueBoundTest() { + HttpSessionBindingEvent event = Mockito.mock(HttpSessionBindingEvent.class); + CollaborateListBindingListener mock = new CollaborateListBindingListener("Test"); + mock.setUserName("Test"); + Mockito.when(event.getValue()).thenReturn(mock); + collabBindingListener.valueBound(event); + Assert.assertTrue(true); + } + + @Test + public void valueUnboundTest() { + HttpSessionBindingEvent event = Mockito.mock(HttpSessionBindingEvent.class); + CollaborateListBindingListener mock = new CollaborateListBindingListener("Test"); + mock.setUserName("Test"); + Mockito.when(event.getValue()).thenReturn(mock); + collabBindingListener.valueUnbound(event); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/UserSessionListenerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/UserSessionListenerTest.java new file mode 100644 index 00000000..e8d93b6f --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/listener/UserSessionListenerTest.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.listener; + +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +public class UserSessionListenerTest { + + @InjectMocks + private UserSessionListener userSessionListener; + + @Test + public void sessionCreatedTest() { + HttpSessionEvent event = Mockito.mock(HttpSessionEvent.class); + userSessionListener.sessionCreated(event); + Assert.assertTrue(true); + } + + @Test + public void sessionDestroyedTest() { + HttpSessionEvent event = Mockito.mock(HttpSessionEvent.class); + HttpSession sesion = Mockito.mock(HttpSession.class); + Mockito.when(event.getSession()).thenReturn(sesion); + userSessionListener.sessionDestroyed(event); + Assert.assertTrue(true); + } + + @Test + public void sessionDestroyedExceptionTest() { + HttpSessionEvent event = Mockito.mock(HttpSessionEvent.class); + userSessionListener.sessionDestroyed(event); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdviceTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdviceTest.java new file mode 100644 index 00000000..324910e4 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdviceTest.java @@ -0,0 +1,92 @@ +/* + * ============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.logging.aspect; + +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.service.AppService; +import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class EELFLoggerAdviceTest { + + @InjectMocks + private EELFLoggerAdvice eelFLoggerAdvice; + + @Mock + private AppService appService; + + @Test + public void getCurrentDateTimeUTCTest(){ + String timeAsString = eelFLoggerAdvice.getCurrentDateTimeUTC(); + Assert.assertNotNull(timeAsString); + } + + @Test + public void beforeTest() { + SecurityEventTypeEnum securityEventType = SecurityEventTypeEnum.INCOMING_REST_MESSAGE; + Object[] args = new Object[2]; + Object[] passOnArgs = new Object[2]; + HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class); + passOnArgs[0] = "ClassName"; + passOnArgs[1] = "MethodName"; + args[0] = mockReq; + eelFLoggerAdvice.before(securityEventType, args, passOnArgs); + Assert.assertTrue(true); + } + + @Test + public void afterTest() { + SecurityEventTypeEnum securityEventType = SecurityEventTypeEnum.INCOMING_REST_MESSAGE; + Object[] args = new Object[2]; + Object[] passOnArgs = new Object[2]; + HttpServletRequest mockReq = Mockito.mock(HttpServletRequest.class); + passOnArgs[0] = "ClassName"; + passOnArgs[1] = "MethodName"; + args[0] = mockReq; + eelFLoggerAdvice.after(securityEventType, "Result", args, null, passOnArgs); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java new file mode 100644 index 00000000..ea0b42fb --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspectTest.java @@ -0,0 +1,162 @@ +/* + * ============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.logging.aspect; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.annotation.Around; +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.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class EELFLoggerAspectTest { + + @InjectMocks + private EELFLoggerAspect eelFLoggerAspect; + + @Mock + private EELFLoggerAdvice advice; + + @Test + public void incomingAuditMessagesTest() { + eelFLoggerAspect.incomingAuditMessages(); + Assert.assertTrue(true); + } + + @Test + public void logAuditMethodAroundTest() throws Throwable { + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + AuditLog mockLog = Mockito.mock(AuditLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.logAuditMethodAround(joinPoint, mockLog); + Assert.assertTrue(true); + } + + @Test + public void logAuditMethodClassAroundTest() throws Throwable { + + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + AuditLog mockLog = Mockito.mock(AuditLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.logAuditMethodClassAround(joinPoint, mockLog); + Assert.assertTrue(true); + } + + @Test + public void publicMethodTst(){ + eelFLoggerAspect.publicMethod(); + Assert.assertTrue(true); + } + + @Test + public void logMetricsClassAroundTest() throws Throwable { + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + MetricsLog mockLog = Mockito.mock(MetricsLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.logMetricsClassAround(joinPoint, mockLog); + Assert.assertTrue(true); + } + + @Test + public void logMetricsMethodAroundTest() throws Throwable { + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + MetricsLog mockLog = Mockito.mock(MetricsLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.logMetricsMethodAround(joinPoint, mockLog); + Assert.assertTrue(true); + } + + @Test + public void performMetricsLoggingTest() { + eelFLoggerAspect.performMetricsLogging(); + Assert.assertTrue(true); + } + + @Test + public void metricsLoggingAroundClassTest() throws Throwable { + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + MetricsLog mockLog = Mockito.mock(MetricsLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.metricsLoggingAroundClass(joinPoint, mockLog); + Assert.assertTrue(true); + } + + @Test + public void metricsLoggingAroundMethodTest() throws Throwable { + ProceedingJoinPoint joinPoint = Mockito.mock(ProceedingJoinPoint.class); + MetricsLog mockLog = Mockito.mock(MetricsLog.class); + Signature sign = Mockito.mock(Signature.class); + + Mockito.when(joinPoint.getSignature()).thenReturn(sign); + Mockito.when(sign.getDeclaringType()).thenReturn(getClass()); + Mockito.when(sign.getName()).thenReturn("MethodName"); + + eelFLoggerAspect.metricsLoggingAroundMethod(joinPoint, mockLog); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java new file mode 100644 index 00000000..cf0b5124 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/logging/logic/EELFLoggerDelegateTest.java @@ -0,0 +1,320 @@ +/* + * ============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.logging.logic; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.onap.portalsdk.core.logging.format.AppMessagesEnum; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.slf4j.MDC; + +import com.att.eelf.configuration.EELFLogger; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({UserUtils.class}) +public class EELFLoggerDelegateTest { + + @Test + public void getLoogerTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + EELFLoggerDelegate logger = eelFLoggerDelegate.getLogger(""); + logger = eelFLoggerDelegate.getLogger(getClass()); + Assert.assertNotNull(logger); + } + + @Test + public void traceTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isTraceEnabled()).thenReturn(true); + String msg = "test"; + eelFLoggerDelegate.trace(logger, msg); + Assert.assertTrue(true); + } + + @Test + public void traceArgsTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isTraceEnabled()).thenReturn(true); + String msg = "test"; + Object[] args = new Object[2]; + eelFLoggerDelegate.trace(logger, msg, args); + Assert.assertTrue(true); + } + + @Test + public void traceExceptionTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isTraceEnabled()).thenReturn(true); + String msg = "test"; + eelFLoggerDelegate.trace(logger, msg, new Exception()); + Assert.assertTrue(true); + } + + @Test + public void debugTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isDebugEnabled()).thenReturn(true); + String msg = "test"; + eelFLoggerDelegate.debug(logger, msg); + Assert.assertTrue(true); + } + + @Test + public void debugArgsTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isDebugEnabled()).thenReturn(true); + String msg = "test"; + Object[] args = new Object[2]; + eelFLoggerDelegate.debug(logger, msg, args); + Assert.assertTrue(true); + } + + @Test + public void debugExceptionTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + Mockito.when(logger.isDebugEnabled()).thenReturn(true); + String msg = "test"; + eelFLoggerDelegate.debug(logger, msg, new Exception()); + Assert.assertTrue(true); + } + + @Test + public void infoTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.info(logger, msg); + Assert.assertTrue(true); + } + + @Test + public void infoArgsTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + Object[] args = new Object[2]; + eelFLoggerDelegate.info(logger, msg, args); + Assert.assertTrue(true); + } + + @Test + public void infoExceptionTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.info(logger, msg, new Exception()); + Assert.assertTrue(true); + } + + @Test + public void warnTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.warn(logger, msg); + Assert.assertTrue(true); + } + + @Test + public void warnArgsTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + Object[] args = new Object[2]; + eelFLoggerDelegate.warn(logger, msg, args); + Assert.assertTrue(true); + } + + @Test + public void warnExceptionTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.warn(logger, msg, new Exception()); + Assert.assertTrue(true); + } + + @Test + public void errorTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.error(logger, msg); + Assert.assertTrue(true); + } + + @Test + public void errorArgsTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + Object[] args = new Object[2]; + eelFLoggerDelegate.error(logger, msg, args); + Assert.assertTrue(true); + } + + @Test + public void errorExceptionTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.error(logger, msg, new Exception()); + Assert.assertTrue(true); + } + @Test + public void errorEnumTest() { + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + + EELFLogger logger = Mockito.mock(EELFLogger.class); + String msg = "test"; + eelFLoggerDelegate.error(logger, msg, AlarmSeverityEnum.MINOR); + Assert.assertTrue(true); + } + + @Test + public void initTest(){ + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + eelFLoggerDelegate.init(); + Assert.assertTrue(true); + } + + @Test + public void logEcompErrorTest() { + AppMessagesEnum epMessageEnum = AppMessagesEnum.BeDaoCloseSessionError; + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + String[] param= new String[2]; + eelFLoggerDelegate.logEcompError(epMessageEnum, param); + Assert.assertTrue(true); + } + + @Test + public void logEcompErrorInfoTest() { + AppMessagesEnum epMessageEnum = AppMessagesEnum.InternalUnexpectedInfo; + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + String[] param= new String[2]; + eelFLoggerDelegate.logEcompError(epMessageEnum, param); + Assert.assertTrue(true); + } + @Test + public void logEcompErrorWarnTest() { + AppMessagesEnum epMessageEnum = AppMessagesEnum.InternalUnexpectedWarning; + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + eelFLoggerDelegate.logEcompError(epMessageEnum, null); + Assert.assertTrue(true); + } + + @Test + public void logEcompErrorNullTest() { + AppMessagesEnum epMessageEnum = null; + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + String[] param= new String[2]; + eelFLoggerDelegate.logEcompError(epMessageEnum, param); + Assert.assertTrue(true); + } + + @Test + public void mdcPutTest() { + String key = "Key"; + String value = "Value"; + EELFLoggerDelegate.mdcPut(key, value); + Assert.assertTrue(true); + } + + @Test + public void mdcGetTest() { + String key = "Key"; + EELFLoggerDelegate.mdcGet(key); + Assert.assertTrue(true); + } + + @Test + public void mdcRemoveTest() { + String key = "Key"; + EELFLoggerDelegate.mdcRemove(key); + Assert.assertTrue(true); + MDC.remove(key); + } + + @Test + public void setRequestBasedDefaultsIntoGlobalLoggingContextTest() { + HttpServletRequest req = Mockito.mock(HttpServletRequest.class); + String appName = "Test App"; + Mockito.when(req.getHeader(SystemProperties.USERAGENT_NAME)).thenReturn("ChromeTest"); + + PowerMockito.mockStatic(UserUtils.class); + User user = new User(); + user.setLoginId("123"); + Mockito.when(UserUtils.getUserSession(req)).thenReturn(user); + Mockito.when(UserUtils.getRequestId(req)).thenReturn("https://xyb/resource"); + Mockito.when(UserUtils.getFullURL(req)).thenReturn("https://xyb/resource"); + EELFLoggerDelegate eelFLoggerDelegate = new EELFLoggerDelegate(getClass().getName()); + eelFLoggerDelegate.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuBuilderTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuBuilderTest.java new file mode 100644 index 00000000..d3789490 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuBuilderTest.java @@ -0,0 +1,173 @@ +/* + * ============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.menu; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +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.MenuData; +import org.onap.portalsdk.core.service.DataAccessService; +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 MenuBuilderTest { + + @InjectMocks + private MenuBuilder menuBuilder; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getMenuTest() { + String menuSetName = "Root Meunu"; + + MenuData menuData = new MenuData(); + Set childMenus = new TreeSet(); + menuData.setChildMenus(childMenus); + List menuItems = new ArrayList(); + menuItems.add(menuData); + Mockito.when(dataAccessService.executeNamedQuery(Mockito.anyString(), Mockito.anyMap(), Mockito.anyMap())) + .thenReturn(menuItems); + Set menu = menuBuilder.getMenu(menuSetName, dataAccessService); + Assert.assertNotNull(menu); + } + + @Test + public void getMenuWithDaoTest() { + String menuSetName = "Root Meunu"; + + MenuData menuData = new MenuData(); + Set childMenus = new TreeSet(); + menuData.setChildMenus(childMenus); + List menuItems = new ArrayList(); + menuItems.add(menuData); + Mockito.when(dataAccessService.executeNamedQuery(Mockito.anyString(), Mockito.anyMap(), Mockito.anyMap())) + .thenReturn(menuItems); + Set menu = menuBuilder.getMenu(menuSetName); + Assert.assertNotNull(menu); + } + + @Test + public void filterMenuTrueTest() { + MenuData menu = new MenuData(); + MenuData childMenu = new MenuData(); + Set childMenus = new TreeSet(); + childMenus.add(childMenu); + menu.setChildMenus(childMenus); + Set menus = new TreeSet(); + menus.add(menu); + + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.isAccessible(Mockito.any(), Mockito.any())).thenReturn(true); + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + menuBuilder.filterMenu(menus, request); + Assert.assertTrue(true); + } + + @Test + public void filterMenuFalseest() { + MenuData menu = new MenuData(); + MenuData childMenu = new MenuData(); + Set childMenus = new TreeSet(); + childMenus.add(childMenu); + menu.setChildMenus(childMenus); + Set menus = new TreeSet(); + menus.add(menu); + + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.isAccessible(Mockito.any(), Mockito.any())).thenReturn(false); + HttpServletRequest request = Mockito.mock(HttpServletRequest.class); + menuBuilder.filterMenu(menus, request); + Assert.assertTrue(true); + } + + @Test + public void getUrlHtmlExternalTest() { + MenuData menuData = new MenuData(); + menuData.setExternalUrl("External"); + String htmlString = menuBuilder.getUrlHtml(menuData); + Assert.assertTrue(true); + } + + @Test + public void getUrlHtmlServletTest() { + MenuData menuData = new MenuData(); + menuData.setServlet("Servlet"); + String htmlString = menuBuilder.getUrlHtml(menuData); + Assert.assertTrue(true); + } + + @Test + public void getUrlHtmlActionTest() { + MenuData menuData = new MenuData(); + menuData.setAction("Action"); + String htmlString = menuBuilder.getUrlHtml(menuData); + Assert.assertNotNull(htmlString); + } + + @Test + public void getTargetHtmlTest() { + MenuData menuData = new MenuData(); + menuData.setTarget("Sub system"); + String html = menuBuilder.getTargetHtml(menuData); + Assert.assertNotNull(html); + } + + @Test + public void getQueryStringHtmlTest() { + MenuData menuData = new MenuData(); + menuData.setQueryString("Sub system"); + String html = menuBuilder.getQueryStringHtml(menuData); + Assert.assertNotNull(html); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuPropertiesTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuPropertiesTest.java new file mode 100644 index 00000000..71857545 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/menu/MenuPropertiesTest.java @@ -0,0 +1,74 @@ +/* + * ============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.menu; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import javax.servlet.ServletContext; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class MenuPropertiesTest { + + @InjectMocks + private MenuProperties menuProperties; + + @Test + public void loadFromFile() throws Exception { + ServletContext servletContext = Mockito.mock(ServletContext.class); + String filename = ""; + String menuSetName =""; + String content = "key=value"; + InputStream is = new ByteArrayInputStream(content.getBytes()); + Mockito.when(servletContext.getResourceAsStream(Mockito.anyString())).thenReturn(is); + menuProperties.loadFromFile(servletContext, filename, menuSetName); + Assert.assertTrue(true); + String key ="key"; + menuProperties.getProperty(key); + Assert.assertTrue(true); + } + + +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandlerTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandlerTest.java new file mode 100644 index 00000000..830af118 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/objectcache/jcs/JCSCacheEventHandlerTest.java @@ -0,0 +1,120 @@ +/* + * ============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.objectcache.jcs; + +import org.apache.jcs.engine.control.event.behavior.IElementEvent; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class JCSCacheEventHandlerTest { + + @InjectMocks + private JCSCacheEventHandler jcsCacheEventHandler; + + @Test + public void handleElementEventBackgroundTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()) + .thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventMaxLifeTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()).thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_EXCEEDED_MAXLIFE_ONREQUEST); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventIdlyBackgroundTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()) + .thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventOnReqTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()) + .thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_EXCEEDED_IDLETIME_ONREQUEST); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventAvaliTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()).thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventNotAvaliTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()).thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventNotAllowedTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()).thenReturn(jcsCacheEventHandler.ELEMENT_EVENT_SPOOLED_NOT_ALLOWED); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } + + @Test + public void handleElementEventDefaultTest() { + IElementEvent event = Mockito.mock(IElementEvent.class); + Mockito.when(event.getElementEvent()).thenReturn(100); + jcsCacheEventHandler.handleElementEvent(event); + Assert.assertTrue(true); + } +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/HttpStatusAndResponseTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/HttpStatusAndResponseTest.java new file mode 100644 index 00000000..ecf2d255 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/HttpStatusAndResponseTest.java @@ -0,0 +1,62 @@ +/* + * ============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.restful.client; + +import org.junit.Test; + +import junit.framework.Assert; + +public class HttpStatusAndResponseTest { + + public HttpStatusAndResponse mockHttpStatusAndResponse(){ + HttpStatusAndResponse httpStatusAndResponse = new HttpStatusAndResponse(0, null); + + return httpStatusAndResponse; + } + + @SuppressWarnings("deprecation") + @Test + public void httpStatusAndResponseTest(){ + HttpStatusAndResponse httpStatusAndResponse1 = mockHttpStatusAndResponse(); + + HttpStatusAndResponse httpStatusAndResponse = new HttpStatusAndResponse(0, null); + + Assert.assertEquals(httpStatusAndResponse.getResponse(), httpStatusAndResponse1.getResponse()); + Assert.assertEquals(httpStatusAndResponse.getStatusCode(), httpStatusAndResponse1.getStatusCode()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/PortalRestClientBaseTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/PortalRestClientBaseTest.java new file mode 100644 index 00000000..056a1190 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/PortalRestClientBaseTest.java @@ -0,0 +1,209 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.restful.client; + +import java.net.URI; + +import org.apache.http.HttpEntity; +import org.apache.http.StatusLine; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +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.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.restful.client.PortalRestClientBase; +import org.onap.portalsdk.core.service.AppService; +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, CipherUtil.class, HttpClients.class}) +public class PortalRestClientBaseTest { + + @InjectMocks + private PortalRestClientBase portalRestClientBase; + + @Mock + private AppService appService; + + @Test(expected = IllegalArgumentException.class) + public void getRestWithCredentialsExceptionTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + portalRestClientBase.getRestWithCredentials(uri); + Assert.assertTrue(true); + } + + @Test + public void getRestWithCredentialsTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + + portalRestClientBase.getRestWithCredentials(uri); + Assert.assertTrue(true); + } + + @Test + public void getRestWithCredentialsEntityNullTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + + portalRestClientBase.getRestWithCredentials(uri); + Assert.assertTrue(true); + } + + @Test(expected = IllegalArgumentException.class) + public void postRestWithCredentialsExceptionTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + String json = ""; + portalRestClientBase.postRestWithCredentials(uri,json); + Assert.assertTrue(true); + } + + @Test + public void postRestWithCredentialsWithEntityTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + + String json = "JSON"; + portalRestClientBase.postRestWithCredentials(uri, json); + Assert.assertTrue(true); + } + + @Test + public void postRestWithCredentialsNullEntityTest() throws Exception { + URI uri = PowerMockito.mock(URI.class); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + + String json = "JSON"; + portalRestClientBase.postRestWithCredentials(uri, json); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/SharedContextRestClientTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/SharedContextRestClientTest.java new file mode 100644 index 00000000..db6cde7c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/restful/client/SharedContextRestClientTest.java @@ -0,0 +1,307 @@ +/* + * ============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.restful.client; + +import java.util.List; + +import org.apache.http.HttpEntity; +import org.apache.http.StatusLine; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +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.util.CipherUtil; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.restful.domain.SharedContext; +import org.onap.portalsdk.core.scheduler.CoreRegister; +import org.onap.portalsdk.core.service.AppService; +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, CipherUtil.class, HttpClients.class, EntityUtils.class}) +public class SharedContextRestClientTest { + + @InjectMocks + private SharedContextRestClient sharedContextRestClient; + + @Mock + private AppService appService; + + @Test(expected = IllegalArgumentException.class) + public void getContextValueExceptionTest() throws Exception { + String contextId= "\123"; + String key = "key"; + sharedContextRestClient.getContextValue(contextId, key); + } + + @Test + public void getContextValueTest() throws Exception { + String contextId= "\123"; + String key = "key"; + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + String responseJson = " { \"response\": \"Success\", \"context_id\": \"200\"}"; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + SharedContext context = sharedContextRestClient.getContextValue(contextId, key); + Assert.assertNull(context); + } + + @Test + public void getUserContextTest() throws Exception { + String contextId = "234"; + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + String responseJson = " [ { \"response\": \"Success\", \"context_id\": \"200\"} ]"; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + + List<SharedContext> contextList = sharedContextRestClient.getUserContext(contextId); + Assert.assertNotNull(contextList); + } + + @Test + public void checkSharedContextTest() throws Exception { + String contextId ="Context"; + String key = "Key"; + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + String responseJson = " { \"response\": \"exists\", \"context_id\": \"200\"} "; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + boolean status = sharedContextRestClient.checkSharedContext(contextId, key); + Assert.assertTrue(status); + } + + @Test + public void removeSharedContextTest() throws Exception { + String contextId ="Context"; + String key = "Key"; + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + String responseJson = " { \"response\": \"removed\", \"context_id\": \"200\"} "; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + boolean status = sharedContextRestClient.removeSharedContext(contextId, key); + Assert.assertTrue(status); + } + + @Test + public void clearSharedContextTest() throws Exception { + String contextId ="Context"; + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + int number = 123; + String responseJson = " { \"response\": " + number + " , \"context_id\": \"200\"} "; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + int status = sharedContextRestClient.clearSharedContext(contextId); + Assert.assertTrue(status == number); + } + + @Test + public void setSharedContextTest() throws Exception { + String contextId ="Context"; + String key ="Key"; + String value = "Value"; + + App app = new App(); + app.setUsername("User"); + String password = "Password"; + app.setAppPassword(password); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ECOMP_REST_URL)).thenReturn("ResetURL/"); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_APP_KEY)).thenReturn("Key"); + + PowerMockito.mockStatic(CipherUtil.class); + Mockito.when(CipherUtil.decryptPKC(app.getAppPassword())).thenReturn(password); + + CloseableHttpClient httpClient = PowerMockito.mock(CloseableHttpClient.class); + CloseableHttpResponse response = PowerMockito.mock(CloseableHttpResponse.class); + + PowerMockito.mockStatic(HttpClients.class); + Mockito.when(HttpClients.createDefault()).thenReturn(httpClient); + + Mockito.when(httpClient.execute(Mockito.any())).thenReturn(response); + HttpEntity entity = PowerMockito.mock(HttpEntity.class); + Mockito.when(response.getEntity()).thenReturn(entity); + + PowerMockito.mockStatic(EntityUtils.class); + String responseJson = " { \"response\": \"replaced\", \"context_id\": \"200\"} "; + Mockito.when(EntityUtils.toString(entity)).thenReturn(responseJson); + StatusLine statusLine = Mockito.mock(StatusLine.class); + Mockito.when(response.getStatusLine()).thenReturn(statusLine); + boolean status = sharedContextRestClient.setSharedContext(contextId, key, value); + Assert.assertTrue(status); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/scheduler/CoreRegisterTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/scheduler/CoreRegisterTest.java new file mode 100644 index 00000000..7959ae81 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/scheduler/CoreRegisterTest.java @@ -0,0 +1,52 @@ +/* + * ============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.scheduler; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CoreRegisterTest { + + @Test + public void getScheduleTriggersTest(){ + CoreRegister coreRegister = new CoreRegister(); + coreRegister.setScheduleTriggers(null); + assertNull(coreRegister.getScheduleTriggers()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java new file mode 100644 index 00000000..efdc3d0d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java @@ -0,0 +1,95 @@ +/* + * ============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; + +public class AccessConfigurationTest { + + AccessConfiguration accessConfiguration = new AccessConfiguration(); + + @Test + public void roleServiceImplTest(){ + accessConfiguration.roleServiceImpl(); + } + + @Test + public void roleServiceCentralizedAccessTest(){ + accessConfiguration.roleServiceCentralizedAccess(); + } + + @Test + public void loginServiceImplTest(){ + accessConfiguration.loginServiceImpl(); + } + + @Test + public void loginServiceCEntralizedImplTest(){ + accessConfiguration.loginServiceCEntralizedImpl(); + } + + @Test + public void userServiceImplTest(){ + accessConfiguration.userServiceImpl(); + } + + @Test + public void profileServiceImplTest(){ + accessConfiguration.profileServiceImpl(); + } + + @Test + public void profileServiceCentralizedImplTest(){ + accessConfiguration.profileServiceCentralizedImpl(); + } + + @Test + public void restApiRequestBuilderTest(){ + accessConfiguration.restApiRequestBuilder(); + } + + @Test + public void functionalMenuListServiceTest(){ + accessConfiguration.functionalMenuListService(); + } + + @Test + public void functionalMenuListServiceCentralizedImplTest(){ + accessConfiguration.functionalMenuListServiceCentralizedImpl(); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.java new file mode 100644 index 00000000..a328033b --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.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 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 CentralAccessConditionTest { + + @InjectMocks + private CentralAccessCondition cntrlAccessCondition; + + @Test + public void matchesFalseTest() { + 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(null); + boolean isRemote = cntrlAccessCondition.matches(context, metadata); + Assert.assertFalse(isRemote); + } + + @Test + public void matchesTrueTest() { + 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("remote"); + boolean isRemote = cntrlAccessCondition.matches(context, metadata); + Assert.assertTrue(isRemote); + } +} 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 index f7bb3108..565142d0 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -68,7 +68,15 @@ public class UserProfileServiceImplTest { Assert.assertTrue(true); } - + /*public void getUserByLoginId(){ + String loginId = "123"; + List<User> users = new ArrayList<>(); + User user = new User(); + users.add(user); + Mockito.when(dataAccessService.getList(Mockito.any(), Mockito.any(), Mockito.anyList(), Mockito.any())).thenReturn(users); + User retrunUser = userProfileServiceImpl.getUserByLoginId(loginId); + Assert.assertNotNull(retrunUser); + }*/ @Test public void saveUserTest(){ @@ -88,4 +96,4 @@ public class UserProfileServiceImplTest { Mockito.when(mockClass.getAllUserName()).thenReturn(onlineUsers); userProfileServiceImpl.findAllUserWithOnOffline(originOrgUserId); }*/ -} +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java new file mode 100644 index 00000000..82b4a6e0 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java @@ -0,0 +1,84 @@ +/* + * ============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.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.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class UserServiceCentalizedImplTest { + + @InjectMocks + private UserServiceCentalizedImpl userServiceCentalizedImpl; + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getUserTest() throws Exception { + String id = "123"; + + String orgUserId = "123"; + List<String> orgUsreIds = new ArrayList<>(); + orgUsreIds.add(orgUserId); + + Map<String, Long> params = new HashMap<>(); + params.put("user_id", new Long(id)); + Mockito.when(dataAccessService.executeNamedQuery("getUserByProfileId", params, null)).thenReturn(orgUsreIds); + String responseString = " { \"id\": 2, \"userApps\":[{\"app\":{\"id\":1},\"role\":{\"active\":true, \"roleFunctions\":[{\"id\":1}] } } ] }"; + Mockito.when(restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id)).thenReturn(responseString); + + User user = userServiceCentalizedImpl.getUser(id); + Assert.assertNotNull(user); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java new file mode 100644 index 00000000..0cb7ac6c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java @@ -0,0 +1,68 @@ +/* + * ============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.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class UserServiceImplTest { + + @InjectMocks + private UserServiceImpl userServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getUserTest() { + String id = "123"; + userServiceImpl.getUser(id); + Assert.assertTrue(true); + } + + @Test(expected = UnsupportedOperationException.class) + public void userMapperTest() { + String response = "Dummy Response"; + userServiceImpl.userMapper(response); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java new file mode 100644 index 00000000..03eeea77 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java @@ -0,0 +1,127 @@ +/* + * ============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.domain.App; +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({CipherUtil.class, SystemProperties.class}) +public class WebServiceCallServiceImplTest { + + @InjectMocks + private WebServiceCallServiceImpl webServiceCallServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private AppService appService; + + + @Test + public void verifyRESTCredentialTrueTest() throws Exception { + String secretKey = "Key"; + String requestAppName = "App"; + String requestPassword = "Password"; + App app = new App(); + app.setAppPassword(requestPassword); + app.setUsername(requestAppName); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn(requestPassword); + webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword); + Assert.assertTrue(true); + } + + @Test + public void verifyRESTCredentialFalseTest() throws Exception { + String secretKey = "Key"; + String requestAppName = "App"; + String requestPassword = "Password"; + App app = new App(); + app.setAppPassword("Password"); + app.setUsername("USER"); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn("Key"); + Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn("Key"); + webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword); + Assert.assertFalse(false); + } + + @Test + public void findAppWithNullTest() { + App app = webServiceCallServiceImpl.findApp(); + Assert.assertNull(app); + } + + @Test + public void findAppWithEmptyTest() { + Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(new ArrayList()); + App app = webServiceCallServiceImpl.findApp(); + Assert.assertNull(app); + } + + @Test + public void findAppTest() { + List list = new ArrayList(); + App app = new App(); + list.add(app); + Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(list); + App returnApp = webServiceCallServiceImpl.findApp(); + Assert.assertNotNull(returnApp); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.java new file mode 100644 index 00000000..53664c64 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.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.support; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ServiceLocatorImplTest { + + @InjectMocks + private ServiceLocatorImpl serviceLocatorImpl; + + @Test + public void getDirContextTest() { + String initialContextFactory ="Initial Context"; + String providerUrl = "URL"; + String securityPrincipal ="Security"; + serviceLocatorImpl.getDirContext(initialContextFactory, providerUrl, securityPrincipal); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/JSONUtilTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/JSONUtilTest.java new file mode 100644 index 00000000..a580b21d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/JSONUtilTest.java @@ -0,0 +1,76 @@ +/* + * ============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.util; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.portalsdk.core.domain.User; + +import com.fasterxml.jackson.core.JsonProcessingException; + +public class JSONUtilTest { + + @Test + public void convertResponseToJSONTest() throws JsonProcessingException { + String response = "Response"; + String json = JSONUtil.convertResponseToJSON(response); + Assert.assertNotNull(json); + } + + @Test + public void mapToDomainUserTest() { + User editUser = new User(); + User domainUser = new User(); + editUser.setOrgId(123L); + editUser.setManagerId(123L); + editUser.setFirstName("FName"); + editUser.setMiddleInitial("FName"); + editUser.setLastName("FName"); + editUser.setPhone("FName"); + editUser.setEmail("FName"); + editUser.setHrid("FName"); + editUser.setOrgUserId("FName"); + editUser.setOrgCode("FName"); + editUser.setOrgManagerUserId("FName"); + editUser.setJobTitle("FName"); + editUser.setLoginId("FName"); + editUser.setActive(true); + domainUser = JSONUtil.mapToDomainUser(domainUser, editUser); + Assert.assertNotNull(domainUser); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SecurityCodecUtilTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SecurityCodecUtilTest.java new file mode 100644 index 00000000..01885ce8 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SecurityCodecUtilTest.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.util; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.owasp.esapi.codecs.Codec; +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 SecurityCodecUtilTest { + + @Test + public void getCodecMySqlTest() { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.DB_DRIVER)).thenReturn("mysql"); + Codec codec = SecurityCodecUtil.getCodec(); + Assert.assertNotNull(codec); + + } + + @Test + public void getCodecMariaDbTest() { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.DB_DRIVER)).thenReturn("mariadb"); + Codec codec = SecurityCodecUtil.getCodec(); + Assert.assertNotNull(codec); + + } + + @Test + public void getCodecOracleTest() { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.DB_DRIVER)).thenReturn("oracle"); + Codec codec = SecurityCodecUtil.getCodec(); + Assert.assertNotNull(codec); + + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SystemPropertiesTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SystemPropertiesTest.java new file mode 100644 index 00000000..0493c3c2 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/SystemPropertiesTest.java @@ -0,0 +1,72 @@ +/* + * ============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.util; + +import static org.junit.Assert.assertEquals; + +import javax.servlet.ServletContext; + +import org.junit.Test; + +public class SystemPropertiesTest { + + @Test + public void getApplicationNameTest(){ + String actualResult = ""; + SystemProperties systemProperties = new SystemProperties(); + String expectedResult = systemProperties.getApplicationName(); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getAppDisplayNameTest(){ + String actualResult = ""; + SystemProperties systemProperties = new SystemProperties(); + String expectedResult = systemProperties.getAppDisplayName(); + assertEquals(actualResult, expectedResult); + } + + @Test + public void getServletContextTest(){ + ServletContext actualResult = null; + SystemProperties systemProperties = new SystemProperties(); + systemProperties.setServletContext(actualResult); + ServletContext expectedResult = systemProperties.getServletContext(); + assertEquals(actualResult, expectedResult); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/UsageUtilsTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/UsageUtilsTest.java new file mode 100644 index 00000000..8fcb7123 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/util/UsageUtilsTest.java @@ -0,0 +1,114 @@ +/* + * ============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.util; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpSession; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.portalsdk.core.command.UserRowBean; +import org.onap.portalsdk.core.domain.User; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class UsageUtilsTest { + + @Test + public void getActiveUsersTest() { + HttpSession mock1 = Mockito.mock(HttpSession.class); + HttpSession mock2 = Mockito.mock(HttpSession.class); + Mockito.when(mock1.getAttribute("user")).thenReturn(null); + + User user = new User(); + user.setFirstName("FName"); + user.setLastName("Lname"); + user.setId(123L); + user.setEmail("Xyz@xyz.com"); + user.setLastLoginDate(new Date()); + + Mockito.when(mock2.getCreationTime()).thenReturn(new Date().getTime()); + Mockito.when(mock2.getLastAccessedTime()).thenReturn(new Date().getTime()); + Mockito.when(mock2.getMaxInactiveInterval()).thenReturn(1000); + + Mockito.when(mock2.getAttribute("user")).thenReturn(user); + Map<String, HttpSession> activeUsers = new HashMap<>(); + activeUsers.put("1", mock1); + activeUsers.put("2", mock2); + List<UserRowBean> beans = UsageUtils.getActiveUsers(activeUsers); + Assert.assertTrue(beans.size() > 0); + } + + @Test + public void getActiveUsersAfterDeleteTest(){ + + HttpSession mock1 = Mockito.mock(HttpSession.class); + HttpSession mock2 = Mockito.mock(HttpSession.class); + Mockito.when(mock1.getAttribute("user")).thenReturn(null); + + User user = new User(); + user.setFirstName("FName"); + user.setLastName("Lname"); + user.setId(123L); + user.setEmail("Xyz@xyz.com"); + user.setLastLoginDate(new Date()); + + Mockito.when(mock2.getCreationTime()).thenReturn(new Date().getTime()); + Mockito.when(mock2.getLastAccessedTime()).thenReturn(new Date().getTime()); + Mockito.when(mock2.getMaxInactiveInterval()).thenReturn(1000); + + Mockito.when(mock2.getAttribute("user")).thenReturn(user); + Map<String, HttpSession> activeUsers = new HashMap<>(); + activeUsers.put("1", mock1); + activeUsers.put("2", mock2); + + UserRowBean bean = new UserRowBean(); + String beanSessionId = "1122"; + bean.setSessionId(beanSessionId); + HttpSession mock3 = Mockito.mock(HttpSession.class); + activeUsers.put(beanSessionId, mock3); + List<UserRowBean> beans = UsageUtils.getActiveUsersAfterDelete(activeUsers, bean); + Assert.assertTrue(beans.size() > 0); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/PeerBroadcastSocketTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/PeerBroadcastSocketTest.java new file mode 100644 index 00000000..8e49ed90 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/PeerBroadcastSocketTest.java @@ -0,0 +1,82 @@ +/* + * ============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.web.socket; + +import javax.websocket.RemoteEndpoint.Basic; +import javax.websocket.Session; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class PeerBroadcastSocketTest { + + @InjectMocks + private PeerBroadcastSocket peerBroadcastSocket; + + @Test + public void messageTest() { + String message = "{\"from\": \"to\", \"to\": \"to\"}"; + Session session = Mockito.mock(Session.class); + Basic basic = Mockito.mock(Basic.class); + Mockito.when(session.getBasicRemote()).thenReturn(basic); + Mockito.when(session.getId()).thenReturn("123"); + peerBroadcastSocket.message(message, session); + peerBroadcastSocket.close(session); + Assert.assertTrue(true); + } + + @Test + public void messageExceptionTest() { + String message = "{\"from\": \"to\", \"to\": \"to\"}"; + Session session = Mockito.mock(Session.class); + peerBroadcastSocket.message(message, session); + Assert.assertTrue(true); + } + + @Test + public void openTest() { + Session session = Mockito.mock(Session.class); + peerBroadcastSocket.open(session); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/WebRTCSocketTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/WebRTCSocketTest.java new file mode 100644 index 00000000..98bbdb85 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/socket/WebRTCSocketTest.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.web.socket; + +import javax.websocket.Session; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class WebRTCSocketTest { + + @InjectMocks + private WebRTCSocket webRTCSocket; + + @Test + public void messageTest(){ + String message = " { \"open\": true , \"channel\": \"123\" , \"data\" : { \"sessionid\": \"123\" } }"; + Session session =Mockito.mock(Session.class); + webRTCSocket.message(message, session); + Assert.assertTrue(true); + } + + @Test + public void openTest() { + Session session =Mockito.mock(Session.class); + webRTCSocket.open(session); + Assert.assertTrue(true); + } + + @Test + public void closeTest(){ + String message = " { \"open\": true , \"channel\": \"123\" , \"data\" : { \"sessionid\": \"123\" } }"; + Session session =Mockito.mock(Session.class); + Mockito.when(session.getId()).thenReturn("1234"); + webRTCSocket.message(message, session); + webRTCSocket.close(session); + Assert.assertTrue(true); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/FeedbackMessageTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/FeedbackMessageTest.java new file mode 100644 index 00000000..a5a24dec --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/FeedbackMessageTest.java @@ -0,0 +1,70 @@ +/* + * ============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.web.support; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class FeedbackMessageTest { + + public FeedbackMessage mockFeedbackMessage(){ + FeedbackMessage feedbackMessage = new FeedbackMessage(); + + feedbackMessage.setKeyed(false); + feedbackMessage.setMessage("test"); + feedbackMessage.setMessageType(1); + + return feedbackMessage; + } + + @Test + public void feedbackMessageTest(){ + FeedbackMessage feedbackMessage1 = mockFeedbackMessage(); + + FeedbackMessage feedbackMessage = new FeedbackMessage(); + feedbackMessage.setKeyed(false); + feedbackMessage.setMessage("test"); + feedbackMessage.setMessageType(1); + + assertEquals(feedbackMessage.isKeyed(), feedbackMessage1.isKeyed()); + assertEquals(feedbackMessage.getMessage(), feedbackMessage1.getMessage()); + assertEquals(feedbackMessage.getMessageType(), feedbackMessage1.getMessageType()); + + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java new file mode 100644 index 00000000..2600025e --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/JsonMessageTest.java @@ -0,0 +1,69 @@ +/* + * ============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.web.support; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class JsonMessageTest { + + public JsonMessage mockJsonMessage(){ + JsonMessage jsonMessage = new JsonMessage("test", "test", "test"); + + jsonMessage.setData("test"); + jsonMessage.setData2("test"); + jsonMessage.setData3("test"); + + return jsonMessage; + } + + @Test + public void jsonMessageTest(){ + JsonMessage jsonMessage1 = new JsonMessage("test", "test", "test"); + + JsonMessage jsonMessage = new JsonMessage("test", "test", "test"); + jsonMessage.setData("test"); + jsonMessage.setData2("test"); + jsonMessage.setData3("test"); + + assertEquals(jsonMessage.getData(), jsonMessage1.getData()); + assertEquals(jsonMessage.getData2(), jsonMessage1.getData2()); + assertEquals(jsonMessage.getData3(), jsonMessage1.getData3()); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java new file mode 100644 index 00000000..d0812e8c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/web/support/MessagesListTest.java @@ -0,0 +1,73 @@ +/* + * ============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.web.support; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class MessagesListTest { + + public MessagesList mockMessagesList (){ + MessagesList messagesList = new MessagesList(); + + messagesList.setExceptionMessages(null); + messagesList.setIncludeCauseInCustomExceptions(false); + messagesList.setSuccessMessageDisplayed(false); + messagesList.setSuccessMessages(null); + + return messagesList; + } + + @Test + public void messagesListTest(){ + MessagesList messagesList1 = mockMessagesList(); + + MessagesList messagesList = new MessagesList(); + messagesList.setExceptionMessages(null); + messagesList.setIncludeCauseInCustomExceptions(false); + messagesList.setSuccessMessageDisplayed(false); + messagesList.setSuccessMessages(null); + + assertEquals(messagesList.getExceptionMessages(), messagesList1.getExceptionMessages()); + assertEquals(messagesList.getSuccessMessages(), messagesList1.getSuccessMessages()); + assertEquals(messagesList.isIncludeCauseInCustomExceptions(), messagesList1.isIncludeCauseInCustomExceptions()); + assertEquals(messagesList.isSuccessMessageDisplayed(), messagesList1.isSuccessMessageDisplayed()); + + } +} |