import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
@After
public void teardown() throws Exception {
connection.close();
- new File("derby.log").delete();
}
@Test
--- /dev/null
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-models-examples</artifactId>
+
+ <name>${project.artifactId}</name>
+ <description>Various examples of policy type and policy models in various formats</description>
+</project>
<description>The provider interface that allows components to manipualte models in the database</description>
<dependencies>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>common-parameters</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.onap.policy.models</groupId>
<artifactId>policy-models-base</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-examples</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
<dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>gson</artifactId>
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
-import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
+import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
-import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* Class to represent the EntrySchema of list/map property in TOSCA definition.
*/
-@Entity
-@Table(name = "ToscaEntityType")
+@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
import java.lang.reflect.Type;
import java.util.Iterator;
-import java.util.Map.Entry;
import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper;
@Test
public void testJsonDeserialization() throws JsonSyntaxException, IOException {
- LegacyOperationalPolicy legacyOperationalPolicy = gson.fromJson(
- TextFileUtils.getTextFileAsString("src/test/resources/policies/vCPE.policy.operational.input.json"),
- LegacyOperationalPolicy.class);
+ String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json");
+
+ LegacyOperationalPolicy legacyOperationalPolicy = gson.fromJson(vcpePolicyJson, LegacyOperationalPolicy.class);
ToscaServiceTemplate serviceTemplate =
new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
import org.junit.Before;
import org.junit.Test;
-import org.onap.policy.common.utils.resources.TextFileUtils;
+import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
@Test
public void testJsonDeserialization() throws JsonSyntaxException, IOException {
- ToscaServiceTemplate serviceTemplate = gson.fromJson(
- TextFileUtils
- .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.json"),
- ToscaServiceTemplate.class);
+ String vcpePolicyJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
+ ToscaServiceTemplate serviceTemplate = gson.fromJson(vcpePolicyJson, ToscaServiceTemplate.class);
assertNotNull(serviceTemplate);
LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
@Test
public void testYamlDeserialization() throws JsonSyntaxException, IOException {
Yaml yaml = new Yaml();
- Object yamlObject = yaml.load(TextFileUtils
- .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.yaml"));
+
+ String vcpePolicyYaml = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.yaml");
+ Object yamlObject = yaml.load(vcpePolicyYaml);
String yamlAsJsonString = new Gson().toJson(yamlObject);
<module>models-pap</module>
<module>models-decisions</module>
<module>models-provider</module>
+ <module>models-examples</module>
</modules>
<distributionManagement>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>