/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-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.
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;
}
@Test
- public void testPolicyPersistence() throws Exception {
+ public void testToscaPolicyPersistence() throws Exception {
Set<String> policyResources = ResourceUtils.getDirectoryContents("policies");
for (String policyResource : policyResources) {
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);
}
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());
}
}
}
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;
}
}
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 =