aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-examples/pom.xml5
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/AuthorativeToscaProviderReferenceTest.java20
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java25
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java15
-rw-r--r--models-provider/src/test/resources/logback-test.xml50
-rw-r--r--models-tosca/src/test/resources/logback-test.xml11
-rw-r--r--pom.xml71
7 files changed, 90 insertions, 107 deletions
diff --git a/models-examples/pom.xml b/models-examples/pom.xml
index e9d31b1ee..d250e5d8d 100644
--- a/models-examples/pom.xml
+++ b/models-examples/pom.xml
@@ -31,4 +31,9 @@
<name>${project.artifactId}</name>
<description>Various examples of policy type and policy models in various formats</description>
+
+ <properties>
+ <!-- There is no code in this sub-module, only holds interfaces. So skip sonar. -->
+ <sonar.skip>true</sonar.skip>
+ </properties>
</project>
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/AuthorativeToscaProviderReferenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/AuthorativeToscaProviderReferenceTest.java
index 57a4d8105..5f904dfb4 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/AuthorativeToscaProviderReferenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/AuthorativeToscaProviderReferenceTest.java
@@ -23,9 +23,6 @@ package org.onap.policy.models.provider.impl;
import static org.junit.Assert.assertEquals;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -35,6 +32,8 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.DaoParameters;
@@ -53,7 +52,7 @@ import org.yaml.snakeyaml.Yaml;
*/
public class AuthorativeToscaProviderReferenceTest {
private static PfDao pfDao;
- private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private static final StandardCoder coder = new StandardCoder();
// @formatter:off
private static final String[] EXAMPLE_POLICY_TYPES = {
@@ -141,17 +140,18 @@ public class AuthorativeToscaProviderReferenceTest {
* Populate the database.
*
* @throws PfModelException on database exceptions
+ * @throws CoderException on JSON encoding/decoding errors
*/
@BeforeClass
- public static void beforeFillDatabase() throws PfModelException {
+ public static void beforeFillDatabase() throws PfModelException, CoderException {
for (String policyTypeDataString : EXAMPLE_POLICY_TYPES) {
String[] policyTypeDataArray = policyTypeDataString.split("#");
String policyTypeYamlDefinition = ResourceUtils.getResourceAsString(policyTypeDataArray[2]);
Object yamlObject = new Yaml().load(policyTypeYamlDefinition);
- String policyTypeJsonDefinition = gson.toJson(yamlObject);
+ String policyTypeJsonDefinition = coder.encode(yamlObject);
- ToscaServiceTemplate serviceTemplate = gson.fromJson(policyTypeJsonDefinition, ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate = coder.decode(policyTypeJsonDefinition, ToscaServiceTemplate.class);
policyTypeMap.put(new ToscaEntityKey(policyTypeDataArray[0], policyTypeDataArray[1]), serviceTemplate);
new AuthorativeToscaProvider().createPolicyTypes(pfDao, serviceTemplate);
}
@@ -163,15 +163,15 @@ public class AuthorativeToscaProviderReferenceTest {
}
@Test
- public void testPolicyTypeRead() throws PfModelException {
+ public void testPolicyTypeRead() throws PfModelException, CoderException {
for (Entry<ToscaEntityKey, ToscaServiceTemplate> policyTypeMapEntry : policyTypeMap.entrySet()) {
ToscaServiceTemplate serviceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao,
policyTypeMapEntry.getKey().getName(), policyTypeMapEntry.getKey().getVersion());
assertEquals(1, serviceTemplate.getPolicyTypes().size());
- String originalJson = gson.toJson(policyTypeMapEntry.getValue());
- String databaseJson = gson.toJson(serviceTemplate);
+ String originalJson = coder.encode(policyTypeMapEntry.getValue());
+ String databaseJson = coder.encode(serviceTemplate);
// TODO: This test has no chance of passing yet but must eventually pass to prove that the policy types
// TODO: that were retrieved are the same as the policy types that were stored
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index cfbbdb9d4..f4196811f 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -23,8 +23,6 @@ package org.onap.policy.models.provider.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import com.google.gson.GsonBuilder;
-
import java.net.URISyntaxException;
import java.util.Base64;
import java.util.List;
@@ -114,7 +112,7 @@ public class PolicyToscaPersistenceTest {
private void testYamlStringPolicyPersistence(final String policyString) throws Exception {
Object yamlObject = new Yaml().load(policyString);
- String yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
testJsonStringPolicyPersistence(yamlAsJsonString);
}
@@ -138,19 +136,20 @@ public class PolicyToscaPersistenceTest {
ToscaServiceTemplate gotToscaServiceTemplate =
databaseProvider.getPolicies(policy.getName(), policy.getVersion());
- assertEquals(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
- .get(policy.getName()).getType(), policy.getType());
+ assertEquals(policy.getType(), gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
+ .get(policy.getName()).getType());
gotToscaServiceTemplate = databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build());
- assertEquals(getToscaPolicyFromMapList(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies(),
- policy.getName()).getType(), policy.getType());
+ assertEquals(policy.getType(),
+ getToscaPolicyFromMapList(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies(),
+ policy.getName()).getType());
gotToscaServiceTemplate = databaseProvider.getFilteredPolicies(
ToscaPolicyFilter.builder().name(policy.getName()).version(policy.getVersion()).build());
- assertEquals(gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
- .get(policy.getName()).getType(), policy.getType());
+ assertEquals(policy.getType(), gotToscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0)
+ .get(policy.getName()).getType());
}
}
}
@@ -159,8 +158,8 @@ public class PolicyToscaPersistenceTest {
String policyName) {
ToscaPolicy toscaPolicy = new ToscaPolicy();
for (Map<String, ToscaPolicy> policyMap : toscaPolicyMapList) {
- if (policyMap.get(policyName) != null) {
- toscaPolicy = policyMap.get(policyName);
+ toscaPolicy = policyMap.get(policyName);
+ if (toscaPolicy != null) {
break;
}
}
@@ -170,8 +169,8 @@ public class PolicyToscaPersistenceTest {
private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException {
Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes");
- for (String policyTyoeResource : policyTypeResources) {
- Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTyoeResource));
+ for (String policyTypeResource : policyTypeResources) {
+ Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTypeResource));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
index fc8452b98..0ecf8a046 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
@@ -24,8 +24,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.gson.GsonBuilder;
-
import java.util.Base64;
import java.util.List;
import java.util.Set;
@@ -100,7 +98,7 @@ public class PolicyTypePersistenceTest {
private void testYamlStringPolicyTypePersistence(final String policyTypeString) throws Exception {
Object yamlObject = new Yaml().load(policyTypeString);
- String yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
testJsonStringPolicyTypePersistence(yamlAsJsonString);
}
@@ -117,13 +115,14 @@ public class PolicyTypePersistenceTest {
assertNotNull(serviceTemplate);
ToscaPolicyType inPolicyType = serviceTemplate.getPolicyTypes().values().iterator().next();
- try {
- databaseProvider.createPolicyTypes(serviceTemplate);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ databaseProvider.createPolicyTypes(serviceTemplate);
+ checkPolicyTypePersistence(inPolicyType);
+
databaseProvider.updatePolicyTypes(serviceTemplate);
+ checkPolicyTypePersistence(inPolicyType);
+ }
+ private void checkPolicyTypePersistence(ToscaPolicyType inPolicyType) throws PfModelException {
List<ToscaPolicyType> policyTypeList =
databaseProvider.getPolicyTypeList(inPolicyType.getName(), inPolicyType.getVersion());
diff --git a/models-provider/src/test/resources/logback-test.xml b/models-provider/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..fe59c89f1
--- /dev/null
+++ b/models-provider/src/test/resources/logback-test.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Nordix Foundation.
+ ================================================================================
+ 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.
+
+ SPDX-License-Identifier: Apache-2.0
+ ============LICENSE_END=========================================================
+-->
+
+<configuration>
+
+ <contextName>PolicyModels</contextName>
+ <statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ <property name="LOG_DIR" value="${java.io.tmpdir}/pf_logging/" />
+
+ <!-- USE FOR STD OUTPUT ONLY -->
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%d %contextName [%t] %level %logger{36} - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${LOG_DIR}/policy-models.log</file>
+ <encoder>
+ <pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
+ %logger{26} - %msg %n %ex{full}</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="org.onap.policy" level="info" additivity="false">
+ <appender-ref ref="STDOUT" />
+ </logger>
+</configuration>
diff --git a/models-tosca/src/test/resources/logback-test.xml b/models-tosca/src/test/resources/logback-test.xml
index a7a583827..bfda254eb 100644
--- a/models-tosca/src/test/resources/logback-test.xml
+++ b/models-tosca/src/test/resources/logback-test.xml
@@ -2,26 +2,27 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2020 Nordix Foundation.
================================================================================
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.
-
+
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
<configuration>
- <contextName>Apex</contextName>
+ <contextName>PolicyModels</contextName>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<property name="LOG_DIR" value="${java.io.tmpdir}/pf_logging/" />
@@ -37,7 +38,7 @@
</root>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${LOG_DIR}/apex.log</file>
+ <file>${LOG_DIR}/policy-models.log</file>
<encoder>
<pattern>%d %-5relative [procId=${processId}] [%thread] %-5level
%logger{26} - %msg %n %ex{full}</pattern>
diff --git a/pom.xml b/pom.xml
index dfe5613a6..7aa780f07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -41,13 +41,6 @@
<properties>
<derby.version>10.13.1.1</derby.version>
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
-
- <!-- sonar/jacoco overrides -->
- <!-- Overriding oparent default sonar/jacoco settings Combine all our reports into one file shared across sub-modules -->
- <sonar.jacoco.reportPath>${project.basedir}/../target/code-coverage/jacoco-ut.exec</sonar.jacoco.reportPath>
- <sonar.jacoco.itReportPath>${project.basedir}/../target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPath>
- <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
-
<policy.common.version>1.6.2-SNAPSHOT</policy.common.version>
</properties>
@@ -218,32 +211,6 @@
<build>
<plugins>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>pre-unit-test</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${sonar.jacoco.reportPath}</destFile>
- <append>true</append>
- </configuration>
- </execution>
- <execution>
- <id>post-unit-test</id>
- <phase>test</phase>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${sonar.jacoco.reportPath}</dataFile>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
@@ -282,44 +249,6 @@
<pluginManagement>
<plugins>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacoco.version}</version>
- <configuration>
- <!-- Note: This exclusion list should match <sonar.exclusions> property above -->
- <excludes>
- <exclude>**/gen/**</exclude>
- <exclude>**/generated-sources/**</exclude>
- <exclude>**/yang-gen/**</exclude>
- <exclude>**/pax/**</exclude>
- </excludes>
- </configuration>
- <executions>
- <!-- Prepares the property pointing to the JaCoCo runtime agent which is passed as VM argument when
- Maven the Surefire plugin is executed. -->
- <execution>
- <id>pre-unit-test</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- <configuration>
- <destFile>${sonar.jacoco.reportPath}</destFile>
- </configuration>
- </execution>
- <!-- Ensures that the code coverage report for unit tests is created after unit tests have been run. -->
- <execution>
- <id>post-unit-test</id>
- <phase>test</phase>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${sonar.jacoco.reportPath}</dataFile>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>