Skip to content

Commit 16f8e9d

Browse files
committed
Add get file path API
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 8f93112 commit 16f8e9d

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

src/analysis/java/JavaAnalysis.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import { JApplication, JCompilationUnit } from "../../models/java";
2222
import * as types from "../../models/java/types";
2323
import { JType } from "../../models/java";
2424
import os from "os";
25-
import JSONStream from "JSONStream";
26-
declare module "JSONStream";
2725
import crypto from "crypto";
2826
import { createLogger } from "src/utils";
2927

@@ -108,6 +106,7 @@ export class JavaAnalysis {
108106

109107
// Read the analysis result from the temporary file
110108
try {
109+
const JSONStream = require("JSONStream");
111110
const stream = fs.createReadStream(path.join(tmpFilePath, "analysis.json")).pipe(JSONStream.parse());
112111
const result = {} as types.JApplicationType;
113112

@@ -297,4 +296,6 @@ export class JavaAnalysis {
297296
}
298297
throw new Error(`Class ${qualifiedName} not found in the application.`);
299298
}
299+
300+
300301
}

test/unit/analysis/java/JavaAnalysis.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ import { daytraderJavaAnalysis } from "../../../conftest";
33
import { expect, test } from "bun:test";
44
import { logger } from "../../../../src/utils";
55

6-
test("Must get analysis object from JavaAnalysis object", () => {
6+
test("Should get analysis object from JavaAnalysis object", () => {
77
expect(daytraderJavaAnalysis).toBeDefined();
88
});
99

10-
test("Must get JApplication instance", async () => {
10+
test("Should get JApplication instance", async () => {
1111
const jApplication = await daytraderJavaAnalysis.getApplication();
1212
expect(jApplication).toBeDefined();
1313
});
1414

15-
test("Must get Symbol Table", async () => {
15+
test("Should get Symbol Table", async () => {
1616
const symbolTable = await daytraderJavaAnalysis.getSymbolTable();
1717
expect(symbolTable).toBeDefined();
1818
});
1919

20-
test("Must get all classes in a Java application", async () => {
20+
test("Should get all classes in a Java application", async () => {
2121
await expect(daytraderJavaAnalysis.getAllClasses()).toBeDefined();
2222
});
2323

24-
test("Must get a specific class the application", async () => {
24+
test("Should get a specific class the application", async () => {
2525
const tradeDirectObject = await daytraderJavaAnalysis.getClassByQualifiedName("com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect");
2626
expect(async () => JType.parse(tradeDirectObject)).not.toThrow();
2727
});
2828

29-
test("Must throw error when a requested class in the application does not exist", async () => {
29+
test("Should throw error when a requested class in the application does not exist", async () => {
3030
/**
3131
* Quick note to self: There is a subtle difference between await expect(...) and expect(await ...)
3232
* When there is an error, the reject happens even before the expect can be honored. So instead, we await the expect
@@ -36,27 +36,27 @@ test("Must throw error when a requested class in the application does not exist"
3636
"Class this.class.does.not.Exist not found in the application.");
3737
});
3838

39-
test("Must get all methods in the application", () => {
39+
test("Should get all methods in the application", () => {
4040
return daytraderJavaAnalysis.getAllMethods().then((methods) => {
4141
expect(methods).toBeDefined()
4242
});
4343
});
4444

45-
test("Must get all methods in a specific class in the application", async () => {
45+
test("Should get all methods in a specific class in the application", async () => {
4646
expect(
4747
(
4848
await daytraderJavaAnalysis.getAllMethodsByClass("com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect")).length
4949
).toBeGreaterThan(0)
5050
});
5151

52-
test("Must get a specific method in a specific class in the application", async () => {
52+
test("Should get a specific method in a specific class in the application", async () => {
5353
const method = await daytraderJavaAnalysis.getMethodByQualifiedName(
5454
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)");
5555

5656
expect(async () => JCallable.parse(method)).not.toThrow();
5757
});
5858

59-
test("Must get parameters of a specific method in a specific class in the application", async () => {
59+
test("Should get parameters of a specific method in a specific class in the application", async () => {
6060
const parameters = await daytraderJavaAnalysis.getMethodParameters(
6161
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)");
6262

@@ -70,7 +70,7 @@ test("Must get parameters of a specific method in a specific class in the applic
7070
logger.success("All parameters are valid JCallableParameter instances");
7171
});
7272

73-
test("Must get parameters of a specific method in a specific class in the application given the callable object", async () => {
73+
test("Should get parameters of a specific method in a specific class in the application given the callable object", async () => {
7474
const method = await daytraderJavaAnalysis.getMethodByQualifiedName(
7575
"com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect", "publishQuotePriceChange(QuoteDataBean, BigDecimal, BigDecimal, double)");
7676
const parameters = await daytraderJavaAnalysis.getMethodParametersFromCallable(method);
@@ -85,3 +85,10 @@ test("Must get parameters of a specific method in a specific class in the applic
8585
logger.success("All parameters are valid JCallableParameter instances");
8686
});
8787

88+
89+
test("Should get file path for a specific class in the application", async () => {
90+
const filePath = await daytraderJavaAnalysis.getJavaFilePathByQualifiedName("com.ibm.websphere.samples.daytrader.impl.direct.TradeDirect");
91+
expect(filePath).toBeDefined();
92+
expect(filePath).toContain(
93+
"main/java/com/ibm/websphere/samples/daytrader/impl/direct/TradeDirect.java");
94+
});

test/unit/utils/loggers.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { test, expect } from 'bun:test';
22
import { logger, createLogger } from '../../../src/utils/logger';
33

4-
test("Must create a logger instance", () => {
4+
test("Should create a logger instance", () => {
55
expect(logger).toBeDefined();
66
});
77

8-
test("Must log info message without throwing", () => {
8+
test("Should log info message without throwing", () => {
99
expect(() => logger.info("This is an info message")).not.toThrow();
1010
});
1111

12-
test("Must log success message without throwing", () => {
12+
test("Should log success message without throwing", () => {
1313
expect(() => logger.success("This is a success message")).not.toThrow();
1414
});
1515

16-
test("Must log warning message without throwing", () => {
16+
test("Should log warning message without throwing", () => {
1717
expect(() => logger.warn("This is a warning message")).not.toThrow();
1818
});
1919

20-
test("Must log error message without throwing", () => {
20+
test("Should log error message without throwing", () => {
2121
expect(() => logger.error("This is an error message")).not.toThrow();
2222
});
2323

24-
test("Must log debug message without throwing", () => {
24+
test("Should log debug message without throwing", () => {
2525
expect(() => logger.debug("This is a debug message")).not.toThrow();
2626
});
2727

28-
test("Must pretty print JSON without throwing", () => {
28+
test("Should pretty print JSON without throwing", () => {
2929
expect(() => logger.prettyJson("Test Object", { foo: "bar", baz: 42 })).not.toThrow();
3030
});
3131

32-
test("Must create scoped logger instance", () => {
32+
test("Should create scoped logger instance", () => {
3333
const scopedLogger = createLogger("TestScope");
3434
expect(scopedLogger).toBeDefined();
3535
});

0 commit comments

Comments
 (0)