use of io.fabric8.camelk.v1alpha1.Kamelet in project kubernetes-client by fabric8io.
the class KameletModelTest method shouldDeserializeValidYamlIntoObject.
@Test
void shouldDeserializeValidYamlIntoObject() throws JsonProcessingException {
final ObjectMapper mapper = new ObjectMapper();
// Given
String originalJson = new Scanner(getClass().getResourceAsStream("/valid-kamelet.json")).useDelimiter("\\A").next();
// When
final Kamelet kamelet = mapper.readValue(originalJson, Kamelet.class);
final String serializedJson = mapper.writeValueAsString(kamelet);
final Kamelet kameletFromSerializedJson = mapper.readValue(serializedJson, Kamelet.class);
// Then
assertNotNull(kamelet);
assertNotNull(serializedJson);
assertNotNull(kameletFromSerializedJson);
assertEquals(kamelet.getMetadata().getName(), kameletFromSerializedJson.getMetadata().getName());
assertNotNull(kamelet.getSpec().getTemplate());
assertFalse(kamelet.getSpec().getTemplate().isEmpty());
assertTrue(kamelet.getSpec().getTemplate().containsKey("beans"));
assertTrue(kamelet.getSpec().getTemplate().containsKey("from"));
}
use of io.fabric8.camelk.v1alpha1.Kamelet in project kaoto-backend by KaotoIO.
the class KamelPopulator method populateKamelet.
public void populateKamelet(final Kamelet kamelet, final Map<String, Object> metadata, final List<Step> steps) {
kamelet.setSpec(new KameletSpec());
kamelet.getSpec().setTemplate(new Template());
kamelet.getSpec().getTemplate().setFrom(getFlow(steps));
kamelet.setMetadata(new ObjectMeta());
populateLabels(kamelet, (Map<String, String>) metadata.getOrDefault("labels", Collections.emptyMap()));
populateAdditionalProperties(kamelet, (Map<String, String>) metadata.getOrDefault("additionalProperties", Collections.emptyMap()));
populateAnnotations(kamelet, (Map<String, String>) metadata.getOrDefault("annotations", Collections.emptyMap()));
// override in case this is outdated from the graphic side
Type type = defineType(steps);
kamelet.getMetadata().getLabels().put(group + "/kamelet.type", type.name());
// consistent naming for kamelets
String name = metadata.getOrDefault(NAME, "").toString();
if (!name.endsWith(type.name())) {
name = name + "-" + type.name();
}
kamelet.getMetadata().setName(name);
// do we have an icon?
if (kamelet.getMetadata().getAnnotations().getOrDefault(CAMEL_APACHE_ORG_KAMELET_ICON, "").isBlank()) {
kamelet.getMetadata().getAnnotations().put(CAMEL_APACHE_ORG_KAMELET_ICON, metadata.getOrDefault("icon", "").toString());
}
}
Aggregations