summaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
Diffstat (limited to 'models-provider')
-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
4 files changed, 79 insertions, 31 deletions
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>