-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'datamapper/main' into merge-datamapper
- Loading branch information
Showing
342 changed files
with
42,467 additions
and
1,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/ui-tests/stories/datamapper/DataMapperDebugger.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DataMapperDebugger } from '@kaoto/kaoto/testing'; | ||
import { Meta, StoryFn } from '@storybook/react'; | ||
import { fn } from '@storybook/test'; | ||
|
||
export default { | ||
title: 'DataMapper/Debugger', | ||
component: DataMapperDebugger, | ||
} as Meta<typeof DataMapperDebugger>; | ||
|
||
const Template: StoryFn<typeof DataMapperDebugger> = (args) => { | ||
return <DataMapperDebugger {...args} />; | ||
}; | ||
|
||
export const Debugger = Template.bind({}); | ||
Debugger.args = { | ||
onUpdateDocument: fn(), | ||
onUpdateMappings: fn(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
{ | ||
"kaoto-datamapper" : { | ||
"model" : { | ||
"kind" : "model", | ||
"name" : "kaoto-datamapper", | ||
"title" : "Kaoto DataMapper", | ||
"description" : "The Kaoto DataMapper maps and transforms data using a set of Camel processors", | ||
"deprecated" : false, | ||
"label" : "transformation", | ||
"javaType" : "org.apache.camel.model.StepDefinition", | ||
"supportLevel" : "Stable", | ||
"abstract" : false, | ||
"input" : true, | ||
"output" : true | ||
}, | ||
"properties" : { | ||
"description" : { | ||
"index" : 0, | ||
"kind" : "attribute", | ||
"displayName" : "Description", | ||
"group" : "common", | ||
"required" : false, | ||
"type" : "string", | ||
"javaType" : "java.lang.String", | ||
"deprecated" : false, | ||
"autowired" : false, | ||
"secret" : false, | ||
"description" : "Sets the description of this node" | ||
}, | ||
"disabled" : { | ||
"index" : 1, | ||
"kind" : "attribute", | ||
"displayName" : "Disabled", | ||
"group" : "advanced", | ||
"label" : "advanced", | ||
"required" : false, | ||
"type" : "boolean", | ||
"javaType" : "java.lang.Boolean", | ||
"deprecated" : false, | ||
"autowired" : false, | ||
"secret" : false, | ||
"defaultValue" : false, | ||
"description" : "Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime." | ||
}, | ||
"outputs" : { | ||
"index" : 2, | ||
"kind" : "element", | ||
"displayName" : "Outputs", | ||
"group" : "common", | ||
"required" : true, | ||
"type" : "array", | ||
"javaType" : "java.util.List", | ||
"oneOf" : [ "aggregate", "bean", "choice", "circuitBreaker", "claimCheck", "convertBodyTo", "convertHeaderTo", "convertVariableTo", "delay", "doCatch", "doFinally", "doTry", "dynamicRouter", "enrich", "filter", "idempotentConsumer", "intercept", "interceptFrom", "interceptSendToEndpoint", "kamelet", "loadBalance", "log", "loop", "marshal", "multicast", "onCompletion", "onException", "onFallback", "otherwise", "pausable", "pipeline", "policy", "pollEnrich", "process", "recipientList", "removeHeader", "removeHeaders", "removeProperties", "removeProperty", "removeVariable", "resequence", "resumable", "rollback", "routingSlip", "saga", "sample", "script", "serviceCall", "setBody", "setExchangePattern", "setHeader", "setHeaders", "setProperty", "setVariable", "setVariables", "sort", "split", "step", "stop", "threads", "throttle", "throwException", "to", "toD", "transacted", "transform", "unmarshal", "validate", "when", "whenSkipSendToEndpoint", "wireTap" ], | ||
"deprecated" : false, | ||
"autowired" : false, | ||
"secret" : false | ||
} | ||
}, | ||
"exchangeProperties" : { | ||
"CamelStepId" : { | ||
"index" : 0, | ||
"kind" : "exchangeProperty", | ||
"displayName" : "Step Id", | ||
"label" : "producer", | ||
"required" : false, | ||
"javaType" : "String", | ||
"deprecated" : false, | ||
"autowired" : false, | ||
"secret" : false, | ||
"description" : "The id of the Step EIP" | ||
} | ||
}, | ||
"propertiesSchema" : { | ||
"title" : "Kaoto DataMapper", | ||
"description" : "The Kaoto DataMapper maps and transforms data using a set of Camel processors", | ||
"type" : "object", | ||
"additionalProperties" : false, | ||
"properties" : { | ||
"description" : { | ||
"type" : "string", | ||
"title" : "Description", | ||
"description" : "Sets the description of this node", | ||
"group" : "common" | ||
}, | ||
"disabled" : { | ||
"type" : "boolean", | ||
"title" : "Disabled", | ||
"description" : "Whether to disable this EIP from the route during build time. Once an EIP has been disabled then it cannot be enabled later at runtime.", | ||
"group" : "advanced" | ||
} | ||
}, | ||
"$comment" : "steps", | ||
"$schema" : "http://json-schema.org/draft-07/schema#", | ||
"required" : [ ] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
const getCryptoObj = () => { | ||
return window.crypto || (window as Window & { msCrypto?: Crypto }).msCrypto; | ||
}; | ||
|
||
export const getCamelRandomId = (kind: string, length = 4): string => { | ||
const cryptoObj = window.crypto || (window as Window & { msCrypto?: Crypto }).msCrypto; | ||
const randomNumber = Math.floor(cryptoObj?.getRandomValues(new Uint32Array(1))[0] ?? Date.now()); | ||
const randomNumber = Math.floor(getCryptoObj()?.getRandomValues(new Uint32Array(1))[0] ?? Date.now()); | ||
|
||
return `${kind}-${randomNumber.toString(10).slice(0, length)}`; | ||
}; | ||
|
||
export const getHexaDecimalRandomId = (prefix: string) => { | ||
const randomNumber = getCryptoObj()?.getRandomValues(new Uint32Array(1))[0] ?? Date.now(); | ||
return `${prefix}-${randomNumber.toString(16)}`; | ||
}; |
113 changes: 113 additions & 0 deletions
113
packages/ui/src/components/DataMapper/DataMapper.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { IVisualizationNode } from '../../models'; | ||
import { DocumentDefinitionType } from '../../models/datamapper/document'; | ||
import { IDataMapperMetadata } from '../../models/datamapper/metadata'; | ||
import { IMetadataApi, MetadataProvider } from '../../providers'; | ||
import { shipOrderToShipOrderXslt, shipOrderXsd } from '../../stubs/data-mapper'; | ||
import { DataMapper } from './DataMapper'; | ||
|
||
describe('DataMapperPage', () => { | ||
const vizNode = { | ||
getId: () => 'route-1234', | ||
getComponentSchema: () => { | ||
return { | ||
definition: { id: 'kaoto-datamapper-1234' }, | ||
}; | ||
}, | ||
} as unknown as IVisualizationNode; | ||
const defaultMetadata: IDataMapperMetadata = { | ||
sourceBody: { | ||
type: DocumentDefinitionType.Primitive, | ||
filePath: [], | ||
}, | ||
sourceParameters: {}, | ||
targetBody: { | ||
type: DocumentDefinitionType.Primitive, | ||
filePath: [], | ||
}, | ||
xsltPath: `kaoto-datamapper-1234.xsl`, | ||
}; | ||
|
||
let metadata: IDataMapperMetadata; | ||
let fileContents: Record<string, string>; | ||
const api = { | ||
getMetadata: (_key: string) => { | ||
return Promise.resolve(metadata); | ||
}, | ||
setMetadata: (_key: string, meta: IDataMapperMetadata) => { | ||
Object.assign(metadata, meta); | ||
return Promise.resolve(); | ||
}, | ||
getResourceContent: (path: string) => { | ||
return Promise.resolve(fileContents[path]); | ||
}, | ||
saveResourceContent: (path: string, content: string) => { | ||
fileContents[path] = content; | ||
return Promise.resolve(); | ||
}, | ||
} as IMetadataApi; | ||
|
||
beforeEach(() => { | ||
metadata = defaultMetadata; | ||
fileContents = {}; | ||
}); | ||
|
||
it('should render initial XSLT mappings', async () => { | ||
fileContents[metadata.xsltPath] = shipOrderToShipOrderXslt; | ||
render( | ||
<MetadataProvider api={api}> | ||
<DataMapper vizNode={vizNode} /> | ||
</MetadataProvider>, | ||
); | ||
await screen.findByTestId('card-source-parameters-header'); | ||
// TODO assert mappings are restored even without loading schema... But how? Lines are not drawn... | ||
}); | ||
|
||
it('should render initial XSLT mappings with initial documents', async () => { | ||
fileContents['ShipOrder.xsd'] = shipOrderXsd; | ||
metadata.sourceBody = { | ||
filePath: ['ShipOrder.xsd'], | ||
type: DocumentDefinitionType.XML_SCHEMA, | ||
}; | ||
metadata.targetBody = { | ||
filePath: ['ShipOrder.xsd'], | ||
type: DocumentDefinitionType.XML_SCHEMA, | ||
}; | ||
metadata.sourceParameters['testparam1'] = { | ||
filePath: [], | ||
type: DocumentDefinitionType.Primitive, | ||
}; | ||
render( | ||
<MetadataProvider api={api}> | ||
<DataMapper vizNode={vizNode} /> | ||
</MetadataProvider>, | ||
); | ||
await screen.findByTestId('card-source-parameters-header'); | ||
expect(screen.getByTestId('node-source-doc-param-testparam1')).toBeInTheDocument(); | ||
expect(screen.getByTestId('node-source-doc-sourceBody-Body')).toBeInTheDocument(); | ||
expect(screen.getByTestId('node-target-doc-targetBody-Body')).toBeInTheDocument(); | ||
expect(screen.getByTestId(/node-source-field-OrderId-\n*/)).toBeInTheDocument(); | ||
expect(screen.getByTestId(/node-target-field-OrderId-\n*/)).toBeInTheDocument(); | ||
// TODO assert mappings are restored even without loading schema... But how? Lines are not drawn... | ||
}); | ||
|
||
it('should not render toolbar menu in embedded mode', async () => { | ||
render( | ||
<MetadataProvider api={api}> | ||
<DataMapper vizNode={vizNode} /> | ||
</MetadataProvider>, | ||
); | ||
try { | ||
await screen.findByTestId('main-menu-button'); | ||
fail(); | ||
} catch (e) { | ||
expect(e).toBeTruthy(); | ||
} | ||
}); | ||
|
||
it('should show an error message if vizNode is not provided', async () => { | ||
render(<DataMapper />); | ||
const error = await screen.findByText('No associated DataMapper step was provided.'); | ||
expect(error).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.