summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorTal Gitelman <tal.gitelman@att.com>2018-12-02 16:14:43 +0200
committerTal Gitelman <tal.gitelman@att.com>2018-12-02 15:41:44 +0000
commitfb81b5b97b8375ed406e191039a95be9df43445f (patch)
treee4cf61ada1804a8ac21f9fbd4dc643417e3fe0e7 /catalog-be/src
parent4a99e32a55f5b9210625274310cb8d68dd4095e7 (diff)
update sdc portal integration
Issue-ID: SDC-1749 Change-Id: Ia6a143bfc0a1511909bc83cb5ea1c1b3f8789b08 Signed-off-by: Tal Gitelman <tal.gitelman@att.com>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java27
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java34
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java57
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverterTest.java21
5 files changed, 71 insertions, 74 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
index 27f214568e..c84558dbd0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java
@@ -93,18 +93,13 @@ public class EcompIntImpl implements IPortalRestAPIService {
modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
- Either<User, String> newASDCUser = EcompUserConverter.convertEcompUserToUser(user);
- if (newASDCUser.isRight()) {
+ User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (convertedAsdcUser == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, ErrorSeverity.INFO);
log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
- } else if (newASDCUser.left().value() == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, ErrorSeverity.INFO);
- log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
+ throw new PortalAPIException("Failed to convert user " + user);
}
- User convertedAsdcUser = newASDCUser.left().value();
Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, convertedAsdcUser);
// ALREADY EXIST ResponseFormat
@@ -158,18 +153,14 @@ public class EcompIntImpl implements IPortalRestAPIService {
user.setLoginId(loginId);
}
- Either<User, String> asdcUser = EcompUserConverter.convertEcompUserToUser(user);
- if (asdcUser.isRight()) {
- log.debug(FAILED_TO_CONVERT_USER);
- BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, FAILED_TO_CONVERT_USER, ErrorSeverity.INFO);
- throw new PortalAPIException(asdcUser.right().value());
- } else if (asdcUser.left().value() == null) {
- log.debug(NULL_POINTER_RETURNED_FROM_USER_CONVERTER);
- BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_EDIT_USER);
+ User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (convertedAsdcUser == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, ErrorSeverity.INFO);
+ log.debug(FAILED_TO_CREATE_USER, user);
+ throw new PortalAPIException("Failed to convert user " + user);
}
- Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser.left().value());
+ Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(convertedAsdcUser);
if (updateUserCredentialsResponse.isRight()) {
log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
index 36f51da3d0..4df659ddd2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
@@ -54,7 +54,7 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
log.debug("PortalRestAPICentralServiceImpl Class Instantiated");
}
- public PortalRestAPICentralServiceImpl(UserBusinessLogic ubl) {
+ PortalRestAPICentralServiceImpl(UserBusinessLogic ubl) {
this.userBusinessLogic = ubl;
}
@@ -92,18 +92,13 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
modifier.setUserId(modifierAttId);
log.debug("modifier id is {}", modifierAttId);
- Either<User, String> newASDCUser = EcompUserConverter.convertEcompUserToUser(user);
- if (newASDCUser.isRight()) {
+ User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (convertedAsdcUser == null) {
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
- } else if (newASDCUser.left().value() == null) {
- BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, BeEcompErrorManager.ErrorSeverity.INFO);
- log.debug(FAILED_TO_CREATE_USER, user);
- throw new PortalAPIException("Failed to create user " + newASDCUser.right().value());
+ throw new PortalAPIException("Failed to convert user " + user);
}
- User convertedAsdcUser = newASDCUser.left().value();
Either<User, ResponseFormat> createUserResponse = userBusinessLogic.createUser(modifier, convertedAsdcUser);
// ALREADY EXIST ResponseFormat
@@ -113,20 +108,20 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
if (!createUserResponse.right().value().getMessageId().equals(ALREADY_EXISTS_RESPONSE_ID)) {
log.debug(FAILED_TO_CREATE_USER, user);
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_CREATE_USER + createUserResponse.right());
+ throw new PortalAPIException(FAILED_TO_CREATE_USER + createUserResponse.right().value());
} else {
log.debug("User already exist and will be updated and reactivated {}", user);
Either<User, ResponseFormat> updateUserResp = userBusinessLogic.updateUserCredentials(convertedAsdcUser);
if(updateUserResp.isRight()){
log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS, user);
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_UPDATE_USER_CREDENTIALS, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_UPDATE_USER_CREDENTIALS + createUserResponse.right());
+ throw new PortalAPIException(FAILED_TO_UPDATE_USER_CREDENTIALS + createUserResponse.right().value());
}
Either<User, ResponseFormat> updateUserRoleResp = userBusinessLogic.updateUserRole(modifier, convertedAsdcUser.getUserId(), convertedAsdcUser.getRole());
if(updateUserRoleResp.isRight()){
log.debug(FAILED_TO_UPDATE_USER_ROLE, user);
BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_UPDATE_USER_ROLE, BeEcompErrorManager.ErrorSeverity.ERROR);
- throw new PortalAPIException(FAILED_TO_UPDATE_USER_ROLE + createUserResponse.right());
+ throw new PortalAPIException(FAILED_TO_UPDATE_USER_ROLE + createUserResponse.right().value());
}
}
@@ -163,18 +158,13 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
user.setLoginId(loginId);
}
- Either<User, String> convertorResp = EcompUserConverter.convertEcompUserToUser(user);
- if (convertorResp.isRight()) {
- log.debug(FAILED_TO_CONVERT_USER);
- BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
- throw new PortalAPIException(convertorResp.right().value());
- } else if (convertorResp.left().value() == null) {
- log.debug(NULL_POINTER_RETURNED_FROM_USER_CONVERTER);
- BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, NULL_POINTER_RETURNED_FROM_USER_CONVERTER, BeEcompErrorManager.ErrorSeverity.INFO);
- throw new PortalAPIException(FAILED_TO_EDIT_USER);
+ User asdcUser = EcompUserConverter.convertEcompUserToUser(user);
+ if (asdcUser == null) {
+ BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CONVERT_USER, BeEcompErrorManager.ErrorSeverity.INFO);
+ log.debug(FAILED_TO_CREATE_USER, user);
+ throw new PortalAPIException("Failed to convert user " + user);
}
- User asdcUser = convertorResp.left().value();
Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser);
if (updateUserCredentialsResponse.isRight()) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
index 61b29a3986..4e06c4ea41 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/EcompUserConverter.java
@@ -72,11 +72,11 @@ public final class EcompUserConverter {
return Either.left(convertedUser);
}
- public static Either<User, String> convertEcompUserToUser(EcompUser ecompUser) {
+ public static User convertEcompUserToUser(EcompUser ecompUser) {
User convertedUser = new User();
if (ecompUser == null) {
- return Either.right("EcompUser is null");
+ return convertedUser;
}
convertedUser.setFirstName(ecompUser.getFirstName());
@@ -105,6 +105,6 @@ public final class EcompUserConverter {
convertedUser.setStatus(UserStatusEnum.INACTIVE);
}
- return Either.left(convertedUser);
+ return convertedUser;
}
} \ No newline at end of file
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() {