update sdc portal integration 29/73929/3
authorTal Gitelman <tal.gitelman@att.com>
Thu, 29 Nov 2018 09:57:23 +0000 (11:57 +0200)
committerTal Gitelman <tal.gitelman@att.com>
Thu, 29 Nov 2018 13:52:43 +0000 (15:52 +0200)
Issue-ID: SDC-1749

Change-Id: Ic8162af62583dd5d1d81662ef555d2267514f107
Signed-off-by: Tal Gitelman <tal.gitelman@att.com>
catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImpl.java
catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/PortalRestAPICentralServiceImplTest.java

index 0dd3717..36f51da 100644 (file)
@@ -40,12 +40,24 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
     private static final String PUSH_USER = "PushUser";
     private static final String RECEIVED_NULL_FOR_ARGUMENT_USER = "Received null for argument user";
     private static final Logger log = Logger.getLogger(PortalRestAPICentralServiceImpl.class);
+    private UserBusinessLogic userBusinessLogic;
 
-    public PortalRestAPICentralServiceImpl() {
+    public PortalRestAPICentralServiceImpl() throws PortalAPIException {
+        try {
+            ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
+            userBusinessLogic = (UserBusinessLogic) ctx.getBean("userBusinessLogic");
+        } catch (Exception e) {
+            log.debug("Failed to get user UserBusinessLogic", e);
+            BeEcompErrorManager.getInstance().logInvalidInputError("constructor", "Exception thrown" + e.getMessage(), BeEcompErrorManager.ErrorSeverity.ERROR);
+            throw new PortalAPIException("SDC Internal server error");
+        }
         log.debug("PortalRestAPICentralServiceImpl Class Instantiated");
     }
 
-    //TODO put username password and appName into portal properties
+    public PortalRestAPICentralServiceImpl(UserBusinessLogic ubl) {
+        this.userBusinessLogic = ubl;
+    }
+
     @Override
     public Map<String, String> getAppCredentials() throws PortalAPIException {
         Map<String, String> credMap = new HashMap<>();
@@ -74,7 +86,6 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
             throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_USER);
         }
         checkIfSingleRoleProvided(user);
-        UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
 
         final String modifierAttId = JH0003;
         User modifier = new User();
@@ -138,7 +149,6 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
         }
 
         checkIfSingleRoleProvided(user);
-        UserBusinessLogic userBusinessLogic = getUserBusinessLogic();
 
         final String modifierAttId = JH0003;
         User modifier = new User();
@@ -193,18 +203,6 @@ public final class PortalRestAPICentralServiceImpl implements IPortalRestCentral
         return request.getHeader(Constants.USER_ID_HEADER);
     }
 
-    private UserBusinessLogic getUserBusinessLogic() throws PortalAPIException {
-        UserBusinessLogic ubl = null;
-        try {
-            ApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext();
-            ubl = (UserBusinessLogic) ctx.getBean("userBusinessLogic");
-        } catch (Exception e) {
-            log.debug("Failed to get user UserBusinessLogic", e);
-            BeEcompErrorManager.getInstance().logInvalidInputError("getUserBusinessLogic", "Exception thrown" + e.getMessage(), BeEcompErrorManager.ErrorSeverity.ERROR);
-            throw new PortalAPIException("SDC Internal server error");
-        }
-        return ubl;
-    }
 
     private void checkIfSingleRoleProvided(EcompUser user) throws PortalAPIException {
         if(user.getRoles() == null) {
index 552d2dd..dd76fb2 100644 (file)
@@ -7,17 +7,12 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 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.user.UserBusinessLogic;
 import org.springframework.web.context.ContextLoader;
 import org.springframework.web.context.WebApplicationContext;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
 
 public class PortalRestAPICentralServiceImplTest {
     @Mock
@@ -108,44 +103,4 @@ public class PortalRestAPICentralServiceImplTest {
     //TODO: Test goes here...
     }
 
-
-    /**
-    *
-    * Method: getUserBusinessLogic()
-    *
-    */
-    @Test
-    public void testGetUserBusinessLogic() throws Exception {
-    //TODO: Test goes here...
-
-    try {
-       Method method = testSubject.getClass().getMethod("getUserBusinessLogic");
-       method.setAccessible(true);
-       method.invoke(testSubject);
-    } catch(NoSuchMethodException e) {
-    } catch(IllegalAccessException e) {
-    } catch(InvocationTargetException e) {
-    }
-    }
-
-    /**
-    *
-    * Method: checkIfSingleRoleProvided(EcompUser user)
-    *
-    */
-    @Test
-    public void testCheckIfSingleRoleProvided() throws Exception {
-    //TODO: Test goes here...
-    /*
-    try {
-       Method method = PortalRestAPICentralServiceImpl.getClass().getMethod("checkIfSingleRoleProvided", EcompUser.class);
-       method.setAccessible(true);
-       method.invoke(<Object>, <Parameters>);
-    } catch(NoSuchMethodException e) {
-    } catch(IllegalAccessException e) {
-    } catch(InvocationTargetException e) {
-    }
-    */
-    }
-
-} 
+}