karavan-core 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/.bebelrc +3 -0
  2. package/.mocharc.json +11 -0
  3. package/.prettierignore +9 -0
  4. package/.prettierrc +14 -0
  5. package/package.json +62 -0
  6. package/src/core/api/CamelDefinitionApi.ts +3271 -0
  7. package/src/core/api/CamelDefinitionApiExt.ts +757 -0
  8. package/src/core/api/CamelDefinitionYaml.ts +412 -0
  9. package/src/core/api/CamelDefinitionYamlStep.ts +4733 -0
  10. package/src/core/api/CamelDisplayUtil.ts +143 -0
  11. package/src/core/api/CamelUtil.ts +360 -0
  12. package/src/core/api/ComponentApi.ts +368 -0
  13. package/src/core/api/KameletApi.ts +147 -0
  14. package/src/core/api/MainConfigurationApi.ts +47 -0
  15. package/src/core/api/ProjectModelApi.ts +75 -0
  16. package/src/core/api/SpiBeanApi.ts +104 -0
  17. package/src/core/api/TemplateApi.ts +58 -0
  18. package/src/core/api/TopologyUtils.ts +392 -0
  19. package/src/core/api/VariableUtil.ts +104 -0
  20. package/src/core/model/CamelDefinition.ts +3783 -0
  21. package/src/core/model/CamelMetadata.ts +2714 -0
  22. package/src/core/model/ComponentModels.ts +106 -0
  23. package/src/core/model/IntegrationDefinition.ts +188 -0
  24. package/src/core/model/KameletModels.ts +223 -0
  25. package/src/core/model/MainConfigurationModel.ts +37 -0
  26. package/src/core/model/ProjectModel.ts +43 -0
  27. package/src/core/model/SpiBeanModels.ts +53 -0
  28. package/src/core/model/TopologyDefinition.ts +117 -0
  29. package/test/addStep.spec.ts +124 -0
  30. package/test/addStep1.yaml +27 -0
  31. package/test/allowableValues.camel.yaml +19 -0
  32. package/test/allowableValues.spec.ts +30 -0
  33. package/test/avro-serialize-action.kamelet.yaml +70 -0
  34. package/test/beans.spec.ts +92 -0
  35. package/test/beans1.yaml +36 -0
  36. package/test/beans2.yaml +42 -0
  37. package/test/beans3.yaml +7 -0
  38. package/test/checkRequired.spec.ts +53 -0
  39. package/test/circuitBreaker.spec.ts +57 -0
  40. package/test/circuitBreaker.yaml +19 -0
  41. package/test/cloneDefinition.spec.ts +106 -0
  42. package/test/createKamelet.spec.ts +38 -0
  43. package/test/cxf.json +615 -0
  44. package/test/cxf.spec.ts +44 -0
  45. package/test/cxf.yaml +15 -0
  46. package/test/deleteStep.spec.ts +74 -0
  47. package/test/demo.spec.ts +49 -0
  48. package/test/demo.yaml +32 -0
  49. package/test/doCatchOnWhen.camel.yaml +20 -0
  50. package/test/doCatchOnWhen.spec.ts +36 -0
  51. package/test/errorHandler.spec.ts +38 -0
  52. package/test/errorHandler1.yaml +27 -0
  53. package/test/expression.spec.ts +55 -0
  54. package/test/findStep.spec.ts +112 -0
  55. package/test/findStep.yaml +65 -0
  56. package/test/getElementProperties.spec.ts +32 -0
  57. package/test/getElementPropertiesByName.spec.ts +31 -0
  58. package/test/getExpressionLanguage.spec.ts +40 -0
  59. package/test/hasElementWithId.camel.yaml +98 -0
  60. package/test/hasElementWithId.spec.ts +57 -0
  61. package/test/hasElementWithId1.camel.yaml +16 -0
  62. package/test/hasElementWithIdError.camel.yaml +98 -0
  63. package/test/integration.spec.ts +60 -0
  64. package/test/integration1.yaml +24 -0
  65. package/test/integration2.yaml +23 -0
  66. package/test/integrationToYaml.spec.ts +51 -0
  67. package/test/intercept.spec.ts +62 -0
  68. package/test/intercept.yaml +19 -0
  69. package/test/is-not-integration.yaml +5114 -0
  70. package/test/isIntegration.spec.ts +45 -0
  71. package/test/kamelet.spec.ts +61 -0
  72. package/test/metadata/components.json +697 -0
  73. package/test/metadata/kamelets.yaml +23414 -0
  74. package/test/metadata/spiBeans.json +3094 -0
  75. package/test/multiObjectProperties.spec.ts +46 -0
  76. package/test/multiObjectProperties1.yaml +19 -0
  77. package/test/multiple.spec.ts +38 -0
  78. package/test/multiple.yaml +29 -0
  79. package/test/openapi.spec.ts +48 -0
  80. package/test/openapi.yaml +7 -0
  81. package/test/placeholder.spec.ts +32 -0
  82. package/test/placeholder.yaml +133 -0
  83. package/test/plain-try-catch.yaml +31 -0
  84. package/test/plain.spec.ts +72 -0
  85. package/test/plain1.yaml +22 -0
  86. package/test/plain2.yaml +13 -0
  87. package/test/plain3.yaml +5 -0
  88. package/test/plain4.yaml +5 -0
  89. package/test/postgresql-source.kamelet.yaml +113 -0
  90. package/test/restConfigDsl.yaml +15 -0
  91. package/test/restDsl.spec.ts +83 -0
  92. package/test/restDsl.yaml +29 -0
  93. package/test/routes.spec.ts +37 -0
  94. package/test/routes1.yaml +31 -0
  95. package/test/supported-components.json +1221 -0
  96. package/test/supportedComponents.spec.ts +34 -0
  97. package/test/template1.AggregationStrategy.java +21 -0
  98. package/test/template1.Processor.java +13 -0
  99. package/test/template2.AggregationStrategy.java +21 -0
  100. package/test/template2.Processor.java +13 -0
  101. package/test/templateApi.spec.ts +45 -0
  102. package/test/timer-source.kamelet.yaml +75 -0
  103. package/test/tod.spec.ts +31 -0
  104. package/test/tod.yaml +9 -0
  105. package/test/topology.spec.ts +51 -0
  106. package/test/topology1.camel.yaml +56 -0
  107. package/test/topology2.camel.yaml +44 -0
  108. package/test/topology3.camel.yaml +27 -0
  109. package/test/tsconfig.testing.json +14 -0
  110. package/test/updateStep.spec.ts +72 -0
  111. package/test/variable1.camel.yaml +42 -0
  112. package/test/variable2.camel.yaml +42 -0
  113. package/test/variables.spec.ts +34 -0
  114. package/tsconfig.json +34 -0
@@ -0,0 +1,117 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import { CamelElement } from './IntegrationDefinition';
19
+ import { FromDefinition, RestDefinition, RouteConfigurationDefinition, RouteDefinition } from './CamelDefinition';
20
+
21
+ export class TopologyRestNode {
22
+ path: string;
23
+ id: string;
24
+ uris: string[];
25
+ title: string;
26
+ fileName: string;
27
+ rest: RestDefinition;
28
+
29
+ constructor(path: string, id: string, uris: string[], title: string, fileName: string, rest: RestDefinition) {
30
+ this.path = path;
31
+ this.id = id;
32
+ this.uris = uris;
33
+ this.title = title;
34
+ this.fileName = fileName;
35
+ this.rest = rest;
36
+ }
37
+ }
38
+
39
+ export class TopologyIncomingNode {
40
+ id: string;
41
+ type: 'internal' | 'external';
42
+ connectorType: 'component' | 'kamelet';
43
+ routeId: string;
44
+ title: string;
45
+ fileName: string;
46
+ from: FromDefinition;
47
+ uniqueUri?: string;
48
+
49
+
50
+ constructor(id: string, type: "internal" | "external", connectorType: "component" | "kamelet", routeId: string, title: string, fileName: string, from: FromDefinition, uniqueUri: string) {
51
+ this.id = id;
52
+ this.type = type;
53
+ this.connectorType = connectorType;
54
+ this.routeId = routeId;
55
+ this.title = title;
56
+ this.fileName = fileName;
57
+ this.from = from;
58
+ this.uniqueUri = uniqueUri;
59
+ }
60
+ }
61
+
62
+ export class TopologyRouteNode {
63
+ id: string;
64
+ routeId: string;
65
+ title: string;
66
+ fileName: string;
67
+ from: FromDefinition;
68
+ route: RouteDefinition
69
+
70
+ constructor(id: string, routeId: string, title: string, fileName: string, from: FromDefinition, route: RouteDefinition) {
71
+ this.id = id;
72
+ this.routeId = routeId;
73
+ this.title = title;
74
+ this.fileName = fileName;
75
+ this.from = from;
76
+ this.route = route;
77
+ }
78
+ }
79
+
80
+ export class TopologyRouteConfigurationNode {
81
+ id: string;
82
+ routeConfigurationId: string;
83
+ title: string;
84
+ fileName: string;
85
+ routeConfiguration: RouteConfigurationDefinition
86
+
87
+ constructor(id: string, routeConfigurationId: string, title: string, fileName: string, routeConfiguration: RouteConfigurationDefinition) {
88
+ this.id = id;
89
+ this.routeConfigurationId = routeConfigurationId;
90
+ this.title = title;
91
+ this.fileName = fileName;
92
+ this.routeConfiguration = routeConfiguration;
93
+ }
94
+ }
95
+
96
+ export class TopologyOutgoingNode {
97
+ id: string;
98
+ type: 'internal' | 'external';
99
+ connectorType: 'component' | 'kamelet';
100
+ routeId: string;
101
+ title: string;
102
+ fileName: string;
103
+ step: CamelElement;
104
+ uniqueUri?: string;
105
+
106
+
107
+ constructor(id: string, type: "internal" | "external", connectorType: "component" | "kamelet", routeId: string, title: string, fileName: string, step: CamelElement, uniqueUri: string) {
108
+ this.id = id;
109
+ this.type = type;
110
+ this.connectorType = connectorType;
111
+ this.routeId = routeId;
112
+ this.title = title;
113
+ this.fileName = fileName;
114
+ this.step = step;
115
+ this.uniqueUri = uniqueUri;
116
+ }
117
+ }
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import {expect} from 'chai';
18
+ import 'mocha';
19
+ import {
20
+ FromDefinition,
21
+ LogDefinition,
22
+ WhenDefinition,
23
+ ChoiceDefinition,
24
+ MulticastDefinition,
25
+ ExpressionDefinition,
26
+ RouteDefinition, TryDefinition,CatchDefinition
27
+ } from "../src/core/model/CamelDefinition";
28
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
29
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
30
+ import {SimpleExpression} from "../src/core/model/CamelDefinition";
31
+ import {Integration} from "../src/core/model/IntegrationDefinition";
32
+ import * as fs from 'fs';
33
+
34
+ describe('Add Step', () => {
35
+
36
+ it('Add Step', () => {
37
+ const i = Integration.createNew("test")
38
+
39
+ const when1 = new WhenDefinition({
40
+ expression: new ExpressionDefinition({simple: '$[body} != null'}),
41
+ steps: [new LogDefinition({logName: 'log11', message: "hello11"})]
42
+ })
43
+ const choice = new ChoiceDefinition({when: [when1]})
44
+ const flow1 = new FromDefinition({uri: "direct1"});
45
+
46
+ flow1.steps?.push(choice);
47
+ i.spec.flows?.push(new RouteDefinition({from:flow1}));
48
+
49
+ const when2 = new WhenDefinition({
50
+ expression: new ExpressionDefinition({simple: '$[body} != "null"'}),
51
+ steps: [new LogDefinition({logName: 'log22', message: "hello22"})]
52
+ })
53
+ const i2 = CamelDefinitionApiExt.addStepToIntegration(i, when2, choice.uuid);
54
+
55
+ if (i2.spec.flows && i2.spec.flows.length > 0) {
56
+ const f: FromDefinition = i2.spec.flows[0].from;
57
+ const c: ChoiceDefinition = f.steps ? f.steps[0] : new ChoiceDefinition();
58
+ const w = c.when ? c.when[1] : undefined;
59
+ expect(c?.when?.length).to.equal(2);
60
+ }
61
+ });
62
+
63
+ it('Add step to Otherwise', () => {
64
+ const yaml = fs.readFileSync('test/addStep1.yaml',{encoding:'utf8', flag:'r'});
65
+ const i1 = CamelDefinitionYaml.yamlToIntegration("test1.yaml", yaml);
66
+
67
+ if (i1.spec.flows && i1.spec.flows.length > 0) {
68
+ const r: RouteDefinition = i1.spec.flows[0];
69
+ const c: ChoiceDefinition = r ? r.from?.steps[1] : new ChoiceDefinition();
70
+ const parentUuid = c.otherwise?.uuid || "";
71
+
72
+ const step: MulticastDefinition = new MulticastDefinition();
73
+ const i2 = CamelDefinitionApiExt.addStepToIntegration(i1, step, parentUuid);
74
+
75
+ if (i2.spec.flows) {
76
+ expect(i2.spec.flows[0].from.steps[1].otherwise.steps.length).to.equal(1);
77
+ }
78
+ }
79
+ });
80
+
81
+ it('Add step to Catch', () => {
82
+ const yaml = fs.readFileSync('test/addStep1.yaml',{encoding:'utf8', flag:'r'});
83
+ const i1 = CamelDefinitionYaml.yamlToIntegration("test1.yaml", yaml);
84
+
85
+ if (i1.spec.flows && i1.spec.flows.length > 0) {
86
+ const r: RouteDefinition = i1.spec.flows[0];
87
+ const t: TryDefinition = r ? r.from?.steps[0] : new TryDefinition();
88
+ const c: CatchDefinition = t.doCatch ? t.doCatch[0] : new CatchDefinition();
89
+ const parentUuid = c.uuid || "";
90
+
91
+ const w: WhenDefinition = new WhenDefinition({expression: new ExpressionDefinition({simple: new SimpleExpression({expression:"${body} != null"})})});
92
+ const i2 = CamelDefinitionApiExt.addStepToIntegration(i1, w, parentUuid);
93
+
94
+ if (i2.spec.flows) {
95
+ expect(i2.spec.flows[0].from.steps[0].doCatch[0].onWhen.expression.simple.expression).to.equal("${body} != null");
96
+ }
97
+ }
98
+ });
99
+
100
+ it('Add Step to position', () => {
101
+ const i = Integration.createNew("test")
102
+
103
+ const log1 =new LogDefinition({logName: 'log11', message: "hello11"});
104
+ const log2 =new LogDefinition({logName: 'log11', message: "hello22"});
105
+ const log3 =new LogDefinition({logName: 'log11', message: "hello33"});
106
+
107
+ const from = new FromDefinition({uri: "direct1"});
108
+ from.steps?.push(log1);
109
+ from.steps?.push(log2);
110
+ from.steps?.push(log3);
111
+ i.spec.flows?.push(new RouteDefinition({from:from}));
112
+
113
+ const choice = new ChoiceDefinition({})
114
+ const i2 = CamelDefinitionApiExt.addStepToIntegration(i, choice, from.uuid, 2);
115
+
116
+ if (i2.spec.flows && i2.spec.flows.length > 0) {
117
+ const f: FromDefinition = i2.spec.flows[0].from;
118
+ const c: ChoiceDefinition = f.steps[2];
119
+ expect(c?.dslName).to.equal('ChoiceDefinition');
120
+
121
+ }
122
+ });
123
+
124
+ });
@@ -0,0 +1,27 @@
1
+ apiVersion: camel.apache.org/v1
2
+ kind: Integration
3
+ metadata:
4
+ name: ''
5
+ spec:
6
+ flows:
7
+ - from:
8
+ uri: kamelet:http-secured-source
9
+ steps:
10
+ - do-try:
11
+ steps:
12
+ - to: "log:when-a"
13
+ - to: "log:when-b"
14
+ do-catch:
15
+ - exception:
16
+ - "java.io.FileNotFoundException"
17
+ - "java.io.IOException"
18
+ on-when:
19
+ simple: "${body.size()} == 1"
20
+ steps:
21
+ - to: "log:io-error"
22
+ - choice:
23
+ when:
24
+ - expression: {}
25
+ steps:
26
+ - tod: {}
27
+ otherwise: {}
@@ -0,0 +1,19 @@
1
+ - rest:
2
+ id: rest-b536
3
+ get:
4
+ - id: metadata
5
+ path: /metadata
6
+ to: direct:metadata
7
+ param:
8
+ - description: Requests the server to return a designated subset of the resource
9
+ name: _summary
10
+ type: query
11
+ required: false
12
+ collectionFormat: multi
13
+ dataType: string
14
+ allowableValues:
15
+ - "true"
16
+ - text
17
+ - data
18
+ - count
19
+ - "false"
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import {expect} from 'chai';
18
+ import 'mocha';
19
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
20
+ import * as fs from 'fs';
21
+
22
+ describe('Array of string', () => {
23
+
24
+ it('Array of string', () => {
25
+ const yaml = fs.readFileSync('test/allowableValues.camel.yaml', { encoding: 'utf8', flag: 'r' });
26
+ const i = CamelDefinitionYaml.yamlToIntegration('allowableValues.camel.yaml', yaml);
27
+ const yaml2 = CamelDefinitionYaml.integrationToYaml(i);
28
+ expect(yaml2).to.equal(yaml);
29
+ });
30
+ });
@@ -0,0 +1,70 @@
1
+ # ---------------------------------------------------------------------------
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership.
5
+ # The ASF licenses this file to You under the Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ # ---------------------------------------------------------------------------
17
+
18
+ apiVersion: camel.apache.org/v1
19
+ kind: Kamelet
20
+ metadata:
21
+ name: avro-serialize-action
22
+ annotations:
23
+ camel.apache.org/kamelet.support.level: "Stable"
24
+ camel.apache.org/catalog.version: "4.6.0-SNAPSHOT"
25
+ camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My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AvPgogIDwvZz4KPC9zdmc+Cg=="
26
+ camel.apache.org/provider: "Apache Software Foundation"
27
+ camel.apache.org/kamelet.group: "Actions"
28
+ camel.apache.org/kamelet.namespace: "Transformation"
29
+ labels:
30
+ camel.apache.org/kamelet.type: "action"
31
+ spec:
32
+ definition:
33
+ title: "Avro Serialize Action"
34
+ description: "Serialize payload to Avro"
35
+ type: object
36
+ properties:
37
+ schema:
38
+ title: Schema
39
+ description: The Avro schema to use during serialization (as single-line, using JSON format)
40
+ type: string
41
+ example: '{"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]}'
42
+ validate:
43
+ title: Validate
44
+ description: Indicates if the content must be validated against the schema
45
+ type: boolean
46
+ default: true
47
+ dependencies:
48
+ - "camel:kamelet"
49
+ - "camel:core"
50
+ - "camel:jackson-avro"
51
+ template:
52
+ beans:
53
+ - name: schemaResolver
54
+ type: "#class:org.apache.camel.component.jackson.avro.transform.AvroSchemaResolver"
55
+ property:
56
+ - key: validate
57
+ value: '{{validate}}'
58
+ - key: schema
59
+ value: '{{schema:}}'
60
+ from:
61
+ uri: kamelet:source
62
+ steps:
63
+ - marshal:
64
+ avro:
65
+ library: Jackson
66
+ unmarshalType: com.fasterxml.jackson.databind.JsonNode
67
+ schemaResolver: "#bean:{{schemaResolver}}"
68
+ - setHeader:
69
+ name: "Content-Type"
70
+ constant: "application/avro"
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { expect } from 'chai';
18
+ import * as fs from 'fs';
19
+ import 'mocha';
20
+ import { CamelDefinitionYaml } from '../src/core/api/CamelDefinitionYaml';
21
+ import { Beans, Integration } from '../src/core/model/IntegrationDefinition';
22
+ import { BeanFactoryDefinition } from '../src/core/model/CamelDefinition';
23
+
24
+ describe('bean configuration', () => {
25
+
26
+ it('Read beans from plain YAML', () => {
27
+ const yaml = fs.readFileSync('test/beans1.yaml', { encoding: 'utf8', flag: 'r' });
28
+ const i = CamelDefinitionYaml.yamlToIntegration('beans.yaml', yaml);
29
+ expect(i.metadata.name).to.equal('beans.yaml');
30
+ expect(i.kind).to.equal('Integration');
31
+ expect(i.spec.flows?.length).to.equal(3);
32
+ expect(i.type).to.equal('plain');
33
+ if (i.spec.flows) {
34
+ expect(i.spec.flows[2].beans[0].name).to.equal('myNested');
35
+ expect(i.spec.flows[2].beans[0].type).to.equal('${MyBean.class.name}');
36
+ expect(i.spec.flows[2].beans[0].properties['nested.foo']).to.equal('valueFoo');
37
+ expect(i.spec.flows[2].beans[1].name).to.equal('myProps');
38
+ }
39
+ CamelDefinitionYaml.integrationToYaml(i)
40
+ });
41
+
42
+ it('Read beans from Integration', () => {
43
+ const yaml = fs.readFileSync('test/beans2.yaml', { encoding: 'utf8', flag: 'r' });
44
+ const i = CamelDefinitionYaml.yamlToIntegration('beans.yaml', yaml);
45
+ expect(i.metadata.name).to.equal('Beans');
46
+ expect(i.kind).to.equal('Integration');
47
+ expect(i.spec.flows?.length).to.equal(3);
48
+ expect(i.type).to.equal('crd');
49
+ if (i.spec.flows) {
50
+ expect(i.spec.flows[2].beans[0].name).to.equal('myNested');
51
+ expect(i.spec.flows[2].beans[0].type).to.equal('${MyBean.class.name}');
52
+ expect(i.spec.flows[2].beans[0].properties['nested.foo']).to.equal('valueFoo');
53
+ expect(i.spec.flows[2].beans[1].name).to.equal('myProps');
54
+ }
55
+ });
56
+
57
+ function countSubstring(str: string, search: string): number {
58
+ if (search.length === 0) {
59
+ return 0; // Avoid infinite loops for empty search strings
60
+ }
61
+
62
+ let count = 0;
63
+ let pos = 0;
64
+
65
+ // Loop to find all occurrences of 'search'
66
+ while ((pos = str.indexOf(search, pos)) !== -1) {
67
+ count++; // Increment count for each occurrence found
68
+ pos += search.length; // Move past the last found substring to find next
69
+ }
70
+
71
+ return count;
72
+ }
73
+
74
+ it('Bean constructor', () => {
75
+ const text = fs.readFileSync('test/beans3.yaml', { encoding: 'utf8', flag: 'r' });
76
+ const i = CamelDefinitionYaml.yamlToIntegration('beans.yaml', text);
77
+
78
+ const b = Integration.createNew('beans');
79
+ const bean1 = new BeanFactoryDefinition({
80
+ name: 'Name1', type: 'Type', constructors: {
81
+ 0: 'zero',
82
+ 1: 'one',
83
+ 2: 'two',
84
+ }
85
+ });
86
+ const bean2 = new BeanFactoryDefinition({ name: 'Name2', type: 'Type'});
87
+ b.spec.flows?.push(new Beans({beans: [bean1, bean2]}));
88
+ const yaml = CamelDefinitionYaml.integrationToYaml(b);
89
+ expect(countSubstring(yaml, 'constructors')).to.equal(1);
90
+ });
91
+
92
+ });
@@ -0,0 +1,36 @@
1
+ - beans:
2
+ - name: myNested
3
+ type: ${MyBean.class.name}
4
+ properties:
5
+ field1: 'value1'
6
+ field2: 'value2'
7
+ nested:
8
+ foo: 'valueFoo'
9
+ bar: 'valueBar'
10
+ - name: myProps
11
+ type: ${MyBean.class.name}
12
+ properties:
13
+ field1: 'f1_p'
14
+ field2: 'f2_p'
15
+ nested.foo: 'nf1_p'
16
+ nested.bar: 'nf2_p'
17
+ - from:
18
+ uri: "direct:route"
19
+ steps:
20
+ - aggregate:
21
+ strategy-ref: "myAggregatorStrategy"
22
+ completion-size: 2
23
+ correlation-expression:
24
+ simple: "${header.StockSymbol}"
25
+ steps:
26
+ - to: "mock:route"
27
+ - from:
28
+ uri: "direct:route"
29
+ steps:
30
+ - aggregate:
31
+ strategy-ref: "myAggregatorStrategy"
32
+ completion-size: 2
33
+ correlation-expression:
34
+ simple: "${header.StockSymbol}"
35
+ steps:
36
+ - to: "mock:route"
@@ -0,0 +1,42 @@
1
+ apiVersion: camel.apache.org/v1
2
+ kind: Integration
3
+ metadata:
4
+ name: Beans
5
+ spec:
6
+ flows:
7
+ - beans:
8
+ - name: myNested
9
+ type: ${MyBean.class.name}
10
+ properties:
11
+ field1: 'value1'
12
+ field2: 'value2'
13
+ nested:
14
+ foo: 'valueFoo'
15
+ bar: 'valueBar'
16
+ - name: myProps
17
+ type: ${MyBean.class.name}
18
+ properties:
19
+ field1: 'f1_p'
20
+ field2: 'f2_p'
21
+ nested.foo: 'nf1_p'
22
+ nested.bar: 'nf2_p'
23
+ - from:
24
+ uri: "direct:route"
25
+ steps:
26
+ - aggregate:
27
+ strategy-ref: "myAggregatorStrategy"
28
+ completion-size: 2
29
+ correlation-expression:
30
+ simple: "${header.StockSymbol}"
31
+ steps:
32
+ - to: "mock:route"
33
+ - from:
34
+ uri: "direct:route"
35
+ steps:
36
+ - aggregate:
37
+ strategy-ref: "myAggregatorStrategy"
38
+ completion-size: 2
39
+ correlation-expression:
40
+ simple: "${header.StockSymbol}"
41
+ steps:
42
+ - to: "mock:route"
@@ -0,0 +1,7 @@
1
+ - beans:
2
+ - constructors:
3
+ 0: zero
4
+ 1: one
5
+ 2: two
6
+ name: Name
7
+ type: Type
@@ -0,0 +1,53 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import {expect} from 'chai';
18
+ import 'mocha';
19
+ import {
20
+ LogDefinition, ExpressionDefinition, SplitDefinition, SimpleExpression
21
+ } from "../src/core/model/CamelDefinition";
22
+ import {CamelDefinitionApi} from "../src/core/api/CamelDefinitionApi";
23
+ import {CamelUtil} from "../src/core/api/CamelUtil";
24
+ import { SetHeaderDefinition } from '../src/core/model/CamelDefinition';
25
+
26
+ describe('Check required properties', () => {
27
+
28
+ it('Check Log DSL', () => {
29
+ const log: LogDefinition = CamelDefinitionApi.createLogDefinition({});
30
+ expect(CamelUtil.checkRequired(log)[0]).to.equal(false);
31
+ log.message = '${body}'
32
+ expect(CamelUtil.checkRequired(log)[0]).to.equal(true);
33
+ });
34
+
35
+ it('Check SetHeader DSL', () => {
36
+ const setHeader: SetHeaderDefinition = CamelDefinitionApi.createSetHeaderDefinition({});
37
+ setHeader.expression = new ExpressionDefinition({simple: new SimpleExpression({expression: '${body}'})})
38
+ const check = CamelUtil.checkRequired(setHeader);
39
+ expect(check[0]).to.equal(false);
40
+ setHeader.name = 'header1'
41
+ expect(CamelUtil.checkRequired(setHeader)[0]).to.equal(true);
42
+ });
43
+
44
+ it('Check Split DSL', () => {
45
+ const split: SplitDefinition = CamelDefinitionApi.createSplitDefinition({});
46
+ expect(CamelUtil.checkRequired(split)[0]).to.equal(false);
47
+ split.expression = new ExpressionDefinition({simple: new SimpleExpression()})
48
+ expect(CamelUtil.checkRequired(split)[0]).to.equal(false);
49
+ split.expression = new ExpressionDefinition({simple: new SimpleExpression({expression: "${body} !== null"})})
50
+ expect(CamelUtil.checkRequired(split)[0]).to.equal(true);
51
+ });
52
+
53
+ });