summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2019-04-21 12:43:15 +0300
committertali orenbach <tali.orenbach@amdocs.com>2019-04-21 12:57:34 +0000
commit521000b2278eaf9fb1e57533e523014da1900098 (patch)
tree2aef25ddbc1a684e49315fd1ecadfa58c2f0bbf1 /catalog-be/src/test/java/org
parent04aecc5c84e2b2f4c59ec86850d6bcd25d3bc912 (diff)
Fix property name regex
property name should contain only letters, numbers and / or underscores Change-Id: Ic6b8d627a30f5f157bed1617a8af819b66352136 Issue-ID: SDC-2243 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'catalog-be/src/test/java/org')
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java128
1 files changed, 128 insertions, 0 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java
new file mode 100644
index 0000000000..b816702317
--- /dev/null
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/servlets/ComponentPropertyServletTest.java
@@ -0,0 +1,128 @@
+package org.openecomp.sdc.be.servlets;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
+import com.google.gson.Gson;
+import fj.data.Either;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.ws.rs.core.Response;
+import org.glassfish.grizzly.http.util.HttpStatus;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
+import org.openecomp.sdc.be.impl.WebAppContextWrapper;
+import org.openecomp.sdc.be.model.PropertyDefinition;
+import org.openecomp.sdc.be.resources.data.EntryData;
+import org.openecomp.sdc.common.api.Constants;
+import org.openecomp.sdc.exception.ResponseFormat;
+import org.springframework.web.context.WebApplicationContext;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ComponentPropertyServletTest extends JerseySpringBaseTest {
+ @Mock
+ private static HttpSession session;
+ @Mock
+ private static ServletContext context;
+ @Mock
+ private static WebAppContextWrapper wrapper;
+ @Mock
+ private static WebApplicationContext webAppContext;
+ @Mock
+ private static PropertyBusinessLogic propertyBl;
+ @Mock
+ private static ComponentsUtils componentsUtils;
+ @InjectMocks
+ @Spy
+ private ComponentPropertyServlet componentPropertyServlet;
+
+ private static final String SERVICE_ID = "service1";
+ private final static String USER_ID = "jh0003";
+ private static final String VALID_PROPERTY_NAME = "valid_name_123";
+ private static final String INVALID_PROPERTY_NAME = "invalid_name_$.&";
+ private static final String STRING_TYPE = "string";
+
+ @Before
+ public void initClass() {
+ initMockitoStubbings();
+ }
+
+ @Test
+ public void testCreatePropertyOnService_success() {
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(VALID_PROPERTY_NAME);
+ property.setType(STRING_TYPE);
+
+ EntryData<String, PropertyDefinition> propertyEntry = new EntryData<>(VALID_PROPERTY_NAME, property);
+ when(propertyBl.addPropertyToComponent(eq(SERVICE_ID), any(), any(), any())).thenReturn(Either.left(propertyEntry));
+
+ Response propertyInService =
+ componentPropertyServlet.createPropertyInService(SERVICE_ID, getValidProperty(), request, USER_ID);
+
+ Assert.assertEquals(HttpStatus.OK_200.getStatusCode(), propertyInService.getStatus());
+ }
+
+ @Test
+ public void testCreatePropertyInvalidName_failure() {
+ PropertyDefinition property = new PropertyDefinition();
+ property.setName(INVALID_PROPERTY_NAME);
+ property.setType(STRING_TYPE);
+
+ ResponseFormat responseFormat = new ResponseFormat();
+ responseFormat.setStatus(HttpStatus.BAD_REQUEST_400.getStatusCode());
+
+ when(componentsUtils.getResponseFormat(eq(ActionStatus.INVALID_PROPERTY_NAME))).thenReturn(responseFormat);
+
+
+ Response propertyInService =
+ componentPropertyServlet.createPropertyInService(SERVICE_ID, getInvalidProperty(), request, USER_ID);
+
+ Assert.assertEquals(HttpStatus.BAD_REQUEST_400.getStatusCode(), propertyInService.getStatus());
+ }
+
+ private static void initMockitoStubbings() {
+ when(request.getSession()).thenReturn(session);
+ when(session.getServletContext()).thenReturn(context);
+ when(context.getAttribute(eq(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))).thenReturn(wrapper);
+ when(wrapper.getWebAppContext(any())).thenReturn(webAppContext);
+ when(webAppContext.getBean(eq(PropertyBusinessLogic.class))).thenReturn(propertyBl);
+ when(webAppContext.getBean(eq(ComponentsUtils.class))).thenReturn(componentsUtils);
+ }
+
+ private String getValidProperty() {
+ return "{\n"
+ + " \"valid_name_123\": {\n"
+ + " \"schema\": {\n"
+ + " \"property\": {\n"
+ + " \"type\": \"\"\n"
+ + " }\n" + " },\n"
+ + " \"type\": \"string\",\n"
+ + " \"name\": \"valid_name_123\"\n"
+ + " }\n"
+ + "}";
+ }
+
+ private String getInvalidProperty() {
+ return "{\n"
+ + " \"invalid_name_$.&\": {\n"
+ + " \"schema\": {\n"
+ + " \"property\": {\n"
+ + " \"type\": \"\"\n"
+ + " }\n" + " },\n"
+ + " \"type\": \"string\",\n"
+ + " \"name\": \"invalid_name_$.&\"\n"
+ + " }\n"
+ + "}";
+ }
+
+}