From 95b22d8d074f294e997c27d79d369b0eb3bee9e2 Mon Sep 17 00:00:00 2001 From: davsad Date: Fri, 16 Jul 2021 09:44:22 +0100 Subject: Disable locking during deployment Issue-ID: SDC-3643 Signed-off-by: davsad Change-Id: I1a04c253d70bf5aebf33bba7b2b9f83bd559ae64 --- .../openecomp/sdc/be/servlets/LockServletTest.java | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LockServletTest.java (limited to 'catalog-be/src/test/java') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LockServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LockServletTest.java new file mode 100644 index 0000000000..c2fb235476 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/LockServletTest.java @@ -0,0 +1,121 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.be.servlets; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response.Status; + +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.TestProperties; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.be.components.validation.UserValidations; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.be.config.SpringConfig; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation; +import org.openecomp.sdc.be.user.UserBusinessLogic; +import org.openecomp.sdc.common.api.ConfigurationSource; +import org.openecomp.sdc.common.api.Constants; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +class LockServletTest extends JerseyTest { + + @Mock + private HttpServletRequest request; + @Mock + private UserBusinessLogic userBusinessLogic; + @Mock + private ComponentsUtils componentsUtils; + @Mock + private IGraphLockOperation graphLockOperation; + @Mock + private UserValidations userValidations; + + private static final String postUrl = "/v1/catalog/lock"; + private static final String USER_ID = "cs0008"; + + @BeforeEach + void init() throws Exception { + super.setUp(); + initConfig(); + } + + @AfterEach + void destory() throws Exception { + super.tearDown(); + } + + private void initConfig() { + final String appConfigDir = "src/test/resources/config/catalog-be"; + final ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir); + final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource); + final org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration(); + configuration.setJanusGraphInMemoryGraph(true); + configurationManager.setConfiguration(configuration); + ExternalConfiguration.setAppName("catalog-be"); + } + + @Override + protected ResourceConfig configure() { + MockitoAnnotations.openMocks(this); + forceSet(TestProperties.CONTAINER_PORT, "0"); + final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class); + return new ResourceConfig(LockServlet.class) + .register(new AbstractBinder() { + @Override + protected void configure() { + bind(request).to(HttpServletRequest.class); + bind(userBusinessLogic).to(UserBusinessLogic.class); + bind(componentsUtils).to(ComponentsUtils.class); + bind(graphLockOperation).to(IGraphLockOperation.class); + bind(userValidations).to(UserValidations.class); + } + }) + .property("contextConfig", context); + } + + @Test + void disableLockTest() { + assertEquals(Status.OK.getStatusCode(), postDisableLock(true)); + assertEquals(Status.OK.getStatusCode(), postDisableLock(false)); + assertEquals(Status.OK.getStatusCode(), postDisableLock("true")); + assertEquals(Status.OK.getStatusCode(), postDisableLock("false")); + assertEquals(Status.BAD_REQUEST.getStatusCode(), postDisableLock("true1")); + assertEquals(Status.BAD_REQUEST.getStatusCode(), postDisableLock(null)); + } + + private int postDisableLock(Object disable) { + return target(postUrl).request(MediaType.APPLICATION_JSON) + .header(Constants.USER_ID_HEADER, USER_ID) + .post(Entity.json(disable)).getStatus(); + } +} \ No newline at end of file -- cgit 1.2.3-korg