From 88fdc6dd75f1119ffa8e54dbfd721b6ed722b779 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Wed, 23 Mar 2022 15:39:45 +0000 Subject: Fix Service/VF set value to list/map properties In the Service Property Assignment page, setting a value to a property of type list or map was having the type replaced by the schema type and the value incorrectly set. Add test cases to cover the problem. Include small refactors. Issue-ID: SDC-3926 Change-Id: I1257dbb02e18b103118672ec52d663707d53229c Signed-off-by: andre.schmid --- .../PropertyValueConstraintValidationUtilTest.java | 261 ++++++++++++++------- 1 file changed, 173 insertions(+), 88 deletions(-) (limited to 'catalog-be/src/test/java') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java index a8dcf8acce..c1e33a8474 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtilTest.java @@ -20,34 +20,33 @@ package org.openecomp.sdc.be.datamodel.utils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import fj.data.Either; -import java.io.BufferedReader; -import java.io.File; +import java.io.IOException; import java.lang.reflect.Type; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.sdc.be.components.impl.ResponseFormatManager; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.InputDefinition; @@ -58,7 +57,7 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade import org.openecomp.sdc.be.model.operations.impl.PropertyOperation; import org.openecomp.sdc.exception.ResponseFormat; -public class PropertyValueConstraintValidationUtilTest { +class PropertyValueConstraintValidationUtilTest { @Mock ApplicationDataTypeCache applicationDataTypeCache; @@ -72,10 +71,10 @@ public class PropertyValueConstraintValidationUtilTest { private Map dataTypeDefinitionMap; - @Before - public void init() { + @BeforeEach + void init() throws IOException { MockitoAnnotations.openMocks(this); - ResponseFormatManager responseFormatManagerMock = Mockito.mock(ResponseFormatManager.class); + ResponseFormatManager responseFormatManagerMock = mock(ResponseFormatManager.class); when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat()); when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat()); when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat()); @@ -85,9 +84,9 @@ public class PropertyValueConstraintValidationUtilTest { } @Test - public void primitiveValueSuccessTest() { + void primitiveValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("integer"); @@ -97,13 +96,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void primitiveValueFailTest() { + void primitiveValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("integer"); @@ -112,13 +111,13 @@ public class PropertyValueConstraintValidationUtilTest { Either responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void complexWithValidValueSuccessTest() { + void complexWithValidValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -128,13 +127,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void complexWithValidValueFailTest() { + void complexWithValidValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -143,13 +142,13 @@ public class PropertyValueConstraintValidationUtilTest { Either responseEither = propertyValueConstraintValidationUtil .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void complexWithListWithPrimitiveValueSuccessTest() { + void complexWithListWithPrimitiveValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -159,13 +158,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void complexWithListWithPrimitiveValueFailTest() { + void complexWithListWithPrimitiveValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -175,13 +174,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void complexWithMapWithPrimitiveValueSuccessTest() { + void complexWithMapWithPrimitiveValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -191,13 +190,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void complexWithMapWithPrimitiveValueFailTest() { + void complexWithMapWithPrimitiveValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -207,13 +206,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void inputValidValueSuccessTest() { + void inputValidValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); InputDefinition inputDefinition = new InputDefinition(); inputDefinition.setInputPath("propetyName#ipv6_ra_mode"); @@ -227,13 +226,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(inputDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void inputValidValueFailTest() { + void inputValidValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); InputDefinition inputDefinition = new InputDefinition(); inputDefinition.setInputPath("propetyName#ipv6_ra_mode"); @@ -246,13 +245,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(inputDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void serviceConsumptionValidValueSuccessTest() { + void serviceConsumptionValidValueSuccessTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -263,12 +262,109 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } + @Test - public void serviceConsumptionValidValueFailTest() { + void listOfComplexSuccessTest() { + when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap)); + + final var propertyDefinition = new PropertyDefinition(); + final String type = "list"; + propertyDefinition.setType(type); + final SchemaDefinition schemaDefinition = new SchemaDefinition(); + final PropertyDataDefinition schemaProperty = new PropertyDataDefinition(); + final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet"; + schemaProperty.setType(schemaType); + schemaDefinition.setProperty(schemaProperty); + propertyDefinition.setSchema(schemaDefinition); + final String value = "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}]"; + propertyDefinition.setValue(value); + final String name = "listOfComplex"; + propertyDefinition.setName(name); + + Either responseEither = + propertyValueConstraintValidationUtil + .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); + + assertTrue(responseEither.isLeft()); + //original object values should not be changed + assertEquals(name, propertyDefinition.getName()); + assertEquals(type, propertyDefinition.getType()); + assertEquals(value, propertyDefinition.getValue()); + assertEquals(schemaType, propertyDefinition.getSchemaType()); + } + + @Test + void listOfComplexSuccessTest1() { + when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap)); + + final var propertyDefinition = new PropertyDefinition(); + final String type = "list"; + propertyDefinition.setType(type); + final String listSchemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet"; + final PropertyDataDefinition listSchemaProperty = new PropertyDataDefinition(); + listSchemaProperty.setType(listSchemaType); + final SchemaDefinition listSchemaDefinition = new SchemaDefinition(); + listSchemaDefinition.setProperty(listSchemaProperty); + final PropertyDataDefinition schemaProperty = new PropertyDataDefinition(); + schemaProperty.setSchema(listSchemaDefinition); + final String schemaType = "list"; + schemaProperty.setType(schemaType); + final SchemaDefinition schemaDefinition = new SchemaDefinition(); + schemaDefinition.setProperty(schemaProperty); + propertyDefinition.setSchema(schemaDefinition); + final String value = "[[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}], [{\"ipv6_address_mode\": \"dhcpv6-stateful\"}]]"; + propertyDefinition.setValue(value); + final String name = "listOfComplex"; + propertyDefinition.setName(name); + + Either responseEither = + propertyValueConstraintValidationUtil + .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); + + assertTrue(responseEither.isLeft()); + //original object values should not be changed + assertEquals(name, propertyDefinition.getName()); + assertEquals(type, propertyDefinition.getType()); + assertEquals(value, propertyDefinition.getValue()); + assertEquals(schemaType, propertyDefinition.getSchemaType()); + } + + @Test + void mapOfComplexSuccessTest() { + when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap)); + + final var propertyDefinition = new PropertyDefinition(); + final String type = "map"; + propertyDefinition.setType(type); + final SchemaDefinition schemaDefinition = new SchemaDefinition(); + final PropertyDataDefinition schemaProperty = new PropertyDataDefinition(); + final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet"; + schemaProperty.setType(schemaType); + schemaDefinition.setProperty(schemaProperty); + propertyDefinition.setSchema(schemaDefinition); + final String value = "{\"key1\": {\"ipv6_address_mode\": \"dhcpv6-stateful\"}, \"key2\": {\"ipv6_address_mode\": \"dhcpv6-stateless\"}}"; + propertyDefinition.setValue(value); + final String name = "mapOfComplex"; + propertyDefinition.setName(name); + + Either responseEither = + propertyValueConstraintValidationUtil.validatePropertyConstraints( + Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); + + assertTrue(responseEither.isLeft()); + //original object values should not be changed + assertEquals(name, propertyDefinition.getName()); + assertEquals(type, propertyDefinition.getType()); + assertEquals(value, propertyDefinition.getValue()); + assertEquals(schemaType, propertyDefinition.getSchemaType()); + } + + @Test + void serviceConsumptionValidValueFailTest() { Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet"); @@ -279,13 +375,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void bandwidthTypeValueSuccessTest(){ + void bandwidthTypeValueSuccessTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -294,13 +390,13 @@ public class PropertyValueConstraintValidationUtilTest { Either responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void bandwidthTypeValueFailTest(){ + void bandwidthTypeValueFailTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -310,13 +406,13 @@ public class PropertyValueConstraintValidationUtilTest { Either responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void bandwidthDownstreamValueSuccessTest(){ + void bandwidthDownstreamValueSuccessTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -327,13 +423,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void bandwidthDownstreamValueFailTest(){ + void bandwidthDownstreamValueFailTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -344,13 +440,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void bandwidthUpstreamValueSuccessTest(){ + void bandwidthUpstreamValueSuccessTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -361,13 +457,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void bandwidthUpstreamValueFailTest(){ + void bandwidthUpstreamValueFailTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -378,13 +474,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } @Test - public void bandwidthUnitsValueSuccessTest(){ + void bandwidthUnitsValueSuccessTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -395,13 +491,13 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isLeft()); + assertTrue(responseEither.isLeft()); } @Test - public void bandwidthUnitsValueFailTest(){ + void bandwidthUnitsValueFailTest(){ Either, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap); - Mockito.when(applicationDataTypeCache.getAll(null)).thenReturn(either); + when(applicationDataTypeCache.getAll(null)).thenReturn(either); PropertyDefinition propertyDefinition = new PropertyDefinition(); propertyDefinition.setType("onap.datatypes.partner.bandwidth"); @@ -412,16 +508,16 @@ public class PropertyValueConstraintValidationUtilTest { propertyValueConstraintValidationUtil.validatePropertyConstraints( Collections.singletonList(propertyDefinition), applicationDataTypeCache, null); - Assert.assertTrue(responseEither.isRight()); + assertTrue(responseEither.isRight()); } - private void createDataTypeMap() { + private void createDataTypeMap() throws IOException { Type constraintType = new TypeToken() {}.getType(); Type typeOfHashMap = new TypeToken>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyOperation.PropertyConstraintDeserialiser()).create(); - dataTypeDefinitionMap = gson.fromJson(readFile(), typeOfHashMap); + dataTypeDefinitionMap = gson.fromJson(readDataTypeDefinitionFile(), typeOfHashMap); DataTypeDefinition dataTypeDefinition = dataTypeDefinitionMap.get("org.openecomp.datatypes.heat.network" + ".neutron.Subnet"); @@ -448,19 +544,8 @@ public class PropertyValueConstraintValidationUtilTest { listProperty.getSchema().setProperty(definition); } - private static String readFile() { - StringBuilder stringBuilder = new StringBuilder(); - File file = new File(Objects.requireNonNull( - PropertyValueConstraintValidationUtilTest.class.getClassLoader().getResource("types/datatypes" - + "/constraintTest.json")).getFile()); - Path logFile = Paths.get(file.getAbsolutePath()); - try (BufferedReader reader = Files.newBufferedReader(logFile, StandardCharsets.UTF_8)) { - reader.lines().forEach(stringBuilder::append); - } catch (Exception e) { - Assert.fail(e.getMessage()); - e.printStackTrace(); - } - return stringBuilder.toString(); + private static String readDataTypeDefinitionFile() throws IOException { + return Files.readString(Paths.get("src/test/resources/types/datatypes/constraintTest.json")); } } -- cgit 1.2.3-korg