Skip to content

Commit

Permalink
chore(SourceCode): Provide defaults for Log processor and Log component
Browse files Browse the repository at this point in the history
Currently, defaults for Log processor are provided, but it's not the
case for the Log component nor when a new route is created.

This commit adds a default value for the Log processor from the Route
Template and also adds a logger name for the Log Component
  • Loading branch information
lordrip committed Sep 5, 2024
1 parent 5333f03 commit e6c5ed7
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ describe('Tests for sidebar loadBalancer step configuration', () => {
'steps:',
'- to:',
'parameters: {}',
'uri: log',
'uri: log:InfoLogger',
'- to:',
'parameters: {}',
'uri: log',
'uri: log:InfoLogger',
'description: loadBalancerDescription',
'inheritErrorHandler: true',
'id: testId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
steps:
- log:
id: log-6809
message: template message
message: ${body}
- route:
id: route-4321
from:
Expand All @@ -19,4 +19,4 @@
steps:
- log:
id: log-2966
message: template message
message: ${body}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
expression: body-constant
- log:
id: log-4225
message: template message
message: ${body}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
repeatCount: "5"
steps:
- setBody:
# wrong id placement - creates unknown node
# wrong id placement - creates unknown node
- id: setBody-3518
# wrong id placement
- log:
id: log-4225
message: template message
message: ${body}
id: route-8484
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ parameters:
steps:
- log:
id: log-1234
message: template message
message: \${body}
</code>
</pre>
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/hooks/entities.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('useEntities', () => {
steps:
- log:
id: log-1234
message: template message
message: \${body}
`,
);
});
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('useEntities', () => {
steps:
- log:
id: log-1234
message: template message
message: \${body}
`;

const { result } = renderHook(() => useEntities());
Expand Down Expand Up @@ -219,7 +219,7 @@ describe('useEntities', () => {
steps:
- log:
id: log-1234
message: template message
message: \${body}
`,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,20 @@ describe('CamelComponentDefaultService', () => {
name: 'log',
} as DefinedComponent) as any;
expect(logDefault.log).toBeDefined();
expect((logDefault.log.id as string).startsWith('log-')).toBeTruthy();
expect(logDefault.log.id as string).toMatch(/^log-/);
expect(logDefault.log.message).toEqual('${body}');
});

it('should return the default value for a log component', () => {
const logDefault = CamelComponentDefaultService.getDefaultNodeDefinitionValue({
type: 'component',
name: 'log',
} as DefinedComponent) as any;
expect(logDefault.to).toBeDefined();
expect(logDefault.to.id as string).toMatch(/^to-/);
expect(logDefault.to.uri).toEqual('log:InfoLogger');
});

it('should return the default value for a doCatch processor', () => {
const doCatchDefault = CamelComponentDefaultService.getDefaultNodeDefinitionValue({
type: 'processor',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ export class CamelComponentDefaultService {
}

private static getDefaultValueFromComponent(componentName: string): object {
return parse(`
to:
id: ${getCamelRandomId('to')}
uri: "${componentName}"
parameters: {}
`);
switch (componentName) {
case 'log':
return parse(`
to:
id: ${getCamelRandomId('to')}
uri: log:InfoLogger
parameters: {}
`);

default:
return parse(`
to:
id: ${getCamelRandomId('to')}
uri: "${componentName}"
parameters: {}
`);
}
}

private static getDefaultValueFromKamelet(kameletName: string): object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const routeTemplate = () => {
steps:
- log:
id: ${getCamelRandomId('log')}
message: template message`;
message: \${body}`;
};

0 comments on commit e6c5ed7

Please sign in to comment.