Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ describe('Tests for Design page', { browser: '!firefox' }, () => {
types: { out: { mediaType: 'application/json' } },
dependencies: ['camel:timer', 'camel:http', 'camel:kamelet'],
template: {
from: {
id: 'from-1870',
uri: 'timer:user',
parameters: { period: '{{period}}' },
steps: [
{ setBody: { id: 'setBody-3387', expression: { simple: {} } } },
{ marshal: { id: 'marshal-1414' } },
{ to: { uri: 'kamelet:sink', parameters: {} } },
],
route: {
from: {
id: 'from-1870',
uri: 'timer:user',
parameters: { period: '{{period}}' },
steps: [
{ setBody: { id: 'setBody-3387', expression: { simple: {} } } },
{ marshal: { id: 'marshal-1414' } },
{ to: { uri: 'kamelet:sink', parameters: {} } },
],
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ describe('Test for Branching actions from the canvas', () => {
cy.checkNodeExist('activemq', 1);
cy.checkEdgeExists(
'eip-action',
'template.from.steps.1.choice.when.0.steps.1.setHeader',
'template.from.steps.1.choice.when.0.steps.2.to',
'template.route.from.steps.1.choice.when.0.steps.1.setHeader',
'template.route.from.steps.1.choice.when.0.steps.2.to',
);
});

Expand All @@ -79,8 +79,8 @@ describe('Test for Branching actions from the canvas', () => {
cy.checkNodeExist('activemq', 1);
cy.checkEdgeExists(
'eip-action',
'template.from.steps.1.choice.when.0.steps.0.to',
'template.from.steps.1.choice.when.0.steps.1.to',
'template.route.from.steps.1.choice.when.0.steps.0.to',
'template.route.from.steps.1.choice.when.0.steps.1.to',
);
});

Expand All @@ -93,6 +93,6 @@ describe('Test for Branching actions from the canvas', () => {
cy.chooseFromCatalog('component', 'activemq');

cy.checkNodeExist('activemq', 1);
cy.checkEdgeExists('eip-action', 'template.from.steps.2.to', 'template.from.steps.3.filter');
cy.checkEdgeExists('eip-action', 'template.route.from.steps.2.to', 'template.route.from.steps.3.filter');
});
});
31 changes: 16 additions & 15 deletions packages/ui-tests/cypress/fixtures/flows/kamelet/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ spec:
- camel:http
- camel:kamelet
template:
from:
id: from-1870
uri: timer:user
parameters:
period: "{{period}}"
steps:
- setBody:
id: setBody-3387
expression:
simple: {}
- marshal:
id: marshal-1414
- to:
uri: kamelet:sink
parameters: {}
route:
from:
id: from-1870
uri: timer:user
parameters:
period: "{{period}}"
steps:
- setBody:
id: setBody-3387
expression:
simple: {}
- marshal:
id: marshal-1414
- to:
uri: kamelet:sink
parameters: {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
exports[`CamelResourceFactory.createCamelResource > should create an empty KameletResource if no args is specified 1`] = `
[
{
"from": {},
"route": {
"from": {},
},
},
]
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,28 @@ exports[`KameletResource > should convert to JSON 1`] = `
],
"template": {
"beans": undefined,
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
"route": {
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
},
"uri": "https",
},
"uri": "https",
},
},
{
"to": "kamelet:sink",
},
],
"uri": "timer",
{
"to": "kamelet:sink",
},
],
"uri": "timer",
},
},
},
"types": {
Expand Down Expand Up @@ -107,26 +109,28 @@ exports[`KameletResource > should create a new KameletResource 1`] = `
],
"template": {
"beans": undefined,
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
"route": {
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
},
"uri": "https",
},
"uri": "https",
},
},
{
"to": "kamelet:sink",
},
],
"uri": "timer",
{
"to": "kamelet:sink",
},
],
"uri": "timer",
},
},
},
"types": {
Expand Down Expand Up @@ -163,10 +167,12 @@ exports[`KameletResource > should create a new KameletResource with a kamelet 1`
"dependencies": [],
"template": {
"beans": [],
"from": {
"id": "from",
"steps": [],
"uri": "kamelet:source",
"route": {
"from": {
"id": "from",
"steps": [],
"uri": "kamelet:source",
},
},
},
},
Expand All @@ -176,26 +182,28 @@ exports[`KameletResource > should create a new KameletResource with a kamelet 1`
exports[`KameletResource > should get the visual entities (Camel Route Visual Entity) 1`] = `
[
{
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
"route": {
"from": {
"id": "from-1234",
"parameters": {
"period": "{{period}}",
"timerName": "user",
},
"steps": [
{
"to": {
"parameters": {
"httpUri": "random-data-api.com/api/v2/users",
},
"uri": "https",
},
"uri": "https",
},
},
{
"to": "kamelet:sink",
},
],
"uri": "timer",
{
"to": "kamelet:sink",
},
],
"uri": "timer",
},
},
},
]
Expand Down
12 changes: 7 additions & 5 deletions packages/ui/src/models/camel/kamelet-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ describe('KameletResource', () => {
},
dependencies: [],
template: {
from: {
id: 'from',
uri: 'kamelet:source',
steps: [],
},
beans: [],
route: {
from: {
id: 'from',
uri: 'kamelet:source',
steps: [],
},
},
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/models/camel/kamelet-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class KameletResource extends CamelKResource implements RouteTemplateBean
// Call toJSON() on the flow entity to apply property sorting
const flowJson = this.flow.toJSON();
setValue(this.resource, 'metadata.name', this.flow.getId());
setValue(this.resource, 'spec.template.from', flowJson.from);
setValue(this.resource, 'spec.template.route', flowJson.route);
setValue(this.resource, 'spec.template.beans', this.beans?.parent.beans);
return this.resource as IKameletDefinition;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/models/camel/kamelets-catalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BeanFactory, FromDefinition, Kamelet } from '@kaoto/camel-catalog/types';
import { BeanFactory, FromDefinition, Kamelet, RouteDefinition } from '@kaoto/camel-catalog/types';

import { KaotoSchemaDefinition } from '../kaoto-schema';
import { SourceSchemaType } from './source-schema-type';
Expand Down Expand Up @@ -49,7 +49,8 @@ export interface IKameletSpec {
dependencies: string[];
template: {
beans?: BeanFactory[];
from: FromDefinition;
route: RouteDefinition;
from?: FromDefinition;
Comment thread
lordrip marked this conversation as resolved.
};
dataTypes?: {
in?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export abstract class AbstractCamelVisualEntity<T extends object> implements Bas
canDragNode(path?: string) {
if (!isDefined(path)) return false;

return path !== 'route' && path !== 'route.from' && path !== 'template.from';
return path !== 'route' && path !== 'route.from' && path !== 'template.route.from';
}

canDropOnNode(path?: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import catalogLibrary from '@kaoto/camel-catalog/index.json';
import { CatalogLibrary } from '@kaoto/camel-catalog/types';
import { CatalogLibrary, RouteDefinition } from '@kaoto/camel-catalog/types';
import { cloneDeep } from 'lodash';

import { DynamicCatalogRegistry } from '../../../dynamic-catalog/dynamic-catalog-registry';
import { mockRandomValues } from '../../../stubs';
Expand Down Expand Up @@ -54,7 +55,9 @@ describe('KameletVisualEntity', () => {
type: 'source',
},
template: {
from: camelFromJson.from,
route: {
from: camelFromJson.from,
},
},
dependencies: [],
},
Expand All @@ -65,6 +68,16 @@ describe('KameletVisualEntity', () => {
expect(new KameletVisualEntity(kameletDef)).toBeTruthy();
});

it('should normalize template.from to template.route.from and remove template.from', () => {
const kameletDefWithFrom = cloneDeep(kameletDef);
kameletDefWithFrom.spec.template.from = kameletDefWithFrom.spec.template.route.from;
kameletDefWithFrom.spec.template.route = undefined as unknown as RouteDefinition;

const kameletVisualEntity = new KameletVisualEntity(kameletDefWithFrom);
expect(kameletVisualEntity.kamelet.spec.template.from).toBeUndefined();
expect(kameletVisualEntity.kamelet.spec.template.route?.from).toEqual(camelFromJson.from);
});

it('should set the id to the name if provided', () => {
const kameletVisualEntity = new KameletVisualEntity(kameletDef);
expect(kameletVisualEntity.id).toBe('My Kamelet');
Expand Down Expand Up @@ -138,12 +151,27 @@ describe('KameletVisualEntity', () => {
expect(fetchNodeSchemaSpy).toHaveBeenCalledWith(ids);
});

it('should return the root uri', () => {
it('should return the root uri when using template.from (short syntax)', () => {
class KameletVisualEntityTest extends KameletVisualEntity {
getRootUri(): string | undefined {
return super.getRootUri();
}
}
const kamelet = new KameletVisualEntityTest(kameletDef);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
expect(kamelet.getRootUri()).toBe('timer');
});

it('should return the root uri when using template.route.from', () => {
class KameletVisualEntityTest extends KameletVisualEntity {
getRootUri(): string | undefined {
return super.getRootUri();
}
}
kameletDef.spec.template = {
route: {
from: camelFromJson.from,
},
};
const kamelet = new KameletVisualEntityTest(kameletDef);
expect(kamelet.getRootUri()).toBe('timer');
});
Expand Down
Loading
Loading