summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/aai/validation/data/client/RestClient.java37
-rw-r--r--src/main/java/org/onap/aai/validation/ruledriven/rule/builtin/DataDictionary.java62
-rw-r--r--src/test/java/org/onap/aai/validation/TestApplication.java49
-rw-r--r--src/test/resources/model-validation/instance-validator/aai-environment.properties8
-rw-r--r--src/test/resources/model-validation/instance-validator/rule-data-dictionary.properties19
-rw-r--r--src/test/resources/model-validation/instance-validator/rule-indexing.properties20
-rw-r--r--src/test/resources/model-validation/instance-validator/schemaIngest.properties20
-rw-r--r--src/test/resources/model-validation/instance-validator/topics/topic-poa-audit-result.properties22
-rw-r--r--src/test/resources/model-validation/instance-validator/topics/topic-poa-rule-validation.properties23
-rw-r--r--src/test/resources/model-validation/instance-validator/validation-service-auth.properties18
10 files changed, 221 insertions, 57 deletions
diff --git a/src/main/java/org/onap/aai/validation/data/client/RestClient.java b/src/main/java/org/onap/aai/validation/data/client/RestClient.java
index d2d1196..68f1cec 100644
--- a/src/main/java/org/onap/aai/validation/data/client/RestClient.java
+++ b/src/main/java/org/onap/aai/validation/data/client/RestClient.java
@@ -1,12 +1,12 @@
-/*
+/**
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * Copyright (c) 2018-2019 European Software Marketing Ltd.
* ============================================================================
* 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
+ * 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,
@@ -16,12 +16,12 @@
* ============LICENSE_END=====================================================
*/
package org.onap.aai.validation.data.client;
-
-import com.sun.jersey.core.util.MultivaluedMapImpl;
+
import java.util.Arrays;
import java.util.UUID;
import javax.inject.Inject;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.validation.config.RestConfig;
@@ -51,23 +51,20 @@ public class RestClient {
initialiseRestClient();
}
- /**
- * Initialises the REST client
- *
- */
+ /** Initialises the REST client */
private void initialiseRestClient() {
// @formatter:off
- aaiRestClient = new org.onap.aai.restclient.client.RestClient()
- .validateServerHostname(false)
- .validateServerCertChain(true)
- .clientCertFile(APP_CONFIG_HOME + restConfig.getKeyStorePath())
- .clientCertPassword(restConfig.getKeyStorePassword())
- .trustStore(APP_CONFIG_HOME + restConfig.getTrustStorePath())
- .connectTimeoutMs(restConfig.getConnectionTimeout())
- .readTimeoutMs(restConfig.getReadTimeout());
- // @formatter:on
+ aaiRestClient = new org.onap.aai.restclient.client.RestClient()
+ .validateServerHostname(false)
+ .validateServerCertChain(true)
+ .clientCertFile(APP_CONFIG_HOME + restConfig.getKeyStorePath())
+ .clientCertPassword(restConfig.getKeyStorePassword())
+ .trustStore(APP_CONFIG_HOME + restConfig.getTrustStorePath())
+ .connectTimeoutMs(restConfig.getConnectionTimeout())
+ .readTimeoutMs(restConfig.getReadTimeout());
+ // @formatter:on
- headers = new MultivaluedMapImpl();
+ headers = new MultivaluedHashMap<>();
headers.put("Accept", Arrays.asList(ACCEPT));
headers.put("X-FromAppId", Arrays.asList(HEADER_X_FROM_APP_ID));
headers.put("X-TransactionId", Arrays.asList(UUID.randomUUID().toString()));
@@ -103,7 +100,6 @@ public class RestClient {
*
* @param url
* @param payload
- *
* @return The payload of the REST URL call as a string.
* @throws GapServiceException
*/
@@ -116,6 +112,5 @@ public class RestClient {
throw new ValidationServiceException(ValidationServiceError.REST_CLIENT_RESPONSE_ERROR,
result.getResultCode(), result.getFailureCause());
}
-
}
}
diff --git a/src/main/java/org/onap/aai/validation/ruledriven/rule/builtin/DataDictionary.java b/src/main/java/org/onap/aai/validation/ruledriven/rule/builtin/DataDictionary.java
index dc5cdc2..9eaef94 100644
--- a/src/main/java/org/onap/aai/validation/ruledriven/rule/builtin/DataDictionary.java
+++ b/src/main/java/org/onap/aai/validation/ruledriven/rule/builtin/DataDictionary.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START===================================================
- * Copyright (c) 2018 Amdocs
+ * Copyright (c) 2018-2019 European Software Marketing Ltd.
* ============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
-import com.sun.jersey.core.util.MultivaluedMapImpl;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -30,6 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.onap.aai.cl.api.Logger;
import org.onap.aai.restclient.client.OperationResult;
@@ -51,13 +51,13 @@ public class DataDictionary {
UNSUPPORTED;
}
-
private DataDictionary() {
// intentionally empty
}
/**
* Initializes this class' static variables using MethodInvokingFactoryBean
+ *
* @param props
*/
public static void setProperties(Properties props) {
@@ -69,54 +69,51 @@ public class DataDictionary {
credentials = "Basic " + props.getProperty("rule.datadictionary.credentials");
urlTemplate = hostport + uriTemplate;
- restClient = new org.onap.aai.restclient.client.RestClient()
- .validateServerHostname(false)
- .connectTimeoutMs(Integer.parseInt(connectTimeout))
+ restClient = new org.onap.aai.restclient.client.RestClient() //
+ .validateServerHostname(false) //
+ .connectTimeoutMs(Integer.parseInt(connectTimeout)) //
.readTimeoutMs(Integer.parseInt(readTimeout));
}
-
/**
* Generates a REST request to data-dictionary to validate the given attributes.
*
- * URI: /commonModelElements/[commonModelElementId]/validateInstance
- * where commonModelElementId is defined as:
- * [commonModelElementType]~[commonModelElementName]~[commonModelElementVersion]
+ * URI: /commonModelElements/[commonModelElementId]/validateInstance where commonModelElementId is defined as:
+ * [commonModelElementType]~[commonModelElementName]~[commonModelElementVersion]
*
- * Supported commonModelElementType:
- * instance
- * attribute
+ * Supported commonModelElementType: instance attribute
*
- * Examples:
- * /commonModelElements/instance~nfValuesCatalog~1.0/validateInstance
- * /commonModelElements/attribute~nfRole~1.0/validateInstance
+ * Examples: /commonModelElements/instance~nfValuesCatalog~1.0/validateInstance
+ * /commonModelElements/attribute~nfRole~1.0/validateInstance
*
- * @param commonModelElementType "instance" or "attribute"
- * @param commonModelElementName name of common model element
+ * @param commonModelElementType
+ * "instance" or "attribute"
+ * @param commonModelElementName
+ * name of common model element
* @param attributeName
* @param attributeValue
* @return
*/
- public static String validate(String commonModelElementType, String commonModelElementName,
- String attributeName, String attributeValue) {
+ public static String validate(String commonModelElementType, String commonModelElementName, String attributeName,
+ String attributeValue) {
COMMON_MODEL_ELEMENT_TYPE cmeType = COMMON_MODEL_ELEMENT_TYPE.UNSUPPORTED;
try {
cmeType = COMMON_MODEL_ELEMENT_TYPE.valueOf(commonModelElementType.toUpperCase());
- } catch(IllegalArgumentException e) {
+ } catch (IllegalArgumentException e) {
final String error = "unsupported commonModelElementType: " + commonModelElementType;
logger.error(ApplicationMsgs.CANNOT_VALIDATE_ERROR, error);
return error;
}
- if(attributeValue == null || attributeValue.isEmpty()) {
+ if (attributeValue == null || attributeValue.isEmpty()) {
final String error = "element value missing";
logger.error(ApplicationMsgs.CANNOT_VALIDATE_ERROR, error);
return error;
}
- logger.debug("Executing built-in rule with: '" + commonModelElementType + "', '" + commonModelElementName +
- "'; attribute: " + attributeName + "=" + attributeValue);
+ logger.debug("Executing built-in rule with: '" + commonModelElementType + "', '" + commonModelElementName
+ + "'; attribute: " + attributeName + "=" + attributeValue);
Gson gson = new GsonBuilder().create();
String payload = gson.toJson(new Request(cmeType, attributeName, attributeValue));
@@ -124,35 +121,36 @@ public class DataDictionary {
String url = MessageFormat.format(urlTemplate, commonModelElementType, commonModelElementName);
OperationResult result = post(url, payload);
- if(result.getResultCode() == 500) {
+ if (result.getResultCode() == 500) {
// network unreachable; log a warning and return success
logger.warn(ApplicationMsgs.EVENT_CLIENT_CLOSE_UNSENT_MESSAGE,
- ValidationServiceError.REST_CLIENT_RESPONSE_ERROR.getMessage(result.getResultCode(), result.getFailureCause()));
+ ValidationServiceError.REST_CLIENT_RESPONSE_ERROR.getMessage(result.getResultCode(),
+ result.getFailureCause()));
return "";
}
- if(result.getResultCode() != 200 && result.getResultCode() != 204) {
- String error = ValidationServiceError.REST_CLIENT_RESPONSE_ERROR.getMessage(result.getResultCode(), result.getFailureCause());
+ if (result.getResultCode() != 200 && result.getResultCode() != 204) {
+ String error = ValidationServiceError.REST_CLIENT_RESPONSE_ERROR.getMessage(result.getResultCode(),
+ result.getFailureCause());
logger.error(ApplicationMsgs.CANNOT_VALIDATE_ERROR, error);
return result.getFailureCause();
}
return "";
}
-
/**
* Posts the payload to the URL
+ *
* @param url
* @param payload
* @return
*/
private static OperationResult post(String url, String payload) {
- MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+ MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.put("x-authorization", Arrays.asList(credentials));
return restClient.post(url, payload, headers, MediaType.APPLICATION_JSON_TYPE, MediaType.APPLICATION_JSON_TYPE);
}
-
/**
* JSON serializable class representing an instance sent to data-dictionary.
*/
@@ -162,7 +160,7 @@ public class DataDictionary {
private Object instance;
public Request(COMMON_MODEL_ELEMENT_TYPE cmeType, String attributeName, String attributeValue) {
- switch(cmeType) {
+ switch (cmeType) {
case INSTANCE:
Map<String, String> map = new HashMap<>();
map.put(attributeName, attributeValue);
diff --git a/src/test/java/org/onap/aai/validation/TestApplication.java b/src/test/java/org/onap/aai/validation/TestApplication.java
new file mode 100644
index 0000000..26d480a
--- /dev/null
+++ b/src/test/java/org/onap/aai/validation/TestApplication.java
@@ -0,0 +1,49 @@
+/**
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018-2019 European Software Marketing Ltd.
+ * ============================================================================
+ * 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.aai.validation;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Invoke the Spring Boot Application (primarily for code coverage).
+ *
+ */
+public class TestApplication {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Before
+ public void init() {
+ System.setProperty("CONFIG_HOME", "src/test/resources/model-validation/instance-validator");
+ System.setProperty("APP_HOME", ".");
+ System.clearProperty("KEY_STORE_PASSWORD");
+ }
+
+ @Test
+ public void testApplicationWithNullArgs() {
+ System.setProperty("KEY_STORE_PASSWORD", "test");
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Args must not be null");
+ ValidationServiceApplication.main(null);
+ }
+
+}
diff --git a/src/test/resources/model-validation/instance-validator/aai-environment.properties b/src/test/resources/model-validation/instance-validator/aai-environment.properties
index c595e7f..c100f6a 100644
--- a/src/test/resources/model-validation/instance-validator/aai-environment.properties
+++ b/src/test/resources/model-validation/instance-validator/aai-environment.properties
@@ -1,5 +1,5 @@
# ============LICENSE_START===================================================
-# Copyright (c) 2018 Amdocs
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
# ============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
httpProtocol=file
baseModelURI=src/test/resources/model-validation/instance-validator/all-models.xml
-# the following fields are autowired but will never be used
+# the following fields are autowired into the REST client, but this bean will not be invoked
host=
port=
trustStorePath=
@@ -27,5 +27,5 @@ keyStorePassword.x=
keyManagerFactoryAlgorithm=
keyStoreType=
securityProtocol=
-connectionTimeout=
-readTimeout=
+connectionTimeout=0
+readTimeout=0
diff --git a/src/test/resources/model-validation/instance-validator/rule-data-dictionary.properties b/src/test/resources/model-validation/instance-validator/rule-data-dictionary.properties
new file mode 100644
index 0000000..4fa8e3f
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/rule-data-dictionary.properties
@@ -0,0 +1,19 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+rule.datadictionary.hostport=localhost:8080
+rule.datadictionary.connect.timeout=0
+rule.datadictionary.read.timeout=0
diff --git a/src/test/resources/model-validation/instance-validator/rule-indexing.properties b/src/test/resources/model-validation/instance-validator/rule-indexing.properties
new file mode 100644
index 0000000..0139a8b
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/rule-indexing.properties
@@ -0,0 +1,20 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+rule.indexing.events=POA-EVENT
+rule.indexing.exclude.oxm.validation=POA-EVENT
+rule.indexing.key.attributes=$.poa-event.modelVersionId,$.poa-event.modelInvariantId
+rule.indexing.default.key=default-rules
diff --git a/src/test/resources/model-validation/instance-validator/schemaIngest.properties b/src/test/resources/model-validation/instance-validator/schemaIngest.properties
new file mode 100644
index 0000000..3e295d0
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/schemaIngest.properties
@@ -0,0 +1,20 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+# Test properties for the org.onap.aai.setup.SchemaLocationsBean
+schemaConfig=NA
+nodeDir=src/test/resources/oxm-reader/single/
+edgeDir=src/test/resources/oxm-reader/single/ \ No newline at end of file
diff --git a/src/test/resources/model-validation/instance-validator/topics/topic-poa-audit-result.properties b/src/test/resources/model-validation/instance-validator/topics/topic-poa-audit-result.properties
new file mode 100644
index 0000000..578c9b0
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/topics/topic-poa-audit-result.properties
@@ -0,0 +1,22 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+poa-audit-result.name=POA-AUDIT-RESULT
+poa-audit-result.host=message-router:3904
+poa-audit-result.publisher.partition=1
+poa-audit-result.username=
+poa-audit-result.password=
+poa-audit-result.transport.type=HTTPAUTH
diff --git a/src/test/resources/model-validation/instance-validator/topics/topic-poa-rule-validation.properties b/src/test/resources/model-validation/instance-validator/topics/topic-poa-rule-validation.properties
new file mode 100644
index 0000000..19385ba
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/topics/topic-poa-rule-validation.properties
@@ -0,0 +1,23 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+poa-rule-validation.name=POA-RULE-VALIDATION
+poa-rule-validation.host=message-router:3904
+poa-rule-validation.username=
+poa-rule-validation.password=
+poa-rule-validation.consumer.group=poa-validator-test
+poa-rule-validation.consumer.id=test
+poa-rule-validation.transport.type=HTTPAUTH
diff --git a/src/test/resources/model-validation/instance-validator/validation-service-auth.properties b/src/test/resources/model-validation/instance-validator/validation-service-auth.properties
new file mode 100644
index 0000000..1c1ed97
--- /dev/null
+++ b/src/test/resources/model-validation/instance-validator/validation-service-auth.properties
@@ -0,0 +1,18 @@
+# ============LICENSE_START===================================================
+# Copyright (c) 2018-2019 European Software Marketing Ltd.
+# ============================================================================
+# 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.
+# ============LICENSE_END=====================================================
+
+auth.policy.file=appconfig-local/auth/auth_policy.json
+auth.authentication.disable=false \ No newline at end of file