Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
fix: Beans have two types of properties attributes
Browse files Browse the repository at this point in the history
Fixes #715
  • Loading branch information
Delawen authored and igarashitm committed Jun 28, 2023
1 parent f9c6401 commit 0b39358
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,33 @@ void noFrom() throws Exception {
var to = (Map<String, Object>) ((Map<String, Object>) steps.get(0)).get("to");
assertEquals("log:", to.get("uri"));
}
@Test
void beans() throws Exception {
String yaml = Files.readString(Path.of(
IntegrationsResourceTest.class.getResource("../../resource/kamelet2.yaml").toURI()));
var res = given()
.when()
.contentType("text/yaml")
.body(yaml)
.post("?dsl=Kamelet")
.then()
.statusCode(Response.Status.OK.getStatusCode());
var flows = res.extract().body().as(FlowsWrapper.class);
assertNotNull(flows);
var flow = flows.flows().get(0);
assertNotNull(flow);
var beans = (List<Map<String, Object>>) flow.getMetadata().get("beans");
assertEquals(1, beans.size());
var bean = beans.get(0);
assertEquals(3, bean.size());
assertTrue(bean.containsKey("name"));
assertTrue(bean.containsKey("type"));
assertTrue(bean.containsKey("properties"));
var properties = (Map<String, String>) bean.get("properties");
assertEquals(2, properties.size());
assertTrue(properties.containsKey("remoteURI"));
assertTrue(properties.containsKey("secondProperty"));
}

@ParameterizedTest
@ValueSource(strings = {"Camel Route#route-multi.yaml", "KameletBinding#kamelet-binding-multi.yaml",
Expand Down Expand Up @@ -440,7 +467,7 @@ void uniqueName() throws IOException {
@ParameterizedTest
@ValueSource(strings = {"Kamelet#eip.kamelet.yaml", "Integration#integration.yaml",
"Camel Route#route-with-beans.yaml", "Camel Route#rest-dsl-multi.yaml",
"KameletBinding#kamelet-binding.yaml"})
"KameletBinding#kamelet-binding.yaml", "Kamelet#kamelet2.yaml"})
void changeNameAndDescription(String file) throws IOException {

String[] parameters = file.split("#");
Expand Down
56 changes: 56 additions & 0 deletions api/src/test/resources/io/kaoto/backend/api/resource/kamelet2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
name: jms-amqp-10-source
annotations:
camel.apache.org/kamelet.support.level: "Stable"
camel.apache.org/provider: "Apache Software Foundation"
camel.apache.org/catalog.version: "4.0.0-SNAPSHOT"
camel.apache.org/kamelet.group: "JMS"
camel.apache.org/kamelet.namespace: "Messaging"
labels:
camel.apache.org/kamelet.type: "source"
camel.apache.org/requires.runtime: camel-k
spec:
definition:
title: "JMS - AMQP 1.0 Source"
description: "Consume data from any AMQP 1.0 compliant message broker by using the Apache Qpid JMS client."
required:
- destinationName
- remoteURI
type: object
properties:
destinationType:
title: "Destination Type"
description: "The JMS destination type (queue or topic)."
type: string
default: queue
destinationName:
title: "Destination Name"
description: "The JMS destination name."
type: string
remoteURI:
title: "Broker URL"
description: "The JMS URL."
type: string
example: "amqp://my-host:31616"
dependencies:
- "camel:jms"
- "camel:amqp"
- "camel:kamelet"
template:
beans:
- name: connectionFactoryBean
type: "#class:org.apache.qpid.jms.JmsConnectionFactory"
property:
- key: remoteURI
value: '{{remoteURI}}'
- key: secondProperty
value: 'another'
from:
uri: "jms:{{destinationType}}:{{destinationName}}"
parameters:
connectionFactory: "#bean:{{connectionFactoryBean}}"
steps:
- to:
uri: "kamelet:sink"
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.util.List;
import java.util.Map;

import io.kaoto.backend.model.deployment.camelroute.Bean;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.kaoto.backend.model.deployment.camelroute.CamelRoute;
import io.kaoto.backend.model.deployment.kamelet.Bean;
import io.kaoto.backend.model.deployment.rest.HttpVerb;
import io.kaoto.backend.model.deployment.rest.Rest;
import io.kaoto.backend.model.deployment.rest.RestParameter;
Expand Down Expand Up @@ -45,8 +47,11 @@ public Node representData(final Object data) {
new RepresentMap() {
@Override
public Node representData(final Object data) {
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> properties = mapper.convertValue(data,
new TypeReference<Map<String, Object>>() {});
return representMapping(getTag(data.getClass(), Tag.MAP),
((Bean) data).getRepresenterProperties(),
properties,
DumperOptions.FlowStyle.AUTO);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.type.CollectionType;

import io.kaoto.backend.model.deployment.camelroute.Bean;
import io.kaoto.backend.model.deployment.camelroute.CamelRoute;
import io.kaoto.backend.model.deployment.kamelet.Bean;
import io.kaoto.backend.model.deployment.kamelet.Flow;

public class CamelRouteDeserializer extends StdDeserializer<CamelRoute> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.kaoto.backend.KamelPopulator;
import io.kaoto.backend.api.metadata.catalog.StepCatalog;
import io.kaoto.backend.api.service.step.parser.camelroute.CamelRouteDeserializer;
import io.kaoto.backend.model.deployment.kamelet.Bean;
import io.kaoto.backend.model.deployment.kamelet.Flow;
import io.kaoto.backend.model.deployment.rest.HttpVerb;
import io.kaoto.backend.model.deployment.rest.Rest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;


/**
Expand Down Expand Up @@ -43,8 +45,8 @@ public Bean() {
private String name;
@JsonProperty("type")
private String type;
@JsonProperty("property")
private List<Property> property;
@JsonProperty("properties")
private Map<String, Object> properties;

public String getName() {
return name;
Expand All @@ -62,12 +64,21 @@ public void setType(final String type) {
this.type = type;
}

public List<Property> getProperty() {
return property;
@JsonProperty("property")
public void setProperty(final List<Property> property) {
if (this.properties == null) {
this.properties = new LinkedHashMap<>();
}
for (Property prop : property) {
this.properties.put(prop.getKey(), prop.getValue());
}
}

public Map<String, Object> getProperties() {
return properties;
}

public void setProperty(
final List<Property> property) {
this.property = property;
public void setProperties(Map<String, Object> properties) {
this.properties = properties;
}
}

0 comments on commit 0b39358

Please sign in to comment.