|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.nageoffer.ai.ragent.rag.core.intent; |
| 19 | + |
| 20 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 22 | +import org.junit.jupiter.api.Test; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 27 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 28 | + |
| 29 | +class IntentNodeJsonTest { |
| 30 | + |
| 31 | + private final ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules() |
| 32 | + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); |
| 33 | + |
| 34 | + @Test |
| 35 | + void roundTripsCollectionNamesWithoutSerializingComputedProperty() throws Exception { |
| 36 | + IntentNode node = IntentNode.builder() |
| 37 | + .id("insurance") |
| 38 | + .collectionNames(List.of("insurance", " claims ", "insurance")) |
| 39 | + .build(); |
| 40 | + |
| 41 | + String json = objectMapper.writeValueAsString(node); |
| 42 | + IntentNode restored = objectMapper.readValue(json, IntentNode.class); |
| 43 | + |
| 44 | + assertFalse(json.contains("effectiveCollectionNames")); |
| 45 | + assertEquals(List.of("insurance", "claims"), restored.getEffectiveCollectionNames()); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + void ignoresComputedPropertyFromExistingCacheEntry() throws Exception { |
| 50 | + String json = """ |
| 51 | + { |
| 52 | + "id": "insurance", |
| 53 | + "collectionNames": ["insurance"], |
| 54 | + "effectiveCollectionNames": ["stale"] |
| 55 | + } |
| 56 | + """; |
| 57 | + |
| 58 | + IntentNode restored = objectMapper.readValue(json, IntentNode.class); |
| 59 | + |
| 60 | + assertEquals(List.of("insurance"), restored.getEffectiveCollectionNames()); |
| 61 | + } |
| 62 | +} |
0 commit comments