From 05e4d28f9e77e50793950f93c44b7334ff2a3794 Mon Sep 17 00:00:00 2001 From: 0007 <0007@qq.com> Date: Wed, 27 Aug 2025 19:58:14 +0800 Subject: [PATCH] Add File --- .../core/test/SearchWrapperTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 agents-flex-core/src/test/java/com/agentsflex/core/test/SearchWrapperTest.java diff --git a/agents-flex-core/src/test/java/com/agentsflex/core/test/SearchWrapperTest.java b/agents-flex-core/src/test/java/com/agentsflex/core/test/SearchWrapperTest.java new file mode 100644 index 0000000..d351c45 --- /dev/null +++ b/agents-flex-core/src/test/java/com/agentsflex/core/test/SearchWrapperTest.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023-2025, Agents-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.agentsflex.core.test; + +import java.util.Arrays; + +import com.agentsflex.core.store.SearchWrapper; +import com.agentsflex.core.store.condition.Connector; +import org.junit.Assert; +import org.junit.Test; + +public class SearchWrapperTest { + + @Test + public void test01() { + SearchWrapper rw = new SearchWrapper(); + rw.eq("akey", "avalue").eq(Connector.OR, "bkey", "bvalue").group(rw1 -> { + rw1.eq("ckey", "avalue").in(Connector.AND_NOT, "dkey", Arrays.asList("aa", "bb")); + }).eq("a", "b"); + + String expr = "akey = \"avalue\" OR bkey = \"bvalue\" AND (ckey = \"avalue\" AND NOT dkey IN (\"aa\",\"bb\")) AND a = \"b\""; + Assert.assertEquals(expr, rw.toFilterExpression()); + + System.out.println(rw.toFilterExpression()); + } + + @Test + public void test02() { + SearchWrapper rw = new SearchWrapper(); + rw.eq("akey", "avalue").between(Connector.OR, "bkey", "1", "100").in("ckey", Arrays.asList("aa", "bb")); + + String expr = "akey = \"avalue\" OR bkey BETWEEN \"1\" AND \"100\" AND ckey IN (\"aa\",\"bb\")"; + Assert.assertEquals(expr, rw.toFilterExpression()); + + System.out.println(rw.toFilterExpression()); + } + + @Test + public void test03() { + SearchWrapper rw = new SearchWrapper(); + rw.eq("ak", "av") + // and ( 子条件 ) + .andCriteria(rw1 -> { + rw1.eq("bk", "bv").in("x1", Arrays.asList("1", "2")); + }) + // or ( 子条件 ) + .orCriteria(rw1 -> { + rw1.eq("ck", "cv").eq("ck1", "cv1"); + }) + .eq("a", "b"); + + String expr = "ak = \"av\" AND (bk = \"bv\" AND x1 IN (\"1\",\"2\")) OR (ck = \"cv\" AND ck1 = \"cv1\") AND a = \"b\""; + Assert.assertEquals(expr, rw.toFilterExpression()); + + System.out.println(rw.toFilterExpression()); + } + +}