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,74 @@
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 {FromDefinition, LogDefinition, WhenDefinition, ChoiceDefinition, ExpressionDefinition} from "../src/core/model/CamelDefinition";
20
+ import {CamelUtil} from "../src/core/api/CamelUtil";
21
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
22
+ import {FilterDefinition, RouteDefinition, SimpleExpression} from "../src/core/model/CamelDefinition";
23
+ import {Integration} from "../src/core/model/IntegrationDefinition";
24
+
25
+ describe('Delete Step', () => {
26
+
27
+ it('Delete Expression in When clause', () => {
28
+ const i = Integration.createNew("test")
29
+ const log1 =new LogDefinition({logName: 'log11', message: "hello11"});
30
+ const log2 =new LogDefinition({logName: 'log11', message: "hello22"});
31
+ const log3 =new LogDefinition({logName: 'log11', message: "hello33"});
32
+ const when1 = new WhenDefinition({
33
+ expression:new ExpressionDefinition({simple: new SimpleExpression({expression: '$[body} != null'})}),
34
+ steps:[log1, log2, log3]
35
+ })
36
+ const choice = new ChoiceDefinition({when:[when1]})
37
+ const from1 = new FromDefinition({uri: "direct1"});
38
+ from1.steps?.push(choice);
39
+ i.spec.flows?.push(new RouteDefinition({from: from1}));
40
+ const when2:WhenDefinition = CamelUtil.cloneStep(when1);
41
+ if (when2 && when2.expression){
42
+ when2.expression.simple = new SimpleExpression({expression: '$[body} == "hello world"'});
43
+ }
44
+ const i2 = CamelDefinitionApiExt.deleteStepFromIntegration(i, log2.uuid);
45
+ if (i2.spec.flows && i2.spec.flows.length > 0){
46
+ const f:FromDefinition = i2.spec.flows[0].from;
47
+ const c:ChoiceDefinition = f.steps ? f.steps[0] : new ChoiceDefinition();
48
+ const w = c.when ? c.when[0] : undefined;
49
+ expect(w?.steps?.length).to.equal(2);
50
+ }
51
+ });
52
+
53
+ it('Delete Step from Filter clause', () => {
54
+ const i = Integration.createNew("test")
55
+ const log1 =new LogDefinition({logName: 'log11', message: "hello11"});
56
+ const log2 =new LogDefinition({logName: 'log11', message: "hello22"});
57
+ const log3 =new LogDefinition({logName: 'log11', message: "hello33"});
58
+ const filter = new FilterDefinition({
59
+ expression:new ExpressionDefinition({simple: new SimpleExpression({expression: '$[body} != null'})}),
60
+ steps:[log1, log2, log3]
61
+ })
62
+ const from = new FromDefinition({uri: "direct1"});
63
+ from.steps?.push(filter);
64
+ i.spec.flows?.push(new RouteDefinition({from: from}));
65
+
66
+
67
+ const i2 = CamelDefinitionApiExt.deleteStepFromIntegration(i, log2.uuid);
68
+ if (i2.spec.flows && i2.spec.flows.length > 0){
69
+ const from:FromDefinition = i2.spec.flows[0].from;
70
+ const f:FilterDefinition = from.steps ? from.steps[0] : new FilterDefinition();
71
+ expect(f.steps?.length).to.equal(2);
72
+ }
73
+ });
74
+ });
@@ -0,0 +1,49 @@
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 * as fs from 'fs';
18
+ import 'mocha';
19
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
20
+ import {CamelUtil} from "../src/core/api/CamelUtil";
21
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
22
+ import {CatchDefinition, FromDefinition} from "../src/core/model/CamelDefinition";
23
+ import {expect} from "chai";
24
+ import {TryDefinition} from "../src/core/model/CamelDefinition";
25
+
26
+ describe('Demo', () => {
27
+
28
+ it('Demo', () => {
29
+ const yaml = fs.readFileSync('test/demo.yaml',{encoding:'utf8', flag:'r'});
30
+ const i = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
31
+ const i2 = CamelUtil.cloneIntegration(i);
32
+
33
+ if (i2.spec.flows) {
34
+ const f: FromDefinition = i2.spec.flows[0].from;
35
+ const td: TryDefinition = f.steps[0];
36
+ if (td.doCatch) {
37
+ const c: CatchDefinition | undefined = td.doCatch[0];
38
+ const uuid = c.onWhen?.uuid || '';
39
+ expect(uuid.length).to.above(0)
40
+ const i3 = CamelDefinitionApiExt.deleteStepFromIntegration(i, uuid);
41
+ if (i3.spec.flows && i3.spec.flows.length > 0) {
42
+ const w = i3.spec.flows[0].from.steps[0].doCatch[0].onWhen;
43
+ expect(w).to.equal(undefined);
44
+ }
45
+ }
46
+ }
47
+ });
48
+
49
+ });
package/test/demo.yaml ADDED
@@ -0,0 +1,32 @@
1
+ apiVersion: camel.apache.org/v1
2
+ kind: Integration
3
+ metadata:
4
+ name: 'demo'
5
+ spec:
6
+ flows:
7
+ - route:
8
+ from:
9
+ uri: kamelet:http-secured-source
10
+ steps:
11
+ - doTry:
12
+ steps:
13
+ - to: "log:when-a"
14
+ - to: "log:when-b"
15
+ doCatch:
16
+ - exception:
17
+ - "java.io.FileNotFoundException"
18
+ - "java.io.IOException"
19
+ onWhen:
20
+ expression:
21
+ simple: "${body.size()} == 1"
22
+ steps:
23
+ - to: "log:io-error"
24
+ - choice:
25
+ when:
26
+ - expression:
27
+ simple: "${body.size()} == 1"
28
+ steps:
29
+ - toD: "log:xxx"
30
+ otherwise:
31
+ steps:
32
+ - toD: "log:yyy"
@@ -0,0 +1,20 @@
1
+ - route:
2
+ id: route-8a40
3
+ nodePrefixId: route-78f
4
+ from:
5
+ id: from-674b
6
+ uri: timer
7
+ parameters:
8
+ timerName: name
9
+ steps:
10
+ - doTry:
11
+ id: doTry-258c
12
+ doCatch:
13
+ - id: doCatch-32ac
14
+ exception:
15
+ - java.lang.ArrayIndexOutOfBoundsException
16
+ onWhen:
17
+ id: when-b4f0
18
+ expression:
19
+ groovy:
20
+ id: groovy-2d4f
@@ -0,0 +1,36 @@
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 * as fs from 'fs';
18
+ import 'mocha';
19
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
20
+ import {CamelUtil} from "../src/core/api/CamelUtil";
21
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
22
+ import {CatchDefinition, FromDefinition} from "../src/core/model/CamelDefinition";
23
+ import {expect} from "chai";
24
+ import {TryDefinition} from "../src/core/model/CamelDefinition";
25
+
26
+ describe('DoCatch', () => {
27
+
28
+ it('on When', () => {
29
+ const yaml = fs.readFileSync('test/doCatchOnWhen.camel.yaml',{encoding:'utf8', flag:'r'});
30
+ const i = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
31
+ const yaml2 = CamelDefinitionYaml.integrationToYaml(i);
32
+
33
+ expect(yaml2).to.equal(yaml);
34
+ });
35
+
36
+ });
@@ -0,0 +1,38 @@
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 * as jsYaml from 'js-yaml';
20
+ import 'mocha';
21
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
22
+
23
+
24
+ describe('Global Error Handler', () => {
25
+
26
+ it('Read Global Error Handler from plain YAML', () => {
27
+ const yaml = fs.readFileSync('test/errorHandler1.yaml', {encoding: 'utf8', flag: 'r'});
28
+ const i = CamelDefinitionYaml.yamlToIntegration("errorHandler1.yaml", yaml);
29
+ expect(i.metadata.name).to.equal('errorHandler1.yaml');
30
+ expect(i.spec.flows?.length).to.equal(2);
31
+ expect(i.type).to.equal('plain');
32
+ expect(i.spec.flows?.[1].errorHandler.deadLetterChannel.deadLetterUri).to.equal('log:dlq');
33
+ expect(i.spec.flows?.[1].errorHandler.deadLetterChannel.useOriginalMessage).to.equal(true);
34
+ expect(i.spec.flows?.[1].errorHandler.deadLetterChannel.level).to.equal('TRACE');
35
+ const yaml2 = CamelDefinitionYaml.integrationToYaml(i);
36
+ expect(yaml.replaceAll("\r\n", "\n")).to.equal(yaml2); // replace for Windows compatibility
37
+ });
38
+ });
@@ -0,0 +1,27 @@
1
+ - route:
2
+ id: route-1
3
+ from:
4
+ id: from-1
5
+ uri: kamelet:timer-source
6
+ parameters:
7
+ period: 1000
8
+ message: "1"
9
+ steps:
10
+ - setBody:
11
+ id: setBody-1
12
+ expression:
13
+ groovy:
14
+ id: groovy-10a6
15
+ expression: 1000 / 0
16
+ - log:
17
+ id: log-1
18
+ message: $[body}
19
+ - routeConfiguration:
20
+ id: routeConfiguration-1
21
+ errorHandler:
22
+ id: errorHandler-1
23
+ deadLetterChannel:
24
+ id: deadLetterChannel-1
25
+ deadLetterUri: log:dlq
26
+ useOriginalMessage: true
27
+ level: TRACE
@@ -0,0 +1,55 @@
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 {
22
+ ChoiceDefinition,
23
+ ExpressionDefinition,
24
+ FromDefinition,
25
+ LogDefinition,
26
+ OtherwiseDefinition,
27
+ SimpleExpression,
28
+ ToDefinition,
29
+ WhenDefinition
30
+ } from "../src/core/model/CamelDefinition";
31
+ import { RouteDefinition} from "../src/core/model/CamelDefinition";
32
+ import {Integration} from "../src/core/model/IntegrationDefinition";
33
+ import {AggregateDefinition, ExpressionSubElementDefinition, FilterDefinition} from "../src/core/model/CamelDefinition";
34
+
35
+ describe('Expression to yaml', () => {
36
+
37
+ it('Aggregate Expression', () => {
38
+ const i1 = Integration.createNew("test")
39
+
40
+ const agg = new AggregateDefinition({
41
+ correlationExpression: new ExpressionSubElementDefinition({simple: new SimpleExpression({expression:'${body} != null'})}),
42
+ steps: [new LogDefinition({logName: 'log11', message: "hello11"})]
43
+ })
44
+
45
+ const filter = new FilterDefinition({expression: new ExpressionDefinition({simple: new SimpleExpression({expression:"not null"})})})
46
+
47
+ const flow1 = new FromDefinition({uri: "direct1"});
48
+ flow1.steps?.push(filter);
49
+ flow1.steps?.push(agg);
50
+ i1.spec.flows?.push(new RouteDefinition({from: flow1}));
51
+
52
+ const yaml1 = CamelDefinitionYaml.integrationToYaml(i1);
53
+ });
54
+
55
+ });
@@ -0,0 +1,112 @@
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
+ ExpressionDefinition,
25
+ SimpleExpression,
26
+ FilterDefinition, CatchDefinition, TryDefinition, RouteDefinition
27
+ } from "../src/core/model/CamelDefinition";
28
+ import {CamelUtil} from "../src/core/api/CamelUtil";
29
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
30
+ import {Integration} from "../src/core/model/IntegrationDefinition";
31
+ import * as fs from 'fs';
32
+ import {CamelDefinitionYaml} from "../src/core/api/CamelDefinitionYaml";
33
+ import {StepDefinition} from "../src/core/model/CamelDefinition";
34
+
35
+ describe('Find Step', () => {
36
+
37
+ it('Find Expression in When clause', () => {
38
+ const i = Integration.createNew("test")
39
+ const log1 = new LogDefinition({logName: 'log11', message: "hello11"});
40
+ const log2 = new LogDefinition({logName: 'log11', message: "hello22"});
41
+ const log3 = new LogDefinition({logName: 'log11', message: "hello33"});
42
+ const when1 = new WhenDefinition({
43
+ expression: new ExpressionDefinition({simple: new SimpleExpression({expression: '$[body} != null'})}),
44
+ steps: [log1, log2, log3]
45
+ })
46
+ const choice = new ChoiceDefinition({when: [when1]})
47
+ const from1 = new FromDefinition({uri: "direct1"});
48
+ from1.steps?.push(choice);
49
+ i.spec.flows?.push(new RouteDefinition({from: from1}));
50
+ const when2: WhenDefinition = CamelUtil.cloneStep(when1);
51
+ if (when2 && when2.expression) {
52
+ when2.expression.simple = new SimpleExpression({expression: '$[body} == "hello world"'});
53
+ }
54
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
55
+ expect(log.logName).to.equal(log2.logName);
56
+ expect(log.message).to.equal(log2.message);
57
+ });
58
+
59
+ it('Find Step from Filter clause', () => {
60
+ const i = Integration.createNew("test")
61
+ const log1 = new LogDefinition({logName: 'log11', message: "hello11"});
62
+ const log2 = new LogDefinition({logName: 'log11', message: "hello22"});
63
+ const log3 = new LogDefinition({logName: 'log11', message: "hello33"});
64
+ const filter = new FilterDefinition({
65
+ expression: new ExpressionDefinition({simple: new SimpleExpression({expression: '$[body} != null'})}),
66
+ steps: [log1, log2, log3]
67
+ })
68
+ const from1 = new FromDefinition({uri: "direct1"});
69
+ from1.steps?.push(filter);
70
+ i.spec.flows?.push(new RouteDefinition({from: from1}));
71
+
72
+
73
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
74
+ expect(log.logName).to.equal(log2.logName);
75
+ expect(log.message).to.equal(log2.message);
76
+ });
77
+
78
+ it('Find Step from Try-Catch-Finally clause', () => {
79
+ const log1 = new LogDefinition({message: "hello1"});
80
+ const log2 = new LogDefinition({message: "hello2"});
81
+ const log3 = new LogDefinition({message: "hello3"});
82
+ const catch1 = new CatchDefinition({exception:['IOException'], steps: [log1, log2, log3]})
83
+ const log4 = new LogDefinition({message: "hello4"});
84
+ const log5 = new LogDefinition({message: "hello5"});
85
+ const log6 = new LogDefinition({message: "hello6"});
86
+ const catch2 = new CatchDefinition({exception:['NullPointerException'], steps: [log4, log5, log6]})
87
+ const log7 = new LogDefinition({message: "hello7"});
88
+ const log8 = new LogDefinition({message: "hello8"});
89
+ const log9 = new LogDefinition({message: "hello9"});
90
+ const try1 = new TryDefinition({ doCatch:[catch1, catch2], steps: [log7, log8, log9]})
91
+ const from = new FromDefinition({uri: "direct1", steps:[try1]});
92
+ const i = Integration.createNew("test")
93
+ i.spec.flows?.push(new RouteDefinition({from: from}));
94
+
95
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
96
+ expect(log.logName).to.equal(log2.logName);
97
+ expect(log.message).to.equal(log2.message);
98
+ });
99
+
100
+ it('Find Steps in YAML by Id', () => {
101
+ const yaml = fs.readFileSync('test/findStep.yaml',{encoding:'utf8', flag:'r'});
102
+ const i = CamelDefinitionYaml.yamlToIntegration("demo.yaml", yaml);
103
+ const yaml2 = CamelDefinitionYaml.integrationToYaml(i);
104
+ expect(yaml.replaceAll("\r\n", "\n")).to.equal(yaml2); // replace for Windows compatibility
105
+
106
+ const res1 = CamelDefinitionApiExt.hasElementWithId(i, 'to-6a8b');
107
+ const res2 = CamelDefinitionApiExt.hasElementWithId(i, 'to-6a81');
108
+
109
+ expect(res1).to.equal(1);
110
+ expect(res2).to.equal(0);
111
+ });
112
+ });
@@ -0,0 +1,65 @@
1
+ - restConfiguration: {}
2
+ - rest:
3
+ id: rest-6cff
4
+ get:
5
+ - id: get-ea54
6
+ - route:
7
+ id: route-66bd
8
+ from:
9
+ id: from-6c72
10
+ uri: kamelet:timer-source
11
+ parameters:
12
+ period: 2000
13
+ message: Hello World
14
+ steps:
15
+ - step:
16
+ id: step-6889
17
+ steps:
18
+ - choice:
19
+ id: choice-5cca
20
+ - log:
21
+ id: log-7d33
22
+ - log:
23
+ id: log-0023
24
+ message: ${body}
25
+ - aggregate:
26
+ id: aggregate-6615
27
+ - choice:
28
+ id: choice-9b86
29
+ when:
30
+ - id: when-2521
31
+ expression: {}
32
+ steps:
33
+ - log:
34
+ id: log-8bc9
35
+ otherwise:
36
+ id: otherwise-4843
37
+ steps:
38
+ - to:
39
+ id: to-3d1c
40
+ uri: arangodb
41
+ - split:
42
+ id: split-fe40
43
+ expression: {}
44
+ - saga:
45
+ id: saga-0075
46
+ - to:
47
+ id: to-6a8b
48
+ uri: direct
49
+ parameters:
50
+ sObjectId: hello-world
51
+ - to:
52
+ id: to-6f22
53
+ uri: salesforce
54
+ parameters:
55
+ sObjectId: xxx
56
+ sObjectClass: Account
57
+ operationName: getSObject
58
+ - route:
59
+ id: hello-world
60
+ from:
61
+ id: from-5a9f
62
+ uri: direct
63
+ parameters:
64
+ name: hello-world
65
+ - routeConfiguration: {}
@@ -0,0 +1,32 @@
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 {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
20
+ import {PropertyMeta} from "../src/core/model/CamelMetadata";
21
+
22
+ describe('getElementProperties', () => {
23
+
24
+ it('getElementProperties 1', () => {
25
+
26
+ const p: PropertyMeta[] = CamelDefinitionApiExt.getElementProperties("FromDefinition");
27
+ expect(p.length).to.equal(5);
28
+
29
+ });
30
+
31
+
32
+ });
@@ -0,0 +1,31 @@
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 {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
20
+ import {PropertyMeta} from "../src/core/model/CamelMetadata";
21
+
22
+ describe('getElementPropertiesByName', () => {
23
+
24
+ it('getElementPropertiesByName 1', () => {
25
+
26
+ const p: PropertyMeta[] = CamelDefinitionApiExt.getElementPropertiesByName("json");
27
+ expect(p.length).to.equal(23);
28
+ });
29
+
30
+
31
+ });
@@ -0,0 +1,40 @@
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
+ ExpressionDefinition
21
+ } from "../src/core/model/CamelDefinition";
22
+ import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
23
+ import {SimpleExpression} from "../src/core/model/CamelDefinition";
24
+
25
+ describe('Get Expression Language', () => {
26
+
27
+ it('Get Expression Language 1', () => {
28
+ const e: ExpressionDefinition = new ExpressionDefinition({
29
+ simple: new SimpleExpression({expression:"${body} == null"}
30
+ )});
31
+
32
+ const className = CamelDefinitionApiExt.getExpressionLanguageClassName(e);
33
+ const language = CamelDefinitionApiExt.getExpressionLanguageName(e);
34
+
35
+ expect(className).to.equal("SimpleExpression");
36
+ expect(language).to.equal("simple");
37
+
38
+ });
39
+
40
+ });