Skip to content

Issue 100 capture database entries - #110

Merged
rahlk merged 13 commits into
mainfrom
issue-100-capture-database-entries
Feb 11, 2025
Merged

Issue 100 capture database entries#110
rahlk merged 13 commits into
mainfrom
issue-100-capture-database-entries

Conversation

@rahlk

@rahlkrahlk commented Feb 8, 2025

Copy link
Copy Markdown
Collaborator

Motivation and Context

We now support the following frameworks

  • Jakarta and JavaEE JPA CRUD operations.
  • Springboot
  • JDBC

How Has This Been Tested?

We have added a new test case to our integration testing suite and we have verified that it runs on plantsbywebsphere

packagecom.ibm.cldk;
importorg.junit.jupiter.api.BeforeAll;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.api.Assertions;
importorg.testcontainers.containers.BindMode;
importorg.testcontainers.containers.GenericContainer;
importorg.testcontainers.junit.jupiter.Container;
importorg.testcontainers.junit.jupiter.Testcontainers;
importorg.testcontainers.utility.MountableFile;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.nio.file.Paths;
importjava.util.Properties;
@Testcontainers@SuppressWarnings("resource")
publicclassCodeAnalyzerIntegrationTest {
// ...@TestvoidshouldBeAbleToDetectCRUDOperationsAndQueriesForPlantByWebsphere() throwsException {
varrunCodeAnalyzerOnPlantsByWebsphere = container.execInContainer(
"java",
"-jar",
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
"--input=/test-applications/plantsbywebsphere",
"--analysis-level=1", "--verbose"
);
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"query_type\": \"NAMED\""), "No entry point classes found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"READ\""), "No entry point methods found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"UPDATE\""), "No entry point methods found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"CREATE\""), "No entry point methods found");
}
}

Breaking Changes

Yes. analysis.json has new fields, so cldk's python-sdk will break if this new version of codeanalyzer-2.2.0-dev is used.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the Codellm-Devkit Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

A number of new interfaces and enums were added, some of them will be backported to refactor the entrypoint detection offered in v2.1.0 of codeanalyzer.

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
… test and/or resources folder only within project directory.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
…avaEE and Jakarta Persistence API.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk
rahlk requested a review from pavuluriFebruary 8, 2025 05:51
… the crud operations that occur in it as an array list.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
… the crud operations and queries that occur in it as an array list. Also updated the test case to capture this.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlkrahlk linked an issue Feb 8, 2025 that may be closed by this pull request
… the crud operations and queries that occur in it as an array list. Also updated the test case to capture this.
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk

rahlk commented Feb 8, 2025

Copy link
Copy Markdown
CollaboratorAuthor

I have also made it so that we can get the crud operations easily directly form Callable entity. Added a couple of additional assertions to evaluate that we are indeed capturing the crud operations in the Callable object as expected.

packagecom.ibm.cldk;
importorg.junit.jupiter.api.BeforeAll;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.api.Assertions;
importorg.testcontainers.containers.BindMode;
importorg.testcontainers.containers.GenericContainer;
importorg.testcontainers.junit.jupiter.Container;
importorg.testcontainers.junit.jupiter.Testcontainers;
importorg.testcontainers.utility.MountableFile;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.IOException;
importjava.nio.file.Paths;
importjava.util.Properties;
@Testcontainers@SuppressWarnings("resource")
publicclassCodeAnalyzerIntegrationTest {
// ...@TestvoidshouldBeAbleToDetectCRUDOperationsAndQueriesForPlantByWebsphere() throwsException {
varrunCodeAnalyzerOnPlantsByWebsphere = container.execInContainer(
"java",
"-jar",
String.format("/opt/jars/codeanalyzer-%s.jar", codeanalyzerVersion),
"--input=/test-applications/plantsbywebsphere",
"--analysis-level=1", "--verbose"
);
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"query_type\": \"NAMED\""), "No entry point classes found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"READ\""), "No entry point methods found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"UPDATE\""), "No entry point methods found");
Assertions.assertTrue(runCodeAnalyzerOnPlantsByWebsphere.getStdout().contains("\"operation_type\": \"CREATE\""), "No entry point methods found");
// Convert the expected JSON structure into a stringStringexpectedCrudOperation =
"\"crud_operations\": [" +
"{" +
"\"line_number\": 115," +
"\"operation_type\": \"READ\"," +
"\"target_table\": null," +
"\"involved_fields\": null," +
"\"condition\": null," +
"\"joined_tables\": null," +
"\"technology\": null," +
"\"is_batch_operation\": false" +
"}]";
// Expected JSON for CRUD QueriesStringexpectedCrudQuery =
"\"crud_queries\": [" +
"{" +
"\"line_number\": 141,";
// Normalize the output and expected strings to ignore formatting differencesStringnormalizedOutput = output.replaceAll("\\s+", "");
StringnormalizedExpectedCrudOperation = expectedCrudOperation.replaceAll("\\s+", "");
StringnormalizedExpectedCrudQuery = expectedCrudQuery.replaceAll("\\s+", "");
// Assertions for both CRUD operations and queriesAssertions.assertTrue(normalizedOutput.contains(normalizedExpectedCrudOperation), "Expected CRUD operation JSON structure not found");
Assertions.assertTrue(normalizedOutput.contains(normalizedExpectedCrudQuery), "Expected CRUD query JSON structure not found");
}
}

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlkrahlk self-assigned this Feb 8, 2025
@rahlkrahlk added the enhancement New feature or request label Feb 8, 2025
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk
rahlk merged commit c5e9d1d into mainFeb 11, 2025
@rahlk
rahlk deleted the issue-100-capture-database-entries branch February 19, 2025 21:38
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend Codeanalyzer to Capture Database Entries

2 participants

@rahlk@sinha108