package org.onap.clamp.clds.it;
+import com.google.gson.reflect.TypeToken;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import org.onap.clamp.clds.model.properties.PolicyItem;
import org.onap.clamp.clds.model.properties.Tca;
import org.onap.clamp.clds.transform.XslTransformer;
-import org.onap.clamp.clds.util.JacksonUtils;
+import org.onap.clamp.clds.util.JsonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.policy.api.AttributeType;
@SpringBootTest
public class PolicyClientItCase {
+ private static final Type MAP_OF_STRING_TO_OBJECT_TYPE = new TypeToken<Map<String, Object>>() {}.getType();
+
@Autowired
private CldsDao cldsDao;
@Autowired
String modelBpmnPropJson;
ModelProperties prop;
+ /**
+ * Setup method.
+ * @throws IOException thrown if resources not found
+ * @throws TransformerException thrown if invalid xml given to transformation
+ */
@Before
public void setUp() throws IOException, TransformerException {
modelProp = ResourceFileUtil.getResourceAsString("example/model-properties/tca_new/model-properties.json");
}
@Test
- public void testSendGuardPolicy() throws TransformerException, IOException {
+ public void testSendGuardPolicy() {
// Normally there is only one Guard
List<PolicyItem> policyItems = GuardPolicyAttributesConstructor
.getAllPolicyGuardsFromPolicyChain(prop.getType(Policy.class).getPolicyChains().get(0));
String response = policyClient.sendGuardPolicy(
GuardPolicyAttributesConstructor.formatAttributes(prop, policyItem), prop, LoggingUtils.getRequestId(),
policyItem);
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Decision"),
Assertions.entry("policyName",
modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0_Guard_6TtHGPq"),
}
@Test
- public void testSendBrmsPolicy()
- throws TransformerException, BuilderException, IllegalArgumentException, IOException {
+ public void testSendBrmsPolicy() throws BuilderException, IllegalArgumentException, IOException {
Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(
refProp, prop, prop.getType(Policy.class).getId(), prop.getType(Policy.class).getPolicyChains().get(0));
String response = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"),
Assertions.entry("policyConfigType", PolicyConfigType.BRMS_PARAM.name()),
}
@Test
- public void testSendMicroServiceInJson()
- throws TransformerException, BuilderException, IllegalArgumentException, IOException {
+ public void testSendMicroServiceInJson() throws IllegalArgumentException {
prop.setCurrentModelElementId(prop.getType(Policy.class).getId());
String jsonToSend = "{\"test\":\"test\"}";
String response = policyClient.sendMicroServiceInJson(jsonToSend, prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h"),
Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()),
public void testSendBasePolicyInOther() throws IllegalArgumentException, IOException {
String body = "test";
String response = policyClient.sendBasePolicyInOther(body, "myPolicy", prop, LoggingUtils.getRequestId());
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", "myPolicy"),
Assertions.entry("policyConfigType", PolicyConfigType.Base.name()),
String tcaJson = TcaRequestFormatter.createPolicyJson(refProp, prop);
String response = policyClient.sendMicroServiceInOther(tcaJson, prop);
- Map<String, Object> mapNodes = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(response), Map.class);
+ Map<String, Object> mapNodes = JsonUtils.GSON.fromJson(response, MAP_OF_STRING_TO_OBJECT_TYPE);
+
Assertions.assertThat(mapNodes).contains(Assertions.entry("policyClass", "Config"),
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"),
Assertions.entry("policyConfigType", PolicyConfigType.MicroService.name()),
String[] responses = policyClient.deleteMicrosService(prop).split("\\}\\{");
// There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_TCA_1d13unw"),
prop.setGuardUniqueId(policyItems.get(0).getId());
String[] responses = policyClient.deleteGuard(prop).split("\\}\\{");
- // There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName",
prop.setCurrentModelElementId(prop.getType(Policy.class).getId());
String[] responses = policyClient.deleteBrms(prop).split("\\}\\{");
- // There are 2 responses appended to the result, one for PDP one for PAP !
- Map<String, Object> mapNodesPdp = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree(responses[0] + "}"), Map.class);
- Map<String, Object> mapNodesPap = JacksonUtils.getObjectMapperInstance()
- .convertValue(JacksonUtils.getObjectMapperInstance().readTree("{" + responses[1]), Map.class);
+ Map<String, Object> mapNodesPdp = JsonUtils.GSON.fromJson(responses[0] + "}",
+ MAP_OF_STRING_TO_OBJECT_TYPE);
+ Map<String, Object> mapNodesPap = JsonUtils.GSON.fromJson("{" + responses[1],
+ MAP_OF_STRING_TO_OBJECT_TYPE);
Assertions.assertThat(mapNodesPdp).contains(
Assertions.entry("policyName", modelName.replace("-", "_") + "." + controlName + "_Policy_12lup3h_0"),
String tosca = policyClient.importToscaModel(cldsToscaModel);
Assertions.assertThat(tosca).contains(
- "{\"serviceName\":\"tca-policy-test\",\"description\":\"tca-policy-test\",\"requestID\":null,\"filePath\":\"/tmp/tosca-models/tca-policy-test.yml\",");
+ "{\"serviceName\":\"tca-policy-test\",\"description\":\"tca-policy-test\","
+ + "\"requestID\":null,\"filePath\":\"/tmp/tosca-models/tca-policy-test.yml\",");
Assertions.assertThat(tosca).contains(toscaModelYaml);
}
}