Skip to content

Issue 100 capture database entries #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 11, 2025
Merged

Conversation

rahlk
Copy link
Collaborator

@rahlk rahlk commented Feb 8, 2025

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

package com.ibm.cldk;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.MountableFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;

@Testcontainers
@SuppressWarnings("resource")
public class CodeAnalyzerIntegrationTest {
    // ...
    @Test
    void shouldBeAbleToDetectCRUDOperationsAndQueriesForPlantByWebsphere() throws Exception {
        var runCodeAnalyzerOnPlantsByWebsphere = 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.

rahlk added 4 commits February 6, 2025 19:21
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 review from sinha108 and rangeetpan February 8, 2025 05:46
@rahlk rahlk requested a review from pavuluri February 8, 2025 05:51
rahlk added 2 commits February 8, 2025 11:59
… 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>
@rahlk rahlk 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
Copy link
Collaborator Author

rahlk commented Feb 8, 2025

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.

package com.ibm.cldk;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.MountableFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;

@Testcontainers
@SuppressWarnings("resource")
public class CodeAnalyzerIntegrationTest {
    // ...
    @Test
    void shouldBeAbleToDetectCRUDOperationsAndQueriesForPlantByWebsphere() throws Exception {
        var runCodeAnalyzerOnPlantsByWebsphere = 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 string
        String expectedCrudOperation =
                "\"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 Queries
        String expectedCrudQuery =
                "\"crud_queries\": [" +
                        "{" +
                        "\"line_number\": 141,";

        // Normalize the output and expected strings to ignore formatting differences
        String normalizedOutput = output.replaceAll("\\s+", "");
        String normalizedExpectedCrudOperation = expectedCrudOperation.replaceAll("\\s+", "");
        String normalizedExpectedCrudQuery = expectedCrudQuery.replaceAll("\\s+", "");

        // Assertions for both CRUD operations and queries
        Assertions.assertTrue(normalizedOutput.contains(normalizedExpectedCrudOperation), "Expected CRUD operation JSON structure not found");
        Assertions.assertTrue(normalizedOutput.contains(normalizedExpectedCrudQuery), "Expected CRUD query JSON structure not found");
    }
}

rahlk added 2 commits February 8, 2025 16:04
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk self-assigned this Feb 8, 2025
@rahlk rahlk added the enhancement New feature or request label Feb 8, 2025
rahlk added 2 commits February 8, 2025 17:55
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 main Feb 11, 2025
@rahlk rahlk deleted the issue-100-capture-database-entries branch February 19, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend Codeanalyzer to Capture Database Entries
2 participants