Skip to content

Commit 6d16479

Browse files
authored
Merge branch 'master' into api-generation-for-components
2 parents 5f03eb3 + 33b1719 commit 6d16479

File tree

9 files changed

+275
-22
lines changed

9 files changed

+275
-22
lines changed

apps/generator/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @asyncapi/generator
22

3+
## 3.1.2
4+
5+
### Patch Changes
6+
7+
- 4a09f57: Bump @asyncapi/parser to 3.6.0 to support AsyncAPI 3.1.0
8+
39
## 3.1.1
410

511
### Patch Changes

apps/generator/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/generator",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
55
"main": "./lib/generator.js",
66
"engines": {
@@ -53,7 +53,7 @@
5353
"@asyncapi/generator-hooks": "*",
5454
"@asyncapi/generator-react-sdk": "*",
5555
"@asyncapi/multi-parser": "^2.2.0",
56-
"@asyncapi/parser": "^3.4.0",
56+
"@asyncapi/parser": "^3.6.0",
5757
"@npmcli/arborist": "5.6.3",
5858
"@npmcli/config": "^8.0.2",
5959
"ajv": "^8.12.0",

package-lock.json

Lines changed: 23 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/templates/clients/websocket/java/quarkus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"author": "Shuaib Salad <sh.salat@gmail.com>",
1313
"license": "Apache-2.0",
1414
"scripts": {
15-
"test": "jest --coverage --passWithNoTests",
15+
"test": "jest --coverage",
1616
"test:update": "npm run test -- -u",
1717
"lint": "eslint --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore .",
1818
"lint:fix": "eslint --fix --max-warnings 0 --config ../../../../../../.eslintrc --ignore-path ../../../../../../.eslintignore ."
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import OnTextMessageHandler from '../../components/OnTextMessageHandler.js';
5+
6+
const parser = new Parser();
7+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
8+
9+
describe('OnTextMessageHandler component (integration with AsyncAPI document)', () => {
10+
let parsedAsyncAPIDocument;
11+
12+
beforeAll(async () => {
13+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
14+
parsedAsyncAPIDocument = parseResult.document;
15+
});
16+
17+
test('renders default handler when sendOperations is null', () => {
18+
const result = render(<OnTextMessageHandler sendOperations={null} />);
19+
expect(result.trim()).toMatchSnapshot();
20+
});
21+
22+
test('renders default handler when sendOperations is empty array', () => {
23+
const result = render(<OnTextMessageHandler sendOperations={[]} />);
24+
expect(result.trim()).toMatchSnapshot();
25+
});
26+
27+
test('renders default handler without sendOperations', () => {
28+
const result = render(<OnTextMessageHandler />);
29+
expect(result.trim()).toMatchSnapshot();
30+
});
31+
32+
test('renders handler with if statement for single send operation', () => {
33+
const operations = parsedAsyncAPIDocument.operations();
34+
const allSendOps = operations.filterBySend();
35+
const sendOpsArray = Array.from(allSendOps);
36+
expect(sendOpsArray.length).toBeGreaterThan(0);
37+
const singleOperation = [sendOpsArray[0]];
38+
const result = render(<OnTextMessageHandler sendOperations={singleOperation} />);
39+
expect(result.trim()).toMatchSnapshot();
40+
});
41+
42+
test('renders handler with if-else-if chain for multiple send operations', () => {
43+
const operations = parsedAsyncAPIDocument.operations();
44+
const sendOperations = operations.filterBySend();
45+
const sendOpsArray = Array.from(sendOperations);
46+
expect(sendOpsArray.length).toBeGreaterThan(1);
47+
const result = render(<OnTextMessageHandler sendOperations={sendOperations} />);
48+
expect(result.trim()).toMatchSnapshot();
49+
});
50+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import path from 'path';
2+
import { render } from '@asyncapi/generator-react-sdk';
3+
import { Parser, fromFile } from '@asyncapi/parser';
4+
import { getQueryParams } from '@asyncapi/generator-helpers';
5+
import URIParams from '../../components/URIParams.js';
6+
7+
const parser = new Parser();
8+
const asyncapiFilePath = path.resolve(__dirname, '../../../../test/__fixtures__/asyncapi-websocket-components.yml');
9+
10+
describe('URIParams component (integration with AsyncAPI document)', () => {
11+
let parsedAsyncAPIDocument;
12+
let channels;
13+
let queryParamsArray;
14+
15+
beforeAll(async () => {
16+
const parseResult = await fromFile(parser, asyncapiFilePath).parse();
17+
parsedAsyncAPIDocument = parseResult.document;
18+
channels = parsedAsyncAPIDocument.channels();
19+
const queryParams = getQueryParams(channels);
20+
queryParamsArray = queryParams ? Array.from(queryParams.entries()) : null;
21+
});
22+
23+
test('renders nothing when queryParamsArray is null', () => {
24+
const result = render(<URIParams queryParamsArray={null} pathName="/link" />);
25+
expect(result.trim()).toMatchSnapshot();
26+
});
27+
28+
test('renders nothing when queryParamsArray is empty array', () => {
29+
const result = render(<URIParams queryParamsArray={[]} pathName="/link" />);
30+
expect(result.trim()).toMatchSnapshot();
31+
});
32+
33+
test('renders nothing when queryParamsArray is undefined', () => {
34+
const result = render(<URIParams pathName="/link" />);
35+
expect(result.trim()).toMatchSnapshot();
36+
});
37+
38+
test('renders URI params with multiple query parameters from fixture', () => {
39+
const result = render(<URIParams queryParamsArray={queryParamsArray} pathName="/link" />);
40+
expect(result.trim()).toMatchSnapshot();
41+
});
42+
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`OnTextMessageHandler component (integration with AsyncAPI document) renders default handler when sendOperations is empty array 1`] = `
4+
"@OnTextMessage
5+
public void processTextMessage(String message, WebSocketClientConnection connection) {
6+
LOG.info(\\"Received text message: \\" + message);
7+
}"
8+
`;
9+
10+
exports[`OnTextMessageHandler component (integration with AsyncAPI document) renders default handler when sendOperations is null 1`] = `
11+
"@OnTextMessage
12+
public void processTextMessage(String message, WebSocketClientConnection connection) {
13+
LOG.info(\\"Received text message: \\" + message);
14+
}"
15+
`;
16+
17+
exports[`OnTextMessageHandler component (integration with AsyncAPI document) renders default handler without sendOperations 1`] = `
18+
"@OnTextMessage
19+
public void processTextMessage(String message, WebSocketClientConnection connection) {
20+
LOG.info(\\"Received text message: \\" + message);
21+
}"
22+
`;
23+
24+
exports[`OnTextMessageHandler component (integration with AsyncAPI document) renders handler with if statement for single send operation 1`] = `
25+
"@OnTextMessage
26+
public void handleTextMessage(String message, WebSocketClientConnection connection) {
27+
LOG.info(\\"Handler received text message: \\" + message);
28+
if (message != null && message.contains(\\"sendMessage\\")) {
29+
sendMessage(message, connection);
30+
}
31+
else {
32+
LOG.warn(\\"Handler received unrecognized message type. Falling back to default handler.\\");
33+
// Note: By default, we route unrecognized messages to the first operation handler.
34+
// Depending on your business logic, you may want to change this behavior.
35+
sendMessage(message, connection);
36+
}
37+
}
38+
39+
public void sendMessage(String message, WebSocketClientConnection connection) {
40+
LOG.info(\\"Processing sendMessage type message: \\" + message);
41+
// TODO: implement processing logic for sendMessage
42+
}"
43+
`;
44+
45+
exports[`OnTextMessageHandler component (integration with AsyncAPI document) renders handler with if-else-if chain for multiple send operations 1`] = `
46+
"@OnTextMessage
47+
public void handleTextMessage(String message, WebSocketClientConnection connection) {
48+
LOG.info(\\"Handler received text message: \\" + message);
49+
if (message != null && message.contains(\\"sendMessage\\")) {
50+
sendMessage(message, connection);
51+
}
52+
else if (message != null && message.contains(\\"sendNotification\\")) {
53+
sendNotification(message, connection);
54+
}
55+
else {
56+
LOG.warn(\\"Handler received unrecognized message type. Falling back to default handler.\\");
57+
// Note: By default, we route unrecognized messages to the first operation handler.
58+
// Depending on your business logic, you may want to change this behavior.
59+
sendMessage(message, connection);
60+
}
61+
}
62+
63+
public void sendMessage(String message, WebSocketClientConnection connection) {
64+
LOG.info(\\"Processing sendMessage type message: \\" + message);
65+
// TODO: implement processing logic for sendMessage
66+
}
67+
68+
public void sendNotification(String message, WebSocketClientConnection connection) {
69+
LOG.info(\\"Processing sendNotification type message: \\" + message);
70+
// TODO: implement processing logic for sendNotification
71+
}"
72+
`;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`URIParams component (integration with AsyncAPI document) renders URI params with multiple query parameters from fixture 1`] = `
4+
"// URI parameters
5+
String query = \\"\\";
6+
7+
String heartbeat = System.getenv(\\"HEARTBEAT\\");
8+
if(heartbeat == null || heartbeat.isEmpty()){
9+
throw new IllegalArgumentException(\\"Required environment variable HEARTBEAT is missing or empty\\");
10+
}
11+
query += \\"heartbeat=\\" + URLEncoder.encode(heartbeat, StandardCharsets.UTF_8);
12+
13+
String bids = System.getenv(\\"BIDS\\");
14+
if(bids == null || bids.isEmpty()){
15+
throw new IllegalArgumentException(\\"Required environment variable BIDS is missing or empty\\");
16+
}
17+
query += \\"&bids=\\" + URLEncoder.encode(bids, StandardCharsets.UTF_8);
18+
19+
20+
String queryUri = baseURI + \\"/link\\" + \\"?\\" + query;
21+
WebSocketClientConnection connection = connector.baseUri(queryUri).connectAndAwait();
22+
Thread.sleep(120000); // Keep the connection open for 2 minutes"
23+
`;
24+
25+
exports[`URIParams component (integration with AsyncAPI document) renders nothing when queryParamsArray is empty array 1`] = `""`;
26+
27+
exports[`URIParams component (integration with AsyncAPI document) renders nothing when queryParamsArray is null 1`] = `""`;
28+
29+
exports[`URIParams component (integration with AsyncAPI document) renders nothing when queryParamsArray is undefined 1`] = `""`;

0 commit comments

Comments
 (0)