/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 AT&T.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import java.net.URISyntaxException;
import java.util.Base64;
-
+import java.util.Set;
import lombok.NonNull;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
/**
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class PolicyLegacyOperationalPersistenceTest {
- // Logger for this class
- private static final Logger LOGGER = LoggerFactory.getLogger(PolicyLegacyOperationalPersistenceTest.class);
-
private StandardCoder standardCoder;
private PolicyModelsProvider databaseProvider;
// @formatter:off
private String[] policyInputResourceNames = {
- "policies/vCPE.policy.operational.input.json",
- "policies/vDNS.policy.operational.input.json",
- "policies/vFirewall.policy.operational.input.json"
+ "policies/vCPE.policy.operational.legacy.input.json",
+ "policies/vDNS.policy.operational.legacy.input.json",
+ "policies/vFirewall.policy.operational.legacy.input.json"
};
private String[] policyOutputResourceNames = {
- "policies/vCPE.policy.operational.output.json",
- "policies/vDNS.policy.operational.output.json",
- "policies/vFirewall.policy.operational.output.json"
+ "policies/vCPE.policy.operational.legacy.output.json",
+ "policies/vDNS.policy.operational.legacy.output.json",
+ "policies/vFirewall.policy.operational.legacy.output.json"
};
// @formatter:on
}
@Test
- public void testPolicyPersistence() {
- try {
- for (int i = 0; i < policyInputResourceNames.length; i++) {
- String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]);
- String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]);
- testJsonStringPolicyPersistence(policyInputString, policyOutputString);
- }
- } catch (Exception exc) {
- LOGGER.warn("error processing policies", exc);
- fail("test should not throw an exception");
+ public void testLegacyOperationalPolicyPersistence() throws Exception {
+ for (int i = 0; i < policyInputResourceNames.length; i++) {
+ String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]);
+ String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]);
+ testJsonStringPolicyPersistence(policyInputString, policyOutputString);
}
}
"'"));
}
- private void createPolicyTypes() throws CoderException, PfModelException {
+ private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException {
+ Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes");
- Object yamlObject = new Yaml().load(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
- String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+ for (String policyTypeResource : policyTypeResources) {
+ Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTypeResource));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
- ToscaServiceTemplate toscaServiceTemplatePolicyType =
- standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
- assertNotNull(toscaServiceTemplatePolicyType);
- databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ assertNotNull(toscaServiceTemplatePolicyType);
+ databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+ }
}
}