summaryrefslogtreecommitdiffstats
path: root/runtime-acm/src/test
diff options
context:
space:
mode:
authorSirisha_Manchikanti <sirisha.manchikanti@est.tech>2022-04-12 17:41:14 +0100
committerSirisha_Manchikanti <sirisha.manchikanti@est.tech>2022-04-20 15:04:23 +0100
commit8584f219b638769603101b936497c276323950ca (patch)
treed72f99bd14962e179d6fa5209c228b1a5a48cb28 /runtime-acm/src/test
parent25b2378104e75f14fb950529eeeff09d7d9d585b (diff)
Replace jackson library usage with GSON
Issue-ID: POLICY-4085 Signed-off-by: Sirisha_Manchikanti <sirisha.manchikanti@est.tech> Change-Id: I6f8f55d2c49495b6efcdc7f58de03c440f72626d
Diffstat (limited to 'runtime-acm/src/test')
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java38
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java21
2 files changed, 37 insertions, 22 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
index 33a9fd85c..bcdb4ddd6 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java
@@ -29,9 +29,10 @@ import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.PropertyNamingStrategies;
-import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializer;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -55,7 +56,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
class CommissioningProviderTest {
private static final Coder CODER = new StandardCoder();
- private final ObjectMapper mapper = new ObjectMapper();
/**
* Test the fetching of automation composition definitions (ToscaServiceTemplates).
@@ -191,30 +191,30 @@ class CommissioningProviderTest {
when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate);
provider.createAutomationCompositionDefinitions(serviceTemplate);
+ provider.initialize();
- mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
-
- Map<String, Class<?>> sections = Map.of("all", ToscaServiceTemplate.class, "data_types", ToscaDataType.class,
- "capability_types", ToscaCapabilityType.class, "node_types", ToscaNodeType.class, "relationship_types",
+ final Map<String, Class<?>> sections = Map.of("all", ToscaServiceTemplate.class,
+ "data_types", ToscaDataType.class, "capability_types", ToscaCapabilityType.class,
+ "node_types", ToscaNodeType.class, "relationship_types",
ToscaRelationshipType.class, "policy_types", ToscaPolicyType.class, "topology_template",
ToscaTopologyTemplate.class, "node_templates", List.class);
+ String localServiceTemplateSchema = new String();
+ Gson gson = new Gson();
+ GsonBuilder builder = new GsonBuilder();
+ builder.registerTypeAdapter(ToscaTopologyTemplate.class,
+ (JsonSerializer<ToscaTopologyTemplate>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString()));
+ builder.setPrettyPrinting();
+ gson = builder.create();
+
for (Map.Entry<String, Class<?>> entry : sections.entrySet()) {
String returnedServiceTemplateSchema = provider.getToscaServiceTemplateSchema(entry.getKey());
assertThat(returnedServiceTemplateSchema).isNotNull();
- var visitor = new SchemaFactoryWrapper();
-
- if (entry.getKey().equals("node_templates")) {
- mapper.acceptJsonFormatVisitor(
- mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class), visitor);
- } else {
- mapper.acceptJsonFormatVisitor(mapper.constructType(entry.getValue()), visitor);
+ if (entry.getKey().equals("topology_template")) {
+ localServiceTemplateSchema = gson.toJson(new ToscaTopologyTemplate());
+ assertThat(localServiceTemplateSchema).isEqualTo(returnedServiceTemplateSchema);
}
-
- var jsonSchema = visitor.finalSchema();
- String localServiceTemplateSchema = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema);
- assertThat(localServiceTemplateSchema).isEqualTo(returnedServiceTemplateSchema);
}
}
}
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
index a1f3b104b..f9a7b20e4 100644
--- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -29,6 +29,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonPrimitive;
+import com.google.gson.JsonSerializer;
import java.util.List;
import java.util.Map;
import javax.ws.rs.client.Entity;
@@ -137,9 +143,18 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- ToscaServiceTemplate template = rawresp.readEntity(ToscaServiceTemplate.class);
- assertNotNull(template);
- assertThat(template.getNodeTypes()).hasSize(7);
+ String template = rawresp.readEntity(String.class);
+ final JsonObject jsonObject = new JsonParser().parse(template).getAsJsonObject();
+
+ Gson gson = new Gson();
+ GsonBuilder builder = new GsonBuilder();
+ builder.registerTypeAdapter(ToscaNodeTemplate.class,
+ (JsonSerializer<ToscaNodeTemplate>) (src, typeOfSrc, context) -> new JsonPrimitive(src.toString()));
+ builder.setPrettyPrinting();
+ gson = builder.create();
+
+ ToscaNodeTemplate toscaNodeTemplate = gson.fromJson(jsonObject, ToscaNodeTemplate.class);
+ assertNotNull(toscaNodeTemplate);
}
@Test