+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
package org.openecomp.sdc.be.components;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
+import com.google.common.collect.Sets;
+import fj.data.Either;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
import javax.servlet.ServletContext;
-
import org.junit.Before;
import org.mockito.Mockito;
import org.openecomp.sdc.ElementOperationMock;
import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
-import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
+import org.openecomp.sdc.be.components.utils.ComponentBusinessLogicMock;
+import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.AuditingFieldsKeysEnum;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
-import com.google.common.collect.Sets;
-
-import fj.data.Either;
-public class BaseServiceBusinessLogicTest {
- private static final Logger log = LoggerFactory.getLogger(ServiceBusinessLogicTest.class);
+public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogicMock {
private static final String SERVICE_CATEGORY = "Mobility";
- final ServletContext servletContext = Mockito.mock(ServletContext.class);
- UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
- WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
- WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
- ServiceBusinessLogic bl = new ServiceBusinessLogic();
- ResponseFormatManager responseManager = null;
- IElementOperation mockElementDao;
- ComponentsUtils componentsUtils;
- AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
- ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
- GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
- TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
- ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
- CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
- GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
- ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
+ private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+ private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+ private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+ private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+ protected final IDistributionEngine distributionEngine = Mockito.mock(IDistributionEngine.class);
+ protected final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+ protected final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+ protected final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+ protected final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+ private ServiceBusinessLogic bl;
+ private ResponseFormatManager responseManager = null;
+ private IElementOperation mockElementDao;
+ private ComponentsUtils componentsUtils;
+ private AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
+ private ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
+ private GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+ private JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
+ private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+ private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
+ private ForwardingPathOperation forwardingPathOperation = Mockito.mock(ForwardingPathOperation.class);
+ private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
User user = null;
Service serviceResponse = null;
protected static final String UNCERTIFIED_VERSION = "0.2";
protected static final String COMPONNET_ID = "myUniqueId";
protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
- protected static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
- protected static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
- protected static Map<AuditingFieldsKeysEnum, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_CERTIFIED_VERSION = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_CURR = new HashMap<>();
+ protected static Map<AuditingFieldsKey, Object> FILTER_MAP_UNCERTIFIED_VERSION_PREV = new HashMap<>();
@Before
public void setup() {
ExternalConfiguration.setAppName("catalog-be");
- // init Configuration
- String appConfigDir = "src/test/resources/config/catalog-be";
- ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
- ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
// Elements
user.setLastName("Hendrix");
user.setRole(Role.ADMIN.name());
- Either<User, ActionStatus> eitherGetUser = Either.left(user);
- when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
+ when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
// Servlet Context attributes
when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
when(forwardingPathOperation.deleteForwardingPath(any(),any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
when(toscaOperationFacade.getToscaElement("delete_forward_test")).thenReturn(Either.left(createServiceObject(true)));
- bl = new ServiceBusinessLogic();
- bl.setElementDao(mockElementDao);
+ bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
+ groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
+ artifactsBusinessLogic, distributionEngine, componentInstanceBusinessLogic,
+ serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
+ artifactToscaOperation, componentContactIdValidator, componentNameValidator,
+ componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
+ modelOperation);
bl.setUserAdmin(mockUserAdmin);
- bl.setArtifactBl(artifactBl);
bl.setGraphLockOperation(graphLockOperation);
- bl.setTitanGenericDao(mockTitanDao);
+ bl.setJanusGraphDao(mockJanusGraphDao);
bl.setToscaOperationFacade(toscaOperationFacade);
bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
bl.setComponentsUtils(componentsUtils);
bl.setCassandraAuditingDao(auditingDao);
- bl.setCacheManagerOperation(cacheManager);
bl.setForwardingPathOperation(forwardingPathOperation);
bl.setToscaOperationFacade(toscaOperationFacade);
mockAuditingDaoLogic();
}
private void mockAuditingDaoLogic() {
- FILTER_MAP_CERTIFIED_VERSION.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
- FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
- FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKeysEnum.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+ FILTER_MAP_CERTIFIED_VERSION.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+ FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
+ FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID, COMPONNET_ID);
- FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_CURR_VERSION, UNCERTIFIED_VERSION);
- FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKeysEnum.AUDIT_RESOURCE_PREV_VERSION, UNCERTIFIED_VERSION);
+ FILTER_MAP_UNCERTIFIED_VERSION_CURR.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_VERSION, UNCERTIFIED_VERSION);
+ FILTER_MAP_UNCERTIFIED_VERSION_PREV.put(AuditingFieldsKey.AUDIT_RESOURCE_PREV_VERSION, UNCERTIFIED_VERSION);
final ResourceAdminEvent createResourceAudit = new ResourceAdminEvent();
createResourceAudit.setModifier("Carlos Santana(cs0008)");
checkOutResourceAudit.setResourceName("MyTestResource");
// checkOutResourceAudit.setFields(fields);
- // Mockito.doAnswer(new Answer<Either<List<ESTimeBasedEvent>,
- // ActionStatus> >() {
- // public Either<List<ESTimeBasedEvent>, ActionStatus>
- // answer(InvocationOnMock invocation) {
- // final Either<List<ESTimeBasedEvent>, ActionStatus> either;
- // final List<ESTimeBasedEvent> list;
- // Object[] args = invocation.getArguments();
- // Map<AuditingFieldsKeysEnum, Object> filterMap =
- // (Map<AuditingFieldsKeysEnum, Object>) args[0];
- // if( filterMap.equals(FILTER_MAP_CERTIFIED_VERSION) ){
- // list = new
- // ArrayList<ESTimeBasedEvent>(){{add(createResourceAudit);add(checkInResourceAudit);add(checkOutResourceAudit);}};
- // either = Either.left(list);
- //
- // }
- // else if( filterMap.equals(FILTER_MAP_UNCERTIFIED_VERSION_PREV) ){
- // list = new ArrayList<ESTimeBasedEvent>();
- // either = Either.left(list);
- // }
- // else if( filterMap.equals(FILTER_MAP_UNCERTIFIED_VERSION_CURR) ){
- // list = new
- // ArrayList<ESTimeBasedEvent>(){{/*add(createResourceAudit);add(checkInResourceAudit);*/add(checkOutResourceAudit);}};
- // either = Either.left(list);
- // }
- // else{
- // either = null;
- // }
- // return either;
- // }
- // }).when(auditingDao).getFilteredResourceAdminAuditingEvents(Mockito.anyMap());
- //
- //
List<ResourceAdminEvent> list = new ArrayList<ResourceAdminEvent>() {
{
add(createResourceAudit);
Either<List<ResourceAdminEvent>, ActionStatus> result = Either.left(list);
Mockito.when(auditingDao.getByServiceInstanceId(Mockito.anyString())).thenReturn(result);
- List<ResourceAdminEvent> listPrev = new ArrayList<ResourceAdminEvent>();
+ List<ResourceAdminEvent> listPrev = new ArrayList<>();
Either<List<ResourceAdminEvent>, ActionStatus> resultPrev = Either.left(listPrev);
Mockito.when(auditingDao.getAuditByServiceIdAndPrevVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(resultPrev);
service.setCategories(categories);
service.setDescription("description");
- List<String> tgs = new ArrayList<String>();
+ List<String> tgs = new ArrayList<>();
tgs.add(service.getName());
service.setTags(tgs);
// service.setVendorName("Motorola");