diff options
author | 2018-03-04 14:53:33 +0200 | |
---|---|---|
committer | 2018-03-07 13:19:05 +0000 | |
commit | a5445100050e49e83f73424198d73cd72d672a4d (patch) | |
tree | cacf4df817df31be23e4e790d1dda857bdae061e /catalog-dao/src/test/java/org/openecomp | |
parent | 51157f92c21976cba4914c378aaa3cba49826931 (diff) |
Sync Integ to Master
Change-Id: I71e3acc26fa612127756ac04073a522b9cc6cd74
Issue-ID: SDC-977
Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
Diffstat (limited to 'catalog-dao/src/test/java/org/openecomp')
7 files changed, 155 insertions, 479 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/jsongraph/TitanDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/jsongraph/TitanDaoTest.java deleted file mode 100644 index 0f6faaa02c..0000000000 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/jsongraph/TitanDaoTest.java +++ /dev/null @@ -1,291 +0,0 @@ -package org.openecomp.sdc.be.dao.jsongraph; - -import java.util.List; -import java.util.Map; - -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.Test; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.dao.titan.TitanGraphClient; -import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; - -import com.thinkaurelius.titan.core.TitanGraph; - -import fj.data.Either; - - -public class TitanDaoTest { - - private TitanDao createTestSubject() { - return new TitanDao(new TitanGraphClient()); - } - - - @Test - public void testCommit() throws Exception { - TitanDao testSubject; - TitanOperationStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.commit(); - } - - - @Test - public void testRollback() throws Exception { - TitanDao testSubject; - TitanOperationStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.rollback(); - } - - - @Test - public void testGetGraph() throws Exception { - TitanDao testSubject; - Either<TitanGraph, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getGraph(); - } - - - - - - @Test - public void testGetVertexByPropertyAndLabel() throws Exception { - TitanDao testSubject; - GraphPropertyEnum name = null; - Object value = null; - VertexTypeEnum label = null; - Either<GraphVertex, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVertexByPropertyAndLabel(name, value, label); - } - - - @Test - public void testGetVertexByPropertyAndLabel_1() throws Exception { - TitanDao testSubject; - GraphPropertyEnum name = null; - Object value = null; - VertexTypeEnum label = null; - JsonParseFlagEnum parseFlag = null; - Either<GraphVertex, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVertexByPropertyAndLabel(name, value, label, parseFlag); - } - - - @Test - public void testGetVertexById() throws Exception { - TitanDao testSubject; - String id = ""; - Either<GraphVertex, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getVertexById(id); - } - - - - - - - - - - - - - - - - - - @Test - public void testGetByCriteria() throws Exception { - TitanDao testSubject; - VertexTypeEnum type = null; - Map<GraphPropertyEnum, Object> props = null; - Either<List<GraphVertex>, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getByCriteria(type, props); - } - - - @Test - public void testGetByCriteria_1() throws Exception { - TitanDao testSubject; - VertexTypeEnum type = null; - Map<GraphPropertyEnum, Object> props = null; - JsonParseFlagEnum parseFlag = null; - Either<List<GraphVertex>, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getByCriteria(type, props, parseFlag); - } - - - @Test - public void testGetByCriteria_2() throws Exception { - TitanDao testSubject; - VertexTypeEnum type = null; - Map<GraphPropertyEnum, Object> props = null; - Map<GraphPropertyEnum, Object> hasNotProps = null; - JsonParseFlagEnum parseFlag = null; - Either<List<GraphVertex>, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getByCriteria(type, props, hasNotProps, parseFlag); - } - - - - - - @Test - public void testGetChildVertex() throws Exception { - TitanDao testSubject; - GraphVertex parentVertex = null; - EdgeLabelEnum edgeLabel = null; - JsonParseFlagEnum parseFlag = null; - Either<GraphVertex, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getChildVertex(parentVertex, edgeLabel, parseFlag); - } - - - @Test - public void testGetParentVertex() throws Exception { - TitanDao testSubject; - GraphVertex parentVertex = null; - EdgeLabelEnum edgeLabel = null; - JsonParseFlagEnum parseFlag = null; - Either<GraphVertex, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getParentVertex(parentVertex, edgeLabel, parseFlag); - } - - - @Test - public void testGetChildrenVertecies() throws Exception { - TitanDao testSubject; - GraphVertex parentVertex = null; - EdgeLabelEnum edgeLabel = null; - JsonParseFlagEnum parseFlag = null; - Either<List<GraphVertex>, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getChildrenVertecies(parentVertex, edgeLabel, parseFlag); - } - - - @Test - public void testGetParentVertecies() throws Exception { - TitanDao testSubject; - GraphVertex parentVertex = null; - EdgeLabelEnum edgeLabel = null; - JsonParseFlagEnum parseFlag = null; - Either<List<GraphVertex>, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getParentVertecies(parentVertex, edgeLabel, parseFlag); - } - - - - - - - - - - - - - - - - - - - - - - - - - - - @Test - public void testUpdateVertexMetadataPropertiesWithJson() throws Exception { - TitanDao testSubject; - Vertex vertex = null; - Map<GraphPropertyEnum, Object> properties = null; - TitanOperationStatus result; - - // default test - testSubject = createTestSubject(); - result = testSubject.updateVertexMetadataPropertiesWithJson(vertex, properties); - } - - - - - - - - @Test - public void testGetProperty_1() throws Exception { - TitanDao testSubject; - Edge edge = null; - EdgePropertyEnum key = null; - Object result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getProperty(edge, key); - } - - - - - @Test - public void testGetBelongingEdgeByCriteria_1() throws Exception { - TitanDao testSubject; - String parentId = ""; - EdgeLabelEnum label = null; - Map<GraphPropertyEnum, Object> properties = null; - Either<Edge, TitanOperationStatus> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getBelongingEdgeByCriteria(parentId, label, properties); - } -}
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/rest/RestConfigurationInfoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/rest/RestConfigurationInfoTest.java deleted file mode 100644 index 63091f4412..0000000000 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/rest/RestConfigurationInfoTest.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.openecomp.sdc.be.dao.rest; - -import org.junit.Test; - - -public class RestConfigurationInfoTest { - - private RestConfigurationInfo createTestSubject() { - return new RestConfigurationInfo(); - } - - - @Test - public void testGetReadTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getReadTimeoutInSec(); - } - - - @Test - public void testSetReadTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer readTimeoutInSec = 0; - - // default test - testSubject = createTestSubject(); - testSubject.setReadTimeoutInSec(readTimeoutInSec); - } - - - @Test - public void testGetIgnoreCertificate() throws Exception { - RestConfigurationInfo testSubject; - Boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getIgnoreCertificate(); - } - - - @Test - public void testSetIgnoreCertificate() throws Exception { - RestConfigurationInfo testSubject; - Boolean ignoreCertificate = null; - - // default test - testSubject = createTestSubject(); - testSubject.setIgnoreCertificate(ignoreCertificate); - } - - - @Test - public void testGetConnectionPoolSize() throws Exception { - RestConfigurationInfo testSubject; - Integer result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getConnectionPoolSize(); - } - - - @Test - public void testSetConnectionPoolSize() throws Exception { - RestConfigurationInfo testSubject; - Integer connectionPoolSize = 0; - - // default test - testSubject = createTestSubject(); - testSubject.setConnectionPoolSize(connectionPoolSize); - } - - - @Test - public void testGetConnectTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getConnectTimeoutInSec(); - } - - - @Test - public void testSetConnectTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer connectTimeoutInSec = 0; - - // default test - testSubject = createTestSubject(); - testSubject.setConnectTimeoutInSec(connectTimeoutInSec); - } - - - @Test - public void testGetSocketTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getSocketTimeoutInSec(); - } - - - @Test - public void testSetSocketTimeoutInSec() throws Exception { - RestConfigurationInfo testSubject; - Integer socketTimeoutInSec = 0; - - // default test - testSubject = createTestSubject(); - testSubject.setSocketTimeoutInSec(socketTimeoutInSec); - } - - - @Test - public void testToString() throws Exception { - RestConfigurationInfo testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.toString(); - } -}
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java index cac429c6fb..e02611a5a4 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/JsonParserUtilsTests.java @@ -7,9 +7,9 @@ * 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. @@ -20,54 +20,69 @@ package org.openecomp.sdc.be.resources; -import java.io.IOException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.google.common.collect.ImmutableList; +import org.junit.Test; +import org.openecomp.sdc.be.dao.jsongraph.utils.JsonParserUtils; +import org.openecomp.sdc.be.datatypes.elements.CapabilityDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition; + import java.util.HashMap; +import java.util.List; import java.util.Map; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.map.JsonMappingException; -import org.junit.Test; -import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.openecomp.sdc.be.utils.FixtureHelpers.fixture; +import static org.openecomp.sdc.be.utils.JsonTester.testJsonMap; public class JsonParserUtilsTests { - @Test - public void testProperties() throws JsonGenerationException, JsonMappingException, IOException { - PropertyDataDefinition dataDefinition = new PropertyDataDefinition(); - dataDefinition.setName("myName"); - dataDefinition.setDescription("description"); - dataDefinition.setDefaultValue("default11"); - SchemaDefinition entrySchema = new SchemaDefinition(); - PropertyDataDefinition property = new PropertyDataDefinition(); - property.setName("name12"); - property.setType("string"); - entrySchema.setProperty(property); - Map<String, PropertyDataDefinition> properties = new HashMap<>(); - properties.put("key1", property); - properties.put("key2", property); - - entrySchema.setProperties(properties ); - dataDefinition.setSchema(entrySchema); - - Map<String, PropertyDataDefinition> map = new HashMap<>(); - map.put("prop", dataDefinition); - -// String jsonstring = JsonParserUtils.jsonToString(map); - -// Map<String, PropertyDataDefinition> parseToJson = JsonParserUtils.parseToJson(jsonstring, PropertyDataDefinition.class); -// Map<String, PropertyDataDefinition> parseToJson; -// TypeReference<Map<String, PropertyDataDefinition>> typeRef = new TypeReference<Map<String, PropertyDataDefinition>>() { -// }; -// ObjectMapper mapper = new ObjectMapper(); -// try { -// parseToJson = mapper.readValue(jsonstring, typeRef); -// } catch (Exception e) { -//// logger.debug("Failed to parse json {}", json, e); -// } - -// System.out.println(parseToJson); - - } + private static final String FIXTURE_PATH = "fixtures/ListCapabilityDataDefinition.json"; + + @Test + public void testToMap() { + String json = fixture(FIXTURE_PATH); + Map<String, ListCapabilityDataDefinition> actual = JsonParserUtils.toMap(json, ListCapabilityDataDefinition.class); + Map<String, ListCapabilityDataDefinition> expected = buildMap(); + assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); + } + + @Test + public void testJacksonFasterXml() { + ObjectMapper mapper = new ObjectMapper() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + assertThatCode(() -> testJsonMap(buildMap(), ListCapabilityDataDefinition.class, FIXTURE_PATH, mapper)) + .doesNotThrowAnyException(); + } + + private Map<String, ListCapabilityDataDefinition> buildMap() { + Map<String, ListCapabilityDataDefinition> map = new HashMap<>(); + map.put("org.openecomp.capabilities.Forwarder", buildListCapabilityDataDefinition()); + return map; + } + + private ListCapabilityDataDefinition buildListCapabilityDataDefinition() { + CapabilityDataDefinition dataDefinition = new CapabilityDataDefinition(); + dataDefinition.setName("forwarder"); + dataDefinition.setType("org.openecomp.capabilities.Forwarder"); + dataDefinition.setUniqueId("capability.deb142fd-95eb-48f7-99ae-81ab09466b1e.forwarder"); + dataDefinition.setOwnerId("deb142fd-95eb-48f7-99ae-81ab09466b1e"); + dataDefinition.setMinOccurrences("1"); + dataDefinition.setLeftOccurrences("UNBOUNDED"); + dataDefinition.setMaxOccurrences("UNBOUNDED"); + dataDefinition.setCapabilitySources(buildCapabilitySources()); + + return new ListCapabilityDataDefinition(ImmutableList.of(dataDefinition)); + } + private List<String> buildCapabilitySources() { + return ImmutableList.of( + "org.openecomp.resource.cp.nodes.network.Port", + "org.openecomp.resource.cp.v2.extCP", + "org.openecomp.resource.cp.v2.extContrailCP"); + } } diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java index 6dede29977..97ccb43959 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/TitanGenericDaoTest.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.resources; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -72,6 +73,8 @@ import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.TitanVertex; import com.thinkaurelius.titan.core.attribute.Text; +import com.thinkaurelius.titan.core.schema.ConsistencyModifier; +import com.thinkaurelius.titan.core.schema.TitanGraphIndex; import com.thinkaurelius.titan.core.schema.TitanManagement; import fj.data.Either; diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/PolicyTypeDataTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/PolicyTypeDataTest.java index 840a55b336..afd58c5994 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/PolicyTypeDataTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/resources/data/PolicyTypeDataTest.java @@ -55,15 +55,4 @@ public class PolicyTypeDataTest { testSubject = createTestSubject(); result = testSubject.getPolicyTypeDataDefinition(); } - - - @Test - public void testSetPolicyTypeDataDefinition() throws Exception { - PolicyTypeData testSubject; - PolicyTypeDataDefinition policyTypeDataDefinition = null; - - // default test - testSubject = createTestSubject(); - testSubject.setPolicyTypeDataDefinition(policyTypeDataDefinition); - } }
\ No newline at end of file diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/FixtureHelpers.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/FixtureHelpers.java new file mode 100644 index 0000000000..1992b8043c --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/FixtureHelpers.java @@ -0,0 +1,50 @@ +package org.openecomp.sdc.be.utils; + +import java.io.IOException; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +import com.google.common.io.Resources; + +/** + * A set of helper method for fixture files. + */ +public class FixtureHelpers { + + private FixtureHelpers() { + // singleton + } + + /** + * Reads the given fixture file from the classpath (e. g. {@code src/test/resources}) + * and returns its contents as a UTF-8 string. + * + * @param filename the filename of the fixture file + * @return the contents of {@code src/test/resources/{filename}} + * @throws IllegalArgumentException if an I/O error occurs. + */ + public static String fixture(String filename) { + return fixture(filename, StandardCharsets.UTF_8); + } + + /** + * Reads the given fixture file from the classpath (e. g. {@code src/test/resources}) + * and returns its contents as a string. + * + * @param filename the filename of the fixture file + * @param charset the character set of {@code filename} + * @return the contents of {@code src/test/resources/{filename}} + * @throws IllegalArgumentException if an I/O error occurs. + */ + private static String fixture(String filename, Charset charset) { + try { + URL url = Resources.getResource(filename); + String text = Resources.toString(url, charset); + return text.trim(); + } + catch (IOException e) { + throw new IllegalArgumentException(e); + } + } +} diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/JsonTester.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/JsonTester.java new file mode 100644 index 0000000000..4f1b2f24bc --- /dev/null +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/utils/JsonTester.java @@ -0,0 +1,42 @@ +package org.openecomp.sdc.be.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.type.MapType; +import com.fasterxml.jackson.databind.type.TypeFactory; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.openecomp.sdc.be.utils.FixtureHelpers.fixture; + +public class JsonTester { + private static final ObjectMapper MAPPER = new ObjectMapper(); + + public JsonTester() { + + } + + public static <T> void testJson(T object, String fixturePath) throws Exception { + testJson(object, fixturePath, MAPPER); + } + + @SuppressWarnings("unchecked") + public static <T> void testJson(T object, String fixturePath, ObjectMapper mapper) throws Exception { + T expectedObject = (T) mapper.readValue(fixture(fixturePath), object.getClass()); + String expectedJson = mapper.writeValueAsString(expectedObject); + String actualJson = mapper.writeValueAsString(object); + + assertThat(actualJson).isEqualTo(expectedJson); + } + + @SuppressWarnings("unchecked") + public static <T> void testJsonMap(Map<String, T> map, Class<T> valueClass, String fixturePath, ObjectMapper mapper) throws Exception { + MapType mapType = TypeFactory.defaultInstance().constructMapType(Map.class, String.class, valueClass); + Map<String, T> expectedObject = mapper.readValue(fixture(fixturePath), mapType); + String expectedJson = mapper.writeValueAsString(expectedObject); + + String actualJson = mapper.writeValueAsString(map); + + assertThat(actualJson).isEqualTo(expectedJson); + } +}
\ No newline at end of file |