Skip to content

Commit

Permalink
fix(SourceCode): Fix doCatch serialization
Browse files Browse the repository at this point in the history
Currently, there's no handling when adding a new `doCatch` element to a
`doTry` processor, leading to create a wrong structure.

The fix is to handle this situation so a proper `doCatch` is created at
the right position with the correct structure.

fix: #1025
  • Loading branch information
lordrip committed Apr 23, 2024
1 parent a0a88ab commit 0f1cc40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CamelComponentDefaultService } from './camel-component-default.service';
import { DefinedComponent } from '../../../camel-catalog-index';
import { DoCatch } from '@kaoto-next/camel-catalog/types';

describe('CamelComponentDefaultService', () => {
describe('getDefaultNodeDefinitionValue', () => {
Expand All @@ -24,5 +25,26 @@ describe('CamelComponentDefaultService', () => {
expect(whenDefault.expression.simple.expression).toEqual('${header.foo} == 1');
expect(whenDefault.steps[0].log).toBeDefined();
});

it('should return the default value for a doTry processor', () => {
const doTryDefault = CamelComponentDefaultService.getDefaultNodeDefinitionValue({
type: 'processor',
name: 'doTry',
} as DefinedComponent);
expect(doTryDefault).toBeDefined();
expect(doTryDefault.doTry?.doCatch).toHaveLength(1);
expect(doTryDefault.doTry?.doCatch?.[0].steps).toHaveLength(0);
expect(doTryDefault.doTry?.doCatch?.[0].exception).toHaveLength(1);
});

it('should return the default value for a doCatch processor', () => {
const doCatchDefault = CamelComponentDefaultService.getDefaultNodeDefinitionValue({
type: 'processor',
name: 'doCatch',
} as DefinedComponent) as DoCatch;
expect(doCatchDefault).toBeDefined();
expect(doCatchDefault.id).toBeDefined();
expect(doCatchDefault.exception).toHaveLength(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export class CamelComponentDefaultService {
id: ${getCamelRandomId('doTry')}
doCatch:
- id: ${getCamelRandomId('doCatch')}
exception:
- java.lang.NullPointerException
steps: []
doFinally:
id: ${getCamelRandomId('doFinally')}
Expand All @@ -113,6 +115,14 @@ export class CamelComponentDefaultService {
message: "\${body}"
`);

case 'doCatch':
return parse(`
id: ${getCamelRandomId('doCatch')}
exception:
- java.lang.NullPointerException
steps: []
`);

default:
return {
[processorName]: {
Expand Down

0 comments on commit 0f1cc40

Please sign in to comment.