Commit Graph

9 Commits

Author SHA1 Message Date
Oleksandr Klymenko d73bd94682
test: enhance test coverage for IsEqualTo filter and Tablestore utilities (#3791)
This PR enhances test coverage for the `IsEqualTo` filter class and
`Tablestore` embedding utilities, focusing on edge cases, error
conditions, and type conversion scenarios.

**Changes**
Added 7 new tests to `IsEqualToTest`:

- Value comparison: Tests inequality detection between different values
- Type conversion: Verifies number type conversion (Long to Integer)
- Case sensitivity: Ensures string comparisons are case-sensitive
- Null handling: Tests behavior with null objects and null comparison
values
- Special characters: Validates keys containing dots work correctly
- Floating-point: Tests decimal number comparisons

Added 4 new tests to `TablestoreEmbeddingStoreTest`:

- Empty arrays: Tests serialization/deserialization of empty embeddings
- Null validation: Ensures proper exception handling for null inputs
- Round-trip consistency: Validates empty array parsing

**Impact**
The existing tests missed critical edge cases that could lead to runtime
errors. These additions ensure proper null handling, validate type
conversions work as expected, and document the API's behavior for edge
cases like empty arrays and special characters.

Signed-off-by: Oleksandr Klymenko <alexanderklmn@gmail.com>
2025-10-01 11:45:22 +02:00
Oleksandr Klymenko 1e88059547
test: Add critical validation and edge case tests for AiServices, StreamingChatModelMock, and TablestoreEmbeddingStore (#3759)
## Description
This PR adds comprehensive test coverage for critical validation
scenarios and edge cases across three core components that were
previously untested.

## Changes

### AiServicesTest
- **Null validation**: `should_handle_null_chat_model` - Ensures proper
error when chatModel is null
- **Type validation**: `should_handle_non_interface_class` - Verifies
only interfaces are accepted
- **Instance independence**:
`should_create_different_instances_for_same_interface` - Confirms each
build creates unique instances
- **Type preservation**: `should_preserve_interface_type` - Validates
proxy maintains interface type

### StreamingChatModelMockTest  
- **Empty string handling**: `test_toTokens_with_empty_string` -
Verifies empty strings return empty token list
- **Consecutive spaces preservation**:
`test_toTokens_preserves_consecutive_spaces` - Ensures multiple spaces
are tokenized individually and preserved

### TablestoreEmbeddingStoreTest
- **Empty array parsing**: `parse_embedding_string_with_empty_array` -
Tests empty array handling
- **Single value parsing**: `parse_embedding_string_with_single_value` -
Single element edge case
- **Invalid format**: `parse_embedding_string_with_invalid_format` -
Validates error handling for malformed input
- **Null safety**: `parse_embedding_string_null_input` and
`embedding_to_string_null_array` - Null input validation
- **Empty array conversion**: `embedding_to_string_empty_array` - Tests
empty array to string conversion

## Impact
These tests prevent:
- NullPointerExceptions in production
- Invalid configuration errors going undetected
- Silent failures with edge case inputs
- Enforcing type system constraints and interface contracts

---------

Signed-off-by: Oleksandr Klymenko <alexanderklmn@gmail.com>
2025-09-26 09:58:09 +02:00
Ivan Milosavljević efbdcabbf8
Use isNullOrEmpty and isNullOrBlank functions from Utils class (#3071)
<!--
Thank you so much for your contribution!

Please fill in all the sections below.
Please open the PR as a draft initially. Once it is reviewed and
approved, we will ask you to add documentation and examples.
Please note that PRs with breaking changes or without tests will be
rejected.

Please note that PRs will be reviewed based on the priority of the
issues they address.
We ask for your patience. We are doing our best to review your PR as
quickly as possible.
Please refrain from pinging and asking when it will be reviewed. Thank
you for understanding!
-->

## Issue
<!-- Please specify the ID of the issue this PR is addressing. For
example: "Closes #1234" or "Fixes #1234" -->
Closes #

## Change
<!-- Please describe the changes you made. -->
I noticed that in a lot of files there are duplicated checks for `null`
and not empty or `null` and not blank. Since there exist functions in
`Utils` class which do exactly that, I replaced all custom checks with
calls to such functions.

## General checklist

NB: I purposefully didn't commit formatting changes (i.e., `make lint`
and `make format`) because they'd change many lines in many files, much
more than what I changed in this PR, and that'd make PR difficult to
review. If you think I should do it, I'd gladly commit them.
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes
- [ ] I have added unit and/or integration tests for my change
- [ ] The tests cover both positive and negative cases
- [ ] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)


## Checklist for adding new maven module
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added my new module in the root `pom.xml` and
`langchain4j-bom/pom.xml`


## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [ ] I have added a `{NameOfIntegration}EmbeddingStoreRemovalIT` that
extends from `EmbeddingStoreWithRemovalIT`

## Checklist for changing existing embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [ ] I have manually verified that the
`{NameOfIntegration}EmbeddingStore` works correctly with the data
persisted using the latest released version of LangChain4j

---------

Co-authored-by: Dmytro Liubarskyi <ljubarskij@gmail.com>
2025-07-01 09:33:33 +02:00
Dmytro Liubarskyi 025ed48bd3 cosmetics 2025-04-30 14:10:50 +02:00
Tim te Beek 86afe2698e
Apply testing best practices to the project and future pull requests (#2561)
## Issue
As discussed with @dliubarskyi on
-
https://github.com/langchain4j/langchain4j/pull/2437#discussion_r1928261580

## Change
Ran a trio of OpenRewrite recipes to improve the tests here:
1.
[TestsShouldNotBePublic](https://docs.openrewrite.org/recipes/java/testing/cleanup/testsshouldnotbepublic)
2.
[RemoveTestPrefix](https://docs.openrewrite.org/recipes/java/testing/cleanup/removetestprefix)
3.
[Assertj](https://docs.openrewrite.org/recipes/java/testing/assertj/assertj-best-practices)

This was followed by some light touch ups, and applying Spotless to any
changed files.
I've also added the recipes to those enforced on future PRs, and applied
minor fixes to that workflow.

Already ran the tests on a fork PR, to verify the integration
- https://github.com/timtebeek/langchain4j/pull/1

## General checklist
- [x] There are no breaking changes
- [x] I have added unit and/or integration tests for my change
- [x] The tests cover both positive and negative cases
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2025-02-17 11:24:24 +01:00
Victor 48681d97b5
EmbeddingStore: implement addAll(ids, embeddings, segments) (#2156)
## Issue
Closes #2106 
Contributes to #2160

## Change
Added method `addAll(**ids**, embeddings, embedded)`

## General checklist
- [x] There are no breaking changes
- [ ] I have added unit and integration tests for my change
- [x] I have manually run all the unit tests in the module I have
added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)
2024-12-04 18:00:07 +01:00
Tim te Beek e199c6b2e6
Apply additional AssertJ best practices since #673 (#1904)
## Issue
- Follows https://github.com/langchain4j/langchain4j/pull/673

## Change
Apply best practices once more, as time had passed between when #673 was
opened and today. By clearing out any recipe suggestions on the main
branch we ensure any new suggestions on PRs are limited to changed
files.

## General checklist
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] There are no breaking changes
- [x] I have added unit and integration tests for my change
- [ ] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [ ] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [ ] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
2024-10-14 16:34:09 +02:00
LangChain4j 1dc3ce6e96 Add langchain4j-tablestore Integration:  TablestoreEmbeddingStore/TablestoreChatMemoryStore (#1650) 2024-09-18 11:45:40 +02:00
ScriptShi be7454a7c6
Add langchain4j-tablestore Integration: TablestoreEmbeddingStore/TablestoreChatMemoryStore (#1650)
## Change
Add langchain4j-tablestore Integration: TablestoreEmbeddingStore /
TablestoreChatMemoryStore

## General checklist
- [x] There are no breaking changes
- [x] I have added unit and integration tests for my change
- [x] I have manually run all the unit and integration tests in the
module I have added/changed, and they are all green
- [x] I have manually run all the unit and integration tests in the
[core](https://github.com/langchain4j/langchain4j/tree/main/langchain4j-core)
and
[main](https://github.com/langchain4j/langchain4j/tree/main/langchain4j)
modules, and they are all green
<!-- Before adding documentation and example(s) (below), please wait
until the PR is reviewed and approved. -->
- [x] I have added/updated the
[documentation](https://github.com/langchain4j/langchain4j/tree/main/docs/docs)
- [ ] I have added an example in the [examples
repo](https://github.com/langchain4j/langchain4j-examples) (only for
"big" features)
- [ ] I have added/updated [Spring Boot
starter(s)](https://github.com/langchain4j/langchain4j-spring) (if
applicable)

## Checklist for adding new embedding store integration
<!-- Please double-check the following points and mark them like this:
[X] -->
- [x] I have added a `{NameOfIntegration}EmbeddingStoreIT` that extends
from either `EmbeddingStoreIT` or `EmbeddingStoreWithFilteringIT`
- [x] I have added my new module in the
[BOM](https://github.com/langchain4j/langchain4j/blob/main/langchain4j-bom/pom.xml)
2024-09-18 11:41:53 +02:00