import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
/**
* This interface describes the operations that are provided to users and components for reading
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
/**
* This class provides an implementation of the Policy Models Provider for the ONAP Policy Framework
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.provider.PolicyModelsProvider;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy;
-import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy;
-import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
/**
* This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
/**
* Test the dummy moldes provider implementation.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.legacy;
+package org.onap.policy.models.tosca.legacy.concepts;
import java.util.List;
import java.util.Map;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.legacy;
+package org.onap.policy.models.tosca.legacy.concepts;
+
+import com.google.gson.annotations.SerializedName;
import lombok.Data;
@Data
public class LegacyOperationalPolicy {
+ @SerializedName("policy-id")
private String policyId;
private String policyVersion;
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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=========================================================
+ */
+
+package org.onap.policy.models.tosca.legacy.mapping;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
+import org.onap.policy.models.tosca.simple.mapping.ToscaServiceTemplateMapper;
+
+/**
+ * This class maps a legacy operational policy to and from a TOSCA service template.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class LegacyOperationalPolicyMapper
+ implements ToscaServiceTemplateMapper<LegacyOperationalPolicy, LegacyOperationalPolicy> {
+
+ // TODO: Do this correctly with an atomic integer
+ private static int nextVersion = 1;
+
+ @Override
+ public ToscaServiceTemplate toToscaServiceTemplate(LegacyOperationalPolicy legacyOperationalPolicy) {
+ PfConceptKey policyKey =
+ new PfConceptKey(legacyOperationalPolicy.getPolicyId(), getNextVersion());
+
+ ToscaPolicy toscaPolicy = new ToscaPolicy(policyKey);
+
+ // TODO: Find out how to parse the PolicyType from the content
+ // TODO: Check if this is the correct way to set the policy type version
+ toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.0"));
+
+ Map<String, Object> propertyMap = new HashMap<>();
+ toscaPolicy.setProperties(propertyMap);
+ toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent());
+
+ PfConceptKey serviceTemplateKey = new PfConceptKey("ServiceTemplate", "1.0.0");
+ ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey);
+ serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
+
+ PfReferenceKey topologyTemplateKey = new PfReferenceKey(serviceTemplateKey, "TopolocyTemplate");
+ serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate(topologyTemplateKey));
+
+ PfConceptKey policiesKey = new PfConceptKey("Policies", "1.0.0");
+ serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies(policiesKey));
+ serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy);
+
+ return serviceTemplate;
+ }
+
+ @Override
+ public LegacyOperationalPolicy fromToscaServiceTemplate(ToscaServiceTemplate serviceTemplate) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Get the next policy version.
+ *
+ * @return the next version
+ */
+ private static String getNextVersion() {
+ return "1.0." + nextVersion++;
+ }
+}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.serialization.legacy;
-
-import com.google.gson.GsonBuilder;
-
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provider used to serialize and deserialize TOSCA objects using GSON.
- */
-public class LegacyGuardMessageBodyHandler extends GsonMessageBodyHandler {
-
- public static final Logger logger = LoggerFactory.getLogger(LegacyGuardMessageBodyHandler.class);
-
- /**
- * Constructs the object.
- */
- public LegacyGuardMessageBodyHandler() {
- this(new GsonBuilder());
-
- logger.info("Using GSON with TOSCA for REST calls");
- }
-
- /**
- * Constructs the object.
- *
- * @param builder builder to use to create the gson object
- */
- public LegacyGuardMessageBodyHandler(final GsonBuilder builder) {
- // @formatter:off
- super(builder
- .create()
- );
- // @formatter:on
- }
-
-}
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2019 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.models.tosca.serialization.legacy;
-
-import com.google.gson.GsonBuilder;
-
-import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provider used to serialize and deserialize TOSCA objects using GSON.
- */
-public class LegacyOperationalMessageBodyHandler extends GsonMessageBodyHandler {
-
- public static final Logger logger = LoggerFactory.getLogger(LegacyOperationalMessageBodyHandler.class);
-
- /**
- * Constructs the object.
- */
- public LegacyOperationalMessageBodyHandler() {
- this(new GsonBuilder());
-
- logger.info("Using GSON with TOSCA for REST calls");
- }
-
- /**
- * Constructs the object.
- *
- * @param builder builder to use to create the gson object
- */
- public LegacyOperationalMessageBodyHandler(final GsonBuilder builder) {
- // @formatter:off
- super(builder
- .create()
- );
- // @formatter:on
- }
-
-}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import javax.persistence.Column;
import javax.ws.rs.core.Response;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import javax.persistence.Column;
import javax.persistence.Entity;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.Map;
import java.util.TreeMap;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.Map;
import java.util.TreeMap;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import lombok.NonNull;
import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
private PfConceptKey type;
@ElementCollection
- private List<ToscaProperty> properties;
+ private Map<String, Object> properties;
@ElementCollection
private List<PfConceptKey> targets;
keyList.addAll(type.getKeys());
- if (properties != null) {
- for (ToscaProperty property : properties) {
- keyList.addAll(property.getKeys());
- }
- }
-
if (targets != null) {
keyList.addAll(targets);
}
type.clean();
- if (properties != null) {
- for (ToscaProperty property : properties) {
- property.clean();
- }
- }
-
if (targets != null) {
for (PfConceptKey target : targets) {
target.clean();
if (type == null || type.isNullKey()) {
result.addValidationMessage(new PfValidationMessage(type, this.getClass(), ValidationResult.INVALID,
"type is null or a null key"));
- }
- else {
+ } else {
result = type.validate(result);
}
private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) {
PfValidationResult result = resultIn;
- for (ToscaProperty property : properties) {
- if (property == null) {
+ for (Entry<String, Object> propertyEntry : properties.entrySet()) {
+ if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "policy property may not be null "));
- } else {
- result = property.validate(result);
+ "policy property key may not be null "));
+ } else if (propertyEntry.getValue() == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy property value may not be null "));
}
}
return result;
if (properties == null) {
copy.setProperties(null);
} else {
- final List<ToscaProperty> newProperties = new ArrayList<>();
- for (final ToscaProperty property : properties) {
- newProperties.add(new ToscaProperty(property));
- }
- copy.setProperties(newProperties);
+ copy.setProperties(properties);
}
if (targets == null) {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.Map;
import java.util.TreeMap;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.Map;
import java.util.TreeMap;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.google.gson.annotations.SerializedName;
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.mapping;
+
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+
+/**
+ * This interface is used to map legacy and proprietary policies into and out of TOSCA service templates.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ * @param <I> the type for the incoming policy definition
+ * @param <O> the type for the outgoing policy definition
+ */
+public interface ToscaServiceTemplateMapper<I, O> {
+
+ /**
+ * Translate from the other format to a TOSCA service template.
+ *
+ * @param otherPolicyType the other policy type
+ * @return the TOSCA service template
+ */
+ public ToscaServiceTemplate toToscaServiceTemplate(final I otherPolicyType);
+
+ /**
+ * Translate to the other format from a TOSCA service template.
+ *
+ * @param serviceTemplate the TOSCA service template
+ * @return the policy in the other format
+ */
+ public O fromToscaServiceTemplate(final ToscaServiceTemplate serviceTemplate);
+}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.simple;
+package org.onap.policy.models.tosca.simple.serialization;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.concepts.ToscaPolicies;
-import org.onap.policy.models.tosca.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
/**
* GSON type adapter for TOSCA policies.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.simple;
+package org.onap.policy.models.tosca.simple.serialization;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.tosca.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.simple;
+package org.onap.policy.models.tosca.simple.serialization;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import lombok.NonNull;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
/**
* GSON type adapter for TOSCA policies.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.simple;
+package org.onap.policy.models.tosca.simple.serialization;
import com.google.gson.GsonBuilder;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
-import org.onap.policy.models.tosca.concepts.ToscaPolicies;
-import org.onap.policy.models.tosca.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.simple;
+package org.onap.policy.models.tosca.simple.serialization;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.tosca.concepts.ToscaPolicies;
-import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
/**
* GSON type adapter for TOSCA policies.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.legacy;
+package org.onap.policy.models.tosca.legacy.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Map;
import org.junit.Test;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
public class LegacyGuardPolicyTest {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization.legacy;
+package org.onap.policy.models.tosca.legacy.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
public class LegacyOperationalPolicyTest {
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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=========================================================
+ */
+
+package org.onap.policy.models.tosca.legacy.serialization;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonSyntaxException;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.resources.TextFileUtils;
+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;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test serialization of monitoring policies.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class LegacyOperationalPolicySerializationTest {
+ // Logger for this class
+ private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicySerializationTest.class);
+
+ private Gson gson;
+
+ @Before
+ public void setUp() {
+ gson = new Gson();
+ }
+
+ @Test
+ public void testJsonDeserialization() throws JsonSyntaxException, IOException {
+ LegacyOperationalPolicy legacyOperationalPolicy = gson.fromJson(
+ TextFileUtils.getTextFileAsString("src/test/resources/policies/vCPE.policy.operational.input.json"),
+ LegacyOperationalPolicy.class);
+
+ ToscaServiceTemplate serviceTemplate =
+ new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy);
+
+ assertNotNull(serviceTemplate);
+ LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString());
+ assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
+
+ assertEquals("operational.restart:1.0.1",
+ serviceTemplate.getTopologyTemplate().getPolicies().get("operational.restart").getId());
+ }
+}
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import com.openpojo.reflection.filters.FilterPackageInfo;
import com.openpojo.validation.Validator;
*/
public class TestPojos {
- private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.concepts";
+ private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.simple.concepts";
@Test
public void testPojos() {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalKey;
/**
* DAO test for ToscaConstraintLogicalKey.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString;
/**
* DAO test for ToscaConstraintLogicalString.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.testconcepts.DummyToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical;
+import org.onap.policy.models.tosca.simple.concepts.testconcepts.DummyToscaConstraint;
/**
* DAO test for ToscaConstraintLogical.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.simple.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaProperty;
/**
* DAO test for ToscaDatatype.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes;
public class ToscaDataTypesTest {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.simple.concepts.ToscaEntrySchema;
/**
* DAO test for ToscaEntrySchema.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaEventFilter;
/**
* DAO test for ToscaEventFilter.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelService;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaModel;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplates;
/**
* DAO test for ToscaDatatype.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
public class ToscaPoliciesTest {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
/**
* DAO test for ToscaDatatype.
PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
ToscaPolicy tp = new ToscaPolicy(tpKey, ptKey);
- List<ToscaProperty> properties = new ArrayList<>();
- ToscaProperty property = new ToscaProperty(new PfReferenceKey(tpKey, "pr"), new PfConceptKey("type", "0.0.1"));
- properties.add(property);
- tp.setProperties(properties);
- assertEquals(properties, tp.getProperties());
+ Map<String, Object> propertyMap = new HashMap<>();
+ propertyMap.put("Property", "Property Value");
+ tp.setProperties(propertyMap);
+ assertEquals(propertyMap, tp.getProperties());
List<PfConceptKey> targets = new ArrayList<>();
PfConceptKey target = new PfConceptKey("target", "0.0.1");
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setType(ptKey);
assertFalse(tp.compareTo(otherDt) == 0);
- otherDt.setProperties(properties);
+ otherDt.setProperties(propertyMap);
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setTargets(targets);
assertEquals(0, tp.compareTo(otherDt));
assertEquals("target is marked @NonNull but is null", exc.getMessage());
}
- assertEquals(5, tp.getKeys().size());
+ assertEquals(3, tp.getKeys().size());
assertEquals(2, new ToscaPolicy().getKeys().size());
new ToscaPolicy().clean();
assertEquals(tdtClone0, tp);
assertFalse(new ToscaPolicy().validate(new PfValidationResult()).isValid());
+ System.err.println(tp.validate(new PfValidationResult()));
assertTrue(tp.validate(new PfValidationResult()).isValid());
- tp.getProperties().add(null);
+ tp.getProperties().put(null, null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.getProperties().remove(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.getProperties().put("Key", null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.getProperties().remove("Key");
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.getProperties().put(null, "Value");
assertFalse(tp.validate(new PfValidationResult()).isValid());
tp.getProperties().remove(null);
assertTrue(tp.validate(new PfValidationResult()).isValid());
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaEntityType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaProperty;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTrigger;
/**
* DAO test for ToscaPolicyType.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyTypes;
public class ToscaPolicyTypesTest {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.simple.concepts.ToscaEntrySchema;
+import org.onap.policy.models.tosca.simple.concepts.ToscaProperty;
/**
* DAO test for ToscaProperty.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaDataType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyTypes;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
/**
* DAO test for ToscaDatatype.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplates;
public class ToscaServiceTemplatesTest {
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTimeInterval;
/**
* DAO test for ToscaTimeInterval.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate;
/**
* DAO test for ToscaDatatype.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts;
+package org.onap.policy.models.tosca.simple.concepts;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString;
+import org.onap.policy.models.tosca.simple.concepts.ToscaEventFilter;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTimeInterval;
+import org.onap.policy.models.tosca.simple.concepts.ToscaTrigger;
/**
* DAO test for ToscaTrigger.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.concepts.testconcepts;
+package org.onap.policy.models.tosca.simple.concepts.testconcepts;
import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfReferenceKey;
-import org.onap.policy.models.tosca.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.ToscaConstraint;
/**
* Dummy constraint to test abstract ToscaConstraint class.
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca.serialization;
+package org.onap.policy.models.tosca.simple.serialization;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler;
+import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;