diff options
Diffstat (limited to 'catalog-be/src/test/java/org')
2 files changed, 47 insertions, 31 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java index dd76fb29c7..1a993824c0 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java @@ -1,35 +1,30 @@ package org.openecomp.sdc.be.ecomp; +import fj.data.Either; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.Mockito; import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +import org.onap.portalsdk.core.restful.domain.EcompRole; import org.onap.portalsdk.core.restful.domain.EcompUser; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.user.UserBusinessLogic; -import org.springframework.web.context.ContextLoader; -import org.springframework.web.context.WebApplicationContext; +import org.openecomp.sdc.exception.ResponseFormat; +import java.util.HashSet; import java.util.Map; +import java.util.Set; public class PortalRestAPICentralServiceImplTest { - @Mock - ContextLoader conLoader; - @Mock - WebApplicationContext apContext; - @Mock - UserBusinessLogic userBusinessLogic; - @Mock - ContextLoader ctx; - @InjectMocks - PortalRestAPICentralServiceImpl testSubject; + PortalRestAPICentralServiceImpl testSubject; + UserBusinessLogic ubl; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); + ubl = Mockito.mock(UserBusinessLogic.class); + testSubject = new PortalRestAPICentralServiceImpl(ubl); } @Test @@ -40,8 +35,32 @@ public class PortalRestAPICentralServiceImplTest { Assert.assertTrue(appCredentials.get(PortalRestAPICentralServiceImpl.PortalPropertiesEnum.PORTAL_PASS.value()).equals("asdc")); } - /*@Test - public void testPushUser() throws Exception { + @Test + public void testPushUserGeneralError() throws Exception { + ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class); + Mockito.when(responseFormat.getMessageId()).thenReturn("mock"); + Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.right(responseFormat)); + EcompUser user = new EcompUser(); + Set<EcompRole> roleSet = new HashSet<>(); + EcompRole role = new EcompRole(); + role.setId(1L); + role.setName("Designer"); + roleSet.add(role); + user.setRoles(roleSet); + try{ + testSubject.pushUser(user); + }catch (PortalAPIException e) { + System.out.println(e); + Assert.assertTrue(e.getMessage().startsWith("Failed to create user {}")); + } + + } + + @Test + public void testPushUserSuccess() throws Exception { + ResponseFormat responseFormat = Mockito.mock(ResponseFormat.class); + Mockito.when(responseFormat.getMessageId()).thenReturn("SVC4006"); + Mockito.when(ubl.createUser(Mockito.any(), Mockito.any())).thenReturn(Either.left(new User())); EcompUser user = new EcompUser(); Set<EcompRole> roleSet = new HashSet<>(); EcompRole role = new EcompRole(); @@ -50,7 +69,7 @@ public class PortalRestAPICentralServiceImplTest { roleSet.add(role); user.setRoles(roleSet); testSubject.pushUser(user); - }*/ + } @Test public void testPushUserNullRoles() throws Exception { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverterTest.java index 301de32f6f..fae2135b49 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverterTest.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.be.ecomp.converters; import fj.data.Either; +import org.junit.Assert; import org.junit.Test; import org.onap.portalsdk.core.restful.domain.EcompRole; import org.onap.portalsdk.core.restful.domain.EcompUser; @@ -44,24 +45,20 @@ public class EcompUserConverterTest { @Test public void shouldNotCrashWhenEcompUserIsNotProvided() { - Either<User, String> convertedUser = EcompUserConverter.convertEcompUserToUser(null); + User convertedUser = EcompUserConverter.convertEcompUserToUser(null); - assertThat(convertedUser.isRight()).isTrue(); + Assert.assertTrue(convertedUser != null); } @Test public void shouldProperlyConvertUserToEcompUser() { - Either<User, String> convertedUser = EcompUserConverter.convertEcompUserToUser(createEcompUser()); - - assertThat(convertedUser.isLeft()).isTrue(); - - User user = convertedUser.left().value(); + User convertedUser = EcompUserConverter.convertEcompUserToUser(createEcompUser()); - assertThat(EMAIL_ADDRESS).isEqualTo(user.getEmail()); - assertThat(FIRST_NAME).isEqualTo(user.getFirstName()); - assertThat(LAST_NAME).isEqualTo(user.getLastName()); - assertThat(USER_ID).isEqualTo(user.getUserId()); - assertThat(ROLE).isEqualTo(user.getRole()); + assertThat(EMAIL_ADDRESS).isEqualTo(convertedUser.getEmail()); + assertThat(FIRST_NAME).isEqualTo(convertedUser.getFirstName()); + assertThat(LAST_NAME).isEqualTo(convertedUser.getLastName()); + assertThat(USER_ID).isEqualTo(convertedUser.getUserId()); + assertThat(ROLE).isEqualTo(convertedUser.getRole()); } private EcompUser createEcompUser() { |