summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/crud/CrudApplication.java16
-rw-r--r--src/main/java/org/onap/crud/SchemaIngestConfiguration.java33
-rw-r--r--src/main/java/org/onap/crud/dao/champ/ChampDao.java5
-rw-r--r--src/main/java/org/onap/crud/service/AbstractGraphDataService.java11
-rw-r--r--src/main/java/org/onap/crud/util/CrudServiceUtil.java52
-rw-r--r--src/main/java/org/onap/schema/EdgeRulesLoader.java22
-rw-r--r--src/main/java/org/onap/schema/OxmModelLoader.java30
-rw-r--r--src/main/resources/application.properties2
-rw-r--r--src/test/java/org/onap/crud/OXMModelLoaderSetup.java14
-rw-r--r--src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java2
-rw-r--r--src/test/java/org/onap/crud/service/ChampDaoMockTest.java285
-rw-r--r--src/test/java/org/onap/schema/validation/MultiplicityValidatorTest.java7
12 files changed, 248 insertions, 231 deletions
diff --git a/src/main/java/org/onap/crud/CrudApplication.java b/src/main/java/org/onap/crud/CrudApplication.java
index b2b2611..b91794d 100644
--- a/src/main/java/org/onap/crud/CrudApplication.java
+++ b/src/main/java/org/onap/crud/CrudApplication.java
@@ -22,18 +22,14 @@ package org.onap.crud;
import java.util.Collections;
import java.util.HashMap;
-
import javax.annotation.PostConstruct;
-
import org.eclipse.jetty.util.security.Password;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
-import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
import org.springframework.core.env.Environment;
-
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
@@ -47,7 +43,6 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/
@SpringBootApplication
@EnableSwagger2
-@Import({SchemaIngestConfiguration.class, SchemaLoaderConfiguration.class})
@ImportResource({"file:${SERVICE_BEANS}/*.xml"})
public class CrudApplication extends SpringBootServletInitializer{// NOSONAR
@Autowired
@@ -59,8 +54,13 @@ public class CrudApplication extends SpringBootServletInitializer{// NOSONAR
throw new RuntimeException("Env property KEY_STORE_PASSWORD not set");
}
HashMap<String, Object> props = new HashMap<>();
- props.put("server.ssl.key-store-password", Password.deobfuscate(keyStorePassword));
- new CrudApplication().configure(new SpringApplicationBuilder(SchemaIngestConfiguration.class, SchemaLoaderConfiguration.class).child(CrudApplication.class).properties(props)).run(args);
+ String deobfuscatedKeyStorePassword = Password.deobfuscate(keyStorePassword);
+ props.put("server.ssl.key-store-password", deobfuscatedKeyStorePassword);
+ props.put("schema.service.ssl.key-store-password", deobfuscatedKeyStorePassword);
+ props.put("schema.service.ssl.trust-store-password", deobfuscatedKeyStorePassword);
+ new CrudApplication()
+ .configure(new SpringApplicationBuilder(CrudApplication.class).properties(props))
+ .run(args);
}
/**
@@ -85,8 +85,6 @@ public class CrudApplication extends SpringBootServletInitializer{// NOSONAR
public static final ApiInfo DEFAULT_API_INFO = new ApiInfo("AAI NCSO Adapter Service", "AAI NCSO Adapter Service.",
"1.0", "urn:tos", DEFAULT_CONTACT, "Apache 2.0", "API license URL", Collections.emptyList());
-
-
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(DEFAULT_API_INFO).select().paths(PathSelectors.any())
.apis(RequestHandlerSelectors.basePackage("org.onap.crud")).build();
diff --git a/src/main/java/org/onap/crud/SchemaIngestConfiguration.java b/src/main/java/org/onap/crud/SchemaIngestConfiguration.java
index ee050dd..ca76dbd 100644
--- a/src/main/java/org/onap/crud/SchemaIngestConfiguration.java
+++ b/src/main/java/org/onap/crud/SchemaIngestConfiguration.java
@@ -26,37 +26,44 @@ import org.onap.aai.setup.AAIConfigTranslator;
import org.onap.aai.setup.ConfigTranslator;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersions;
+import org.onap.aai.setup.Translator;
+import org.onap.schema.EdgePropsConfiguration;
+import org.onap.schema.EdgeRulesLoader;
+import org.onap.schema.OxmModelLoader;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
@Configuration
+@ComponentScan(basePackages = {"org.onap.aai.config", "org.onap.aai.setup"})
@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
+@PropertySource(value = "file:${edgeprops.ingest.file}", ignoreResourceNotFound = true)
public class SchemaIngestConfiguration {
- @Bean
- public SchemaVersions schemaVersions() {
- return new SchemaVersions();
- }
+ @Autowired
+ private Translator translator;
@Bean
- public SchemaLocationsBean schemaLocationsBean() {
- return new SchemaLocationsBean();
+ public OxmModelLoader oxmModelLoader(NodeIngestor nodeIngestor) {
+ return new OxmModelLoader(translator, nodeIngestor );
}
@Bean
- public ConfigTranslator configTranslator() {
- return new AAIConfigTranslator(schemaLocationsBean(), schemaVersions());
+ public EdgeRulesLoader edgeRulesLoader(EdgeIngestor edgeIngestor) {
+ return new EdgeRulesLoader(translator, edgeIngestor, edgePropsConfiguration() );
}
@Bean
- public NodeIngestor nodeIngestor() {
- return new NodeIngestor(configTranslator());
+ public EdgePropsConfiguration edgePropsConfiguration() {
+ return new EdgePropsConfiguration();
}
@Bean
- public EdgeIngestor edgeIngestor() {
- return new EdgeIngestor(configTranslator(), schemaVersions());
+ @ConditionalOnExpression("'${schema.translator.list}'.contains('config')")
+ public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean, SchemaVersions schemaVersions) {
+ return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
}
-
} \ No newline at end of file
diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
index 81980cc..8563807 100644
--- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java
+++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
@@ -35,7 +35,6 @@ import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.eclipse.jetty.util.security.Password;
import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.logging.LoggingContext;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.aai.restclient.enums.RestAuthenticationMode;
@@ -411,7 +410,7 @@ public class ChampDao implements GraphDao {
String url = baseTransactionUrl + "/" + id;
Map<String, List<String>> headers = new HashMap<>();
headers.put(HEADER_FROM_APP, Arrays.asList("Gizmo"));
- headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(LoggingContext.LoggingField.REQUEST_ID.toString())));
+ headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(MdcContext.MDC_REQUEST_ID)));
OperationResult getResult = client.get(url, headers, MediaType.APPLICATION_JSON_TYPE);
@@ -550,7 +549,7 @@ public class ChampDao implements GraphDao {
throw createErrorException(getResult, javax.ws.rs.core.Response.Status.NOT_FOUND, "No edge with id " + id + " found in graph");
}
}
-
+
@Override
public Edge getEdge(String id) throws CrudException {
String url = baseRelationshipUrl + "/" + id;
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
index db4c4d8..14ea242 100644
--- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
@@ -20,6 +20,10 @@
*/
package org.onap.crud.service;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.reflect.TypeToken;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -28,6 +32,7 @@ import java.util.Set;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response.Status;
+import net.dongliu.gson.GsonJava8TypeAdapterFactory;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.crud.dao.GraphDao;
@@ -44,18 +49,12 @@ import org.onap.crud.parser.util.EdgePayloadUtil;
import org.onap.crud.util.CrudServiceUtil;
import org.onap.schema.validation.OxmModelValidator;
import org.onap.schema.validation.RelationshipSchemaValidator;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.reflect.TypeToken;
-import net.dongliu.gson.GsonJava8TypeAdapterFactory;
public abstract class AbstractGraphDataService {
protected GraphDao daoForGet;
protected GraphDao dao;
public AbstractGraphDataService() throws CrudException {
- CrudServiceUtil.loadModels();
}
public ImmutablePair<EntityTag, String> getEdge(String version, String id, String type, Map<String, String> queryParams) throws CrudException {
diff --git a/src/main/java/org/onap/crud/util/CrudServiceUtil.java b/src/main/java/org/onap/crud/util/CrudServiceUtil.java
index 5eeb38e..2441776 100644
--- a/src/main/java/org/onap/crud/util/CrudServiceUtil.java
+++ b/src/main/java/org/onap/crud/util/CrudServiceUtil.java
@@ -20,6 +20,9 @@
*/
package org.onap.crud.util;
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonPrimitive;
import java.util.AbstractMap;
import java.util.HashSet;
import java.util.Map;
@@ -29,22 +32,18 @@ import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
-import org.onap.aai.db.props.AAIProperties;
import org.onap.crud.exception.CrudException;
import org.onap.crud.parser.EdgePayload;
import org.onap.crud.parser.util.EdgePayloadUtil;
import org.onap.schema.EdgeRulesLoader;
-import org.onap.schema.OxmModelLoader;
import org.onap.schema.RelationshipSchema;
-import com.google.gson.Gson;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-
public class CrudServiceUtil {
private static Gson gson = new Gson();
-
+ public static final java.lang.String LAST_MOD_SOURCE_OF_TRUTH = "last-mod-source-of-truth";
+ public static final java.lang.String SOURCE_OF_TRUTH = "source-of-truth";
+
@SuppressWarnings({"unchecked", "rawtypes"})
public static Object validateFieldType(String value, Class clazz) throws CrudException {
try {
@@ -76,16 +75,6 @@ public class CrudServiceUtil {
}
}
- public static void loadModels() throws CrudException {
- // load the schemas
- try {
- OxmModelLoader.loadModels();
- EdgeRulesLoader.loadModels ();
- } catch (Exception e) {
- throw new CrudException(e);
- }
- }
-
/**
* This method will merge header property from app id in request payload if not already populated
* @param propertiesFromRequest
@@ -96,22 +85,22 @@ public class CrudServiceUtil {
@SuppressWarnings("unchecked")
public static JsonElement mergeHeaderInFoToPayload(JsonElement propertiesFromRequest, HttpHeaders headers,
boolean isAdd) {
- String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
+ String sourceOfTruth = headers.getRequestHeaders().getFirst("X-FromAppId");
Set<Map.Entry<String, JsonElement>> properties = new HashSet<Map.Entry<String, JsonElement>>();
properties.addAll(propertiesFromRequest.getAsJsonObject().entrySet());
-
+
Set<String> propertyKeys = new HashSet<String>();
for(Map.Entry<String, JsonElement> property : properties) {
propertyKeys.add(property.getKey());
}
-
- if(!propertyKeys.contains(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH)) {
- properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(AAIProperties.LAST_MOD_SOURCE_OF_TRUTH,
+
+ if(!propertyKeys.contains(LAST_MOD_SOURCE_OF_TRUTH)) {
+ properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(LAST_MOD_SOURCE_OF_TRUTH,
(new JsonPrimitive(sourceOfTruth))));
}
-
- if(isAdd && !propertyKeys.contains(AAIProperties.SOURCE_OF_TRUTH)) {
- properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(AAIProperties.SOURCE_OF_TRUTH,
+
+ if(isAdd && !propertyKeys.contains(SOURCE_OF_TRUTH)) {
+ properties.add(new AbstractMap.SimpleEntry<String, JsonElement>(SOURCE_OF_TRUTH,
(new JsonPrimitive(sourceOfTruth))));
}
@@ -144,23 +133,22 @@ public class CrudServiceUtil {
public static String determineEdgeType(EdgePayload payload, String version) throws CrudException {
RelationshipSchema schema = EdgeRulesLoader.getSchemaForVersion(version);
-
+
if (payload.getSource() == null || payload.getTarget() == null) {
throw new CrudException("Source/Target not specified", Status.BAD_REQUEST);
}
-
- Set<String> edgeTypes = schema.getValidRelationTypes(EdgePayloadUtil.getVertexNodeType(payload.getSource()),
+
+ Set<String> edgeTypes = schema.getValidRelationTypes(EdgePayloadUtil.getVertexNodeType(payload.getSource()),
EdgePayloadUtil.getVertexNodeType(payload.getTarget()));
-
+
if (edgeTypes.size() == 0) {
throw new CrudException("No valid relationship types from " + payload.getSource() + " to " + payload.getTarget(), Status.BAD_REQUEST);
}
-
+
if (edgeTypes.size() > 1) {
throw new CrudException("Multiple possible relationship types from " + payload.getSource() + " to " + payload.getTarget(), Status.BAD_REQUEST);
}
-
+
return edgeTypes.iterator().next();
}
-
}
diff --git a/src/main/java/org/onap/schema/EdgeRulesLoader.java b/src/main/java/org/onap/schema/EdgeRulesLoader.java
index 2c139a7..47be12b 100644
--- a/src/main/java/org/onap/schema/EdgeRulesLoader.java
+++ b/src/main/java/org/onap/schema/EdgeRulesLoader.java
@@ -32,6 +32,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import javax.annotation.PostConstruct;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.io.IOUtils;
@@ -39,8 +40,8 @@ import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.edges.EdgeRule;
import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException;
-import org.onap.aai.setup.ConfigTranslator;
import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.Translator;
import org.onap.crud.exception.CrudException;
import org.onap.crud.logging.CrudServiceMsgs;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,8 +49,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.google.common.collect.Multimap;
public class EdgeRulesLoader {
-
- private static ConfigTranslator configTranslator;
+
+ private static Translator translator;
private static EdgeIngestor edgeIngestor;
private static EdgePropsConfiguration edgePropsConfiguration;
@@ -67,14 +68,19 @@ public class EdgeRulesLoader {
LoggerFactory.getInstance ().getLogger ( EdgeRulesLoader.class.getName () );
private EdgeRulesLoader () { }
-
+
@Autowired
- public EdgeRulesLoader(ConfigTranslator configTranslator, EdgeIngestor edgeIngestor, EdgePropsConfiguration edgePropsConfiguration) {
- EdgeRulesLoader.configTranslator = configTranslator;
+ public EdgeRulesLoader(Translator translator, EdgeIngestor edgeIngestor, EdgePropsConfiguration edgePropsConfiguration) {
+ EdgeRulesLoader.translator = translator;
EdgeRulesLoader.edgeIngestor = edgeIngestor;
EdgeRulesLoader.edgePropsConfiguration = edgePropsConfiguration;
}
+ @PostConstruct
+ public void init() throws CrudException {
+ EdgeRulesLoader.loadModels();
+ }
+
/**
* Finds all DB Edge Rules and Edge Properties files for all OXM models.
*
@@ -89,7 +95,7 @@ public class EdgeRulesLoader {
for (String version : OxmModelLoader.getLoadedOXMVersions()) {
try {
- SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream()
+ SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream()
.filter(s -> s.toString().equalsIgnoreCase(version)).findAny().orElse(null);
loadModel(schemaVersion, edgeIngestor, propFiles);
} catch (IOException | EdgeRuleNotFoundException e) {
@@ -112,7 +118,7 @@ public class EdgeRulesLoader {
}
try {
- SchemaVersion schemaVersion = configTranslator.getSchemaVersions().getVersions().stream()
+ SchemaVersion schemaVersion = translator.getSchemaVersions().getVersions().stream()
.filter(s -> s.toString().equalsIgnoreCase(v)).findAny().orElse(null);
loadModel(schemaVersion, edgeIngestor, propFiles);
diff --git a/src/main/java/org/onap/schema/OxmModelLoader.java b/src/main/java/org/onap/schema/OxmModelLoader.java
index 12f8f09..fb41fc9 100644
--- a/src/main/java/org/onap/schema/OxmModelLoader.java
+++ b/src/main/java/org/onap/schema/OxmModelLoader.java
@@ -29,14 +29,15 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.annotation.PostConstruct;
import javax.ws.rs.core.Response.Status;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.internal.oxm.mappings.Descriptor;
import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.nodes.NodeIngestor;
-import org.onap.aai.setup.ConfigTranslator;
import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.Translator;
import org.onap.crud.exception.CrudException;
import org.onap.crud.logging.CrudServiceMsgs;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,9 +46,9 @@ import org.springframework.stereotype.Component;
@Component
public class OxmModelLoader {
- private static ConfigTranslator configTranslator;
+ private static Translator translator;
private static NodeIngestor nodeIngestor;
-
+
private static Map<String, DynamicJAXBContext> versionContextMap = new ConcurrentHashMap<>();
private static Map<String, HashMap<String, DynamicType>> xmlElementLookup = new ConcurrentHashMap<>();
@@ -57,13 +58,18 @@ public class OxmModelLoader {
LoggerFactory.getInstance().getLogger(OxmModelLoader.class.getName());
private OxmModelLoader() { }
-
+
@Autowired
- public OxmModelLoader(ConfigTranslator configTranslator, NodeIngestor nodeIngestor) {
- OxmModelLoader.configTranslator = configTranslator;
+ public OxmModelLoader(Translator translator, NodeIngestor nodeIngestor) {
+ OxmModelLoader.translator = translator;
OxmModelLoader.nodeIngestor = nodeIngestor;
}
+ @PostConstruct
+ public void init() throws CrudException {
+ OxmModelLoader.loadModels();
+ }
+
/**
* Finds all OXM model files
*
@@ -77,7 +83,7 @@ public class OxmModelLoader {
logger.debug("Loading OXM Models");
}
- for (SchemaVersion oxmVersion : configTranslator.getSchemaVersions().getVersions()) {
+ for (SchemaVersion oxmVersion : translator.getSchemaVersions().getVersions()) {
DynamicJAXBContext jaxbContext = nodeIngestor.getContextForVersion(oxmVersion);
if (jaxbContext != null) {
loadModel(oxmVersion.toString(), jaxbContext);
@@ -166,8 +172,8 @@ public class OxmModelLoader {
public static void setVersionContextMap(Map<String, DynamicJAXBContext> versionContextMap) {
OxmModelLoader.versionContextMap = versionContextMap;
}
-
-
+
+
public static void loadXmlLookupMap(String version, DynamicJAXBContext jaxbContext ) {
@SuppressWarnings("rawtypes")
@@ -183,8 +189,8 @@ public class OxmModelLoader {
}
xmlElementLookup.put(version, types);
}
-
-
+
+
public static DynamicType getDynamicTypeForVersion(String version, String type) throws CrudException {
DynamicType dynamicType;
@@ -220,7 +226,7 @@ public class OxmModelLoader {
return dynamicType;
}
-
+
/**
* Retrieves the list of all Loaded OXM versions.
*
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 049a2d9..2b1f302 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,3 +1,5 @@
+spring.application.name=gizmo
+
server.port=9520
SERVICE_BEANS=dynamic/conf
diff --git a/src/test/java/org/onap/crud/OXMModelLoaderSetup.java b/src/test/java/org/onap/crud/OXMModelLoaderSetup.java
index 0b34048..005a393 100644
--- a/src/test/java/org/onap/crud/OXMModelLoaderSetup.java
+++ b/src/test/java/org/onap/crud/OXMModelLoaderSetup.java
@@ -22,8 +22,9 @@ package org.onap.crud;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
-
+import java.util.Set;
import org.junit.Before;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -33,6 +34,7 @@ import org.onap.aai.setup.AAIConfigTranslator;
import org.onap.aai.setup.SchemaLocationsBean;
import org.onap.aai.setup.SchemaVersion;
import org.onap.aai.setup.SchemaVersions;
+import org.onap.aai.setup.Translator;
import org.onap.schema.EdgePropsConfiguration;
import org.onap.schema.EdgeRulesLoader;
import org.onap.schema.OxmModelLoader;
@@ -67,12 +69,16 @@ public class OXMModelLoaderSetup {
Mockito.when(schemaLocationsBean.getNodesInclusionPattern()).thenReturn(Arrays.asList(".*oxm(.*).xml"));
Mockito.when(schemaLocationsBean.getEdgesInclusionPattern()).thenReturn(Arrays.asList("DbEdgeRules_.*.json"));
Mockito.when(schemaLocationsBean.getNodeDirectory()).thenReturn("src/test/resources/multi-oxm/");
- Mockito.when(schemaLocationsBean.getEdgeDirectory()).thenReturn("src/test/resources/rules");
+ Mockito.when(schemaLocationsBean.getEdgeDirectory()).thenReturn("src/test/resources/rules/");
Mockito.when(edgePropsConfiguration.getEdgePropsDir()).thenReturn("src/test/resources/edgeProps/");
AAIConfigTranslator aaiConfigTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
- NodeIngestor nodeIngestor = new NodeIngestor(aaiConfigTranslator);
- EdgeIngestor edgeIngestor = new EdgeIngestor(aaiConfigTranslator, schemaVersions);
+ Set<Translator> translators = new HashSet<>();
+ translators.add(aaiConfigTranslator);
+ NodeIngestor nodeIngestor = new NodeIngestor(translators);
+ nodeIngestor.initialize();
+ EdgeIngestor edgeIngestor = new EdgeIngestor(translators);
+ edgeIngestor.initialize();
edgeRulesLoader = new EdgeRulesLoader(aaiConfigTranslator, edgeIngestor, edgePropsConfiguration);
oxmModelLoader = new OxmModelLoader(aaiConfigTranslator, nodeIngestor);
}
diff --git a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
index a5edd7c..b28ba3a 100644
--- a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
+++ b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
@@ -30,6 +30,7 @@ import org.onap.crud.event.GraphEvent.GraphEventOperation;
import org.onap.crud.event.envelope.GraphEventEnvelope;
import org.onap.crud.exception.CrudException;
import org.onap.crud.util.TestUtil;
+import org.onap.schema.EdgeRulesLoader;
import org.onap.schema.OxmModelLoader;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
@@ -51,6 +52,7 @@ public class GraphEventResponseHandlerTest extends OXMModelLoaderSetup {
System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
OxmModelLoader.loadModels();
+ EdgeRulesLoader.loadModels();
}
@Test
diff --git a/src/test/java/org/onap/crud/service/ChampDaoMockTest.java b/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
index dadf81a..01e4646 100644
--- a/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
+++ b/src/test/java/org/onap/crud/service/ChampDaoMockTest.java
@@ -22,6 +22,7 @@ package org.onap.crud.service;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -30,11 +31,9 @@ import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
-import org.onap.aai.logging.LoggingContext;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.crud.dao.champ.ChampDao;
-import org.slf4j.MDC;
public class ChampDaoMockTest {
// @formatter:off
@@ -44,7 +43,7 @@ public class ChampDaoMockTest {
"\"properties\": {" +
"\"fqdn\": \"myhost.onap.com\"," +
"\"hostname\": \"myhost\" } }";
-
+
private final String champEdge = "{" +
"\"key\": \"test-uuid\"," +
"\"type\": \"edgeType\"," +
@@ -55,154 +54,154 @@ public class ChampDaoMockTest {
"\"target\": {" +
"\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" +
" }";
-
- private final String edgePayload = "{" +
- "\"type\":\"tosca.relationships.HostedOn\"," +
- "\"properties\":{" +
- "\"prevent-delete\":\"NONE\"}," +
- "\"source\":{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"vserver\"," +
- "\"properties\":{}}," +
- "\"target\":{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"hostname\":\"myhost\"," +
+
+ private final String edgePayload = "{" +
+ "\"type\":\"tosca.relationships.HostedOn\"," +
+ "\"properties\":{" +
+ "\"prevent-delete\":\"NONE\"}," +
+ "\"source\":{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"vserver\"," +
+ "\"properties\":{}}," +
+ "\"target\":{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"hostname\":\"myhost\"," +
"\"fqdn\":\"myhost.onap.com\"}}}";
- private final String edgePayloadForPut = "{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"tosca.relationships.HostedOn\"," +
- "\"properties\":{" +
- "\"prevent-delete\":\"NONE\"}," +
- "\"source\":{" +
- "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
- "\"type\":\"vserver\"," +
- "\"properties\":{}}," +
- "\"target\":{" +
- "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
- "\"type\":\"pserver\"," +
+ private final String edgePayloadForPut = "{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"tosca.relationships.HostedOn\"," +
+ "\"properties\":{" +
+ "\"prevent-delete\":\"NONE\"}," +
+ "\"source\":{" +
+ "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
+ "\"type\":\"vserver\"," +
+ "\"properties\":{}}," +
+ "\"target\":{" +
+ "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
+ "\"type\":\"pserver\"," +
"\"properties\":{}}}";
-
- private final String edgePayloadForPatch = "{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"tosca.relationships.HostedOn\"," +
- "\"properties\":{" +
- "\"prevent-delete\":\"NONE\"}," +
- "\"source\":{" +
- "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
- "\"type\":\"vserver\"}," +
- "\"target\":{" +
- "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
+
+ private final String edgePayloadForPatch = "{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"tosca.relationships.HostedOn\"," +
+ "\"properties\":{" +
+ "\"prevent-delete\":\"NONE\"}," +
+ "\"source\":{" +
+ "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
+ "\"type\":\"vserver\"}," +
+ "\"target\":{" +
+ "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
"\"type\":\"pserver\"}}";
-
- private final String edgePayloadForPost = "{" +
- "\"type\":\"tosca.relationships.HostedOn\"," +
- "\"properties\":{" +
- "\"SVC-INFRA\":\"OUT\"," +
- "\"prevent-delete\":\"IN\"," +
- "\"delete-other-v\":\"NONE\"," +
- "\"contains-other-v\":\"NONE\"" +
- "}," +
- "\"source\":{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"vserver\"," +
- "\"properties\":{" +
- "" +
- "}" +
- "}," +
- "\"target\":{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"hostname\":\"myhost\"," +
- "\"fqdn\":\"myhost.onap.com\"" +
- "}" +
- "}" +
+
+ private final String edgePayloadForPost = "{" +
+ "\"type\":\"tosca.relationships.HostedOn\"," +
+ "\"properties\":{" +
+ "\"SVC-INFRA\":\"OUT\"," +
+ "\"prevent-delete\":\"IN\"," +
+ "\"delete-other-v\":\"NONE\"," +
+ "\"contains-other-v\":\"NONE\"" +
+ "}," +
+ "\"source\":{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"vserver\"," +
+ "\"properties\":{" +
+ "" +
+ "}" +
+ "}," +
+ "\"target\":{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"hostname\":\"myhost\"," +
+ "\"fqdn\":\"myhost.onap.com\"" +
+ "}" +
+ "}" +
"}";
-
- private final String edgePayloadForPutNoProperties = "{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"tosca.relationships.HostedOn\"," +
- "\"properties\":{" +
- "\"SVC-INFRA\":\"OUT\"," +
- "\"prevent-delete\":\"IN\"," +
- "\"delete-other-v\":\"NONE\"," +
- "\"contains-other-v\":\"NONE\"" +
- "}," +
- "\"source\":{" +
- "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
- "\"type\":\"vserver\"," +
- "\"properties\":{" +
- "" +
- "}" +
- "}," +
- "\"target\":{" +
- "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "" +
- "}" +
- "}" +
+
+ private final String edgePayloadForPutNoProperties = "{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"tosca.relationships.HostedOn\"," +
+ "\"properties\":{" +
+ "\"SVC-INFRA\":\"OUT\"," +
+ "\"prevent-delete\":\"IN\"," +
+ "\"delete-other-v\":\"NONE\"," +
+ "\"contains-other-v\":\"NONE\"" +
+ "}," +
+ "\"source\":{" +
+ "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
+ "\"type\":\"vserver\"," +
+ "\"properties\":{" +
+ "" +
+ "}" +
+ "}," +
+ "\"target\":{" +
+ "\"key\":\"1d326bc7-b985-492b-9604-0d5d1f06f908\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "" +
+ "}" +
+ "}" +
"}";
-
- private final String vertexPayload = "{" +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"hostname\":\"myhost\"," +
- "\"in-maint\":false," +
- "\"fqdn\":\"myhost.onap.com\"," +
- "\"last-mod-source-of-truth\":\"source-of-truth\"," +
- "\"source-of-truth\":\"source-of-truth\"," +
+
+ private final String vertexPayload = "{" +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"hostname\":\"myhost\"," +
+ "\"in-maint\":false," +
+ "\"fqdn\":\"myhost.onap.com\"," +
+ "\"last-mod-source-of-truth\":\"source-of-truth\"," +
+ "\"source-of-truth\":\"source-of-truth\"," +
"\"aai-node-type\":\"pserver\"}}";
-
- private final String vertexPayloadForVserver = "{" +
- "\"type\":\"vserver\"," +
- "\"properties\":{" +
- "\"in-maint\":false," +
- "\"vserver-name\":\"test-vserver\"," +
- "\"vserver-id\":\"VSER1\"," +
- "\"last-mod-source-of-truth\":\"source-of-truth\"," +
- "\"vserver-name2\":\"alt-test-vserver\"," +
- "\"source-of-truth\":\"source-of-truth\"," +
- "\"vserver-selflink\":\"http://1.2.3.4/moreInfo\"," +
- "\"is-closed-loop-disabled\":false," +
+
+ private final String vertexPayloadForVserver = "{" +
+ "\"type\":\"vserver\"," +
+ "\"properties\":{" +
+ "\"in-maint\":false," +
+ "\"vserver-name\":\"test-vserver\"," +
+ "\"vserver-id\":\"VSER1\"," +
+ "\"last-mod-source-of-truth\":\"source-of-truth\"," +
+ "\"vserver-name2\":\"alt-test-vserver\"," +
+ "\"source-of-truth\":\"source-of-truth\"," +
+ "\"vserver-selflink\":\"http://1.2.3.4/moreInfo\"," +
+ "\"is-closed-loop-disabled\":false," +
"\"aai-node-type\":\"vserver\"}}";
-
- private final String vertexPayloadForPserver = "{" +
- "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"ptnii-equip-name\":\"e-name\"," +
- "\"hostname\":\"steve-host2\"," +
- "\"equip-type\":\"server\"," +
- "\"equip-vendor\":\"HP\"," +
- "\"equip-model\":\"DL380p-nd\"," +
- "\"in-maint\":false," +
- "\"fqdn\":\"myhost.onap.net\"," +
- "\"purpose\":\"my-purpose\"," +
- "\"ipv4-oam-address\":\"1.2.3.4\"," +
- "\"last-mod-source-of-truth\":\"source-of-truth\"," +
+
+ private final String vertexPayloadForPserver = "{" +
+ "\"key\":\"50bdab41-ad1c-4d00-952c-a0aa5d827811\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"ptnii-equip-name\":\"e-name\"," +
+ "\"hostname\":\"steve-host2\"," +
+ "\"equip-type\":\"server\"," +
+ "\"equip-vendor\":\"HP\"," +
+ "\"equip-model\":\"DL380p-nd\"," +
+ "\"in-maint\":false," +
+ "\"fqdn\":\"myhost.onap.net\"," +
+ "\"purpose\":\"my-purpose\"," +
+ "\"ipv4-oam-address\":\"1.2.3.4\"," +
+ "\"last-mod-source-of-truth\":\"source-of-truth\"," +
"\"aai-node-type\":\"pserver\"}}";
-
- private final String vertexPayloadForPut = "{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"hostname\":\"myhost\"," +
- "\"in-maint\":false," +
- "\"fqdn\":\"myhost.onap.com\"," +
- "\"last-mod-source-of-truth\":\"source-of-truth\"," +
+
+ private final String vertexPayloadForPut = "{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"hostname\":\"myhost\"," +
+ "\"in-maint\":false," +
+ "\"fqdn\":\"myhost.onap.com\"," +
+ "\"last-mod-source-of-truth\":\"source-of-truth\"," +
"\"aai-node-type\":\"pserver\"}}";
-
- private final String vertexPayloadForPatch = "{" +
- "\"key\":\"test-uuid\"," +
- "\"type\":\"pserver\"," +
- "\"properties\":{" +
- "\"hostname\":\"myhost\"," +
- "\"fqdn\":\"myhost.onap.com\"," +
- "\"last-mod-source-of-truth\":\"source-of-truth\"," +
+
+ private final String vertexPayloadForPatch = "{" +
+ "\"key\":\"test-uuid\"," +
+ "\"type\":\"pserver\"," +
+ "\"properties\":{" +
+ "\"hostname\":\"myhost\"," +
+ "\"fqdn\":\"myhost.onap.com\"," +
+ "\"last-mod-source-of-truth\":\"source-of-truth\"," +
"\"aai-node-type\":\"pserver\"}}";
// @formatter:on
@@ -345,7 +344,7 @@ public class ChampDaoMockTest {
Map<String, List<String>> headers = new HashMap<>();
headers.put(HEADER_FROM_APP, Arrays.asList(FROM_APP_NAME));
- headers.put(HEADER_TRANS_ID, Arrays.asList(MDC.get(LoggingContext.LoggingField.REQUEST_ID.toString())));
+ headers.put(HEADER_TRANS_ID, Arrays.asList(HEADER_TRANS_ID_VALUE));
when(restClientMock.get(url, headers, MediaType.APPLICATION_JSON_TYPE)).thenReturn(operationResult);
}
@@ -383,7 +382,7 @@ public class ChampDaoMockTest {
operationResult.setResultCode(200);
String baseUrl = BASE_OBJECT_URL + "/" + RELATIONSHIP_SUB_URL + "/" + id;
String url;
-
+
if (txId != null) {
url = baseUrl + txId;
}
diff --git a/src/test/java/org/onap/schema/validation/MultiplicityValidatorTest.java b/src/test/java/org/onap/schema/validation/MultiplicityValidatorTest.java
index b4d5a31..64cab0d 100644
--- a/src/test/java/org/onap/schema/validation/MultiplicityValidatorTest.java
+++ b/src/test/java/org/onap/schema/validation/MultiplicityValidatorTest.java
@@ -36,7 +36,12 @@ import org.onap.crud.parser.EdgePayload;
import org.onap.schema.EdgeRulesLoader;
import org.onap.schema.validation.MultiplicityValidator.MultiplicityType;
-public class MultiplicityValidatorTest {
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class MultiplicityValidatorTest extends OXMModelLoaderSetup{
private final String postEdgePayload = "{" + "\"type\": \"tosca.relationships.HostedOn\","
+ "\"source\": \"services/inventory/v12/vserver/50bdab41-ad1c-4d00-952c-a0aa5d827811\","