From ee4eb6be6246c8128730aecb862d67a5690926bd Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Wed, 3 Oct 2018 15:07:48 +0530 Subject: Test coverage : openecomp-session-lib Increase test coverage Change-Id: I3ac270b651c2e695cc970642fd7d27a3f557904f Issue-ID: SDC-1673 Signed-off-by: siddharth0905 --- .../impl/AsdcSessionContextProviderTest.java | 63 ++++++++++++++++++++++ .../SessionContextProviderFactoryImplTest.java | 45 ++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java create mode 100644 openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java') diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java new file mode 100644 index 0000000000..f0a9d2dcf7 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/AsdcSessionContextProviderTest.java @@ -0,0 +1,63 @@ +/* + * + * Copyright © 2017-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * / + * + */ + +package org.openecomp.sdc.common.session.impl; + +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.session.SessionContext; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class AsdcSessionContextProviderTest { + + private static final String USER_ID = "cs0008"; + + @InjectMocks + private AsdcSessionContextProvider asdcSessionContextProvider; + + @BeforeMethod + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test(expectedExceptions = CoreException.class) + public void testGetUserIdNull() { + asdcSessionContextProvider.create(null, null); + asdcSessionContextProvider.get(); + } + + @Test(expectedExceptions = CoreException.class) + public void testGetTenantNull() { + asdcSessionContextProvider.create(USER_ID, null); + asdcSessionContextProvider.get(); + } + + @Test + public void testGet() { + asdcSessionContextProvider.create(USER_ID, "tenant"); + SessionContext sessionContext = asdcSessionContextProvider.get(); + + Assert.assertNotNull(sessionContext); + Assert.assertSame(USER_ID, sessionContext.getUser().getUserId()); + Assert.assertSame("tenant", sessionContext.getTenant()); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java new file mode 100644 index 0000000000..eec7bd02ad --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-session-lib/src/test/java/org/openecomp/sdc/common/session/impl/SessionContextProviderFactoryImplTest.java @@ -0,0 +1,45 @@ +/* + * + * Copyright © 2017-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file 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. + * / + * + */ + +package org.openecomp.sdc.common.session.impl; + +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.common.session.SessionContextProvider; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class SessionContextProviderFactoryImplTest { + + @InjectMocks + private SessionContextProviderFactoryImpl sessionContextProviderFactoryImpl; + + @BeforeMethod + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testCreateInterface() { + SessionContextProvider sessionContextProvider = sessionContextProviderFactoryImpl.createInterface(); + + Assert.assertTrue(sessionContextProvider instanceof AsdcSessionContextProvider); + } +} -- cgit 1.2.3-korg