-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update test resources and service classes (#883)
- Loading branch information
Showing
9 changed files
with
257 additions
and
18 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
jcommon/ai/neo4j/src/main/java/run/mone/neo4j/BotCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package run.mone.neo4j; | ||
|
||
import com.google.gson.JsonObject; | ||
import lombok.Setter; | ||
import okhttp3.*; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/8/21 13:50 | ||
*/ | ||
public class BotCall { | ||
|
||
//调用bot的地址 | ||
@Setter | ||
private static String url = ""; | ||
|
||
|
||
public static String call(String desc, String input) { | ||
OkHttpClient client = new OkHttpClient.Builder() | ||
.connectTimeout(30, TimeUnit.SECONDS) | ||
.readTimeout(30, TimeUnit.SECONDS) | ||
.writeTimeout(30, TimeUnit.SECONDS) | ||
.build(); | ||
|
||
// 使用 Gson 的 JsonObject 构建请求体 | ||
JsonObject mainObject = new JsonObject(); | ||
mainObject.addProperty("userName", ""); | ||
mainObject.addProperty("botId", ""); | ||
mainObject.addProperty("input", ""); | ||
|
||
JsonObject paramsObject = new JsonObject(); | ||
paramsObject.addProperty("desc", desc); | ||
paramsObject.addProperty("input", input); | ||
mainObject.add("params", paramsObject); | ||
|
||
// 将 JsonObject 转换为字符串 | ||
String jsonBody = mainObject.toString(); | ||
|
||
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonBody); | ||
|
||
Request request = new Request.Builder() | ||
.url(url) | ||
.post(body) | ||
.addHeader("Accept", "application/json, text/plain, */*") | ||
.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8") | ||
.addHeader("Cache-Control", "no-cache") | ||
.addHeader("Connection", "keep-alive") | ||
.addHeader("Content-Type", "application/json") | ||
.addHeader("Authorization", "") | ||
.build(); | ||
|
||
try { | ||
Response response = client.newCall(request).execute(); | ||
return response.body().string(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return ""; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
package run.mone.neo4j.test; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.gson.Gson; | ||
import org.junit.Test; | ||
import org.neo4j.driver.Record; | ||
import org.neo4j.driver.Result; | ||
import org.neo4j.driver.Session; | ||
import org.neo4j.driver.internal.InternalRecord; | ||
import org.neo4j.driver.internal.InternalResult; | ||
import org.neo4j.driver.internal.InternalSession; | ||
import run.mone.neo4j.BotCall; | ||
import run.mone.neo4j.MoneCodeParser; | ||
import run.mone.neo4j.test.MoneCodeParserTest; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
|
||
/** | ||
* @author [email protected] | ||
|
@@ -10,17 +35,68 @@ | |
public class MoneCodeParserTest { | ||
|
||
|
||
|
||
@Test | ||
public void testWriteCatServiceToNeo4j() { | ||
// new MoneCodeParser().writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/ai/m78/m78-service/src/main/java/run/mone/m78/service"); | ||
// MoneCodeParser.writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/ai/m78/m78-service/src/main/java/run/mone/m78/service/database"); | ||
// MoneCodeParser.writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/ai/m78/m78-service/src/main/java/run/mone/m78/service/database/SqlParseUtil.java"); | ||
// new MoneCodeParser().writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/goodjava/mone/jcommon/ai/neo4j/src/test/java/run/mone/neo4j/test/A.java"); | ||
new MoneCodeParser().writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/goodjava/mone/jcommon/ai/neo4j/src/test/java/run/mone/neo4j/test/m"); | ||
new MoneCodeParser().setPassword(System.getenv("password")).writeJavaFilesToNeo4j("/Users/zhangzhiyong/IdeaProjects/goodjava/mone/jcommon/ai/neo4j/src/test/java/run/mone/neo4j/test/m"); | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
new MoneCodeParser().queryEntityClasses(); | ||
} | ||
|
||
|
||
|
||
|
||
@Test | ||
public void testFindClassesWithAnnotation() { | ||
MoneCodeParser moneCodeParser = new MoneCodeParser().setPassword(System.getenv("password")); | ||
List<Map<String, Object>> actual = moneCodeParser.findClassesWithAnnotation(moneCodeParser.getSession(), "Table"); | ||
System.out.println(actual); | ||
|
||
// String xuqiu = "获取狗的主人"; | ||
String xuqiu = "管理宠物鸟"; | ||
String res = BotCall.call(moneCodeParser.readResourceFileContent("entity.md") + xuqiu, new Gson().toJson(actual)); | ||
System.out.println(res); | ||
} | ||
|
||
|
||
|
||
@Test | ||
public void testFindClassesWithAnnotation2() { | ||
MoneCodeParser moneCodeParser = new MoneCodeParser().setPassword(System.getenv("password")); | ||
List<Map<String, Object>> actual = moneCodeParser.findClassesWithAnnotation(moneCodeParser.getSession(), "RestController"); | ||
System.out.println(actual); | ||
|
||
String xuqiu = "获取狗的主人"; | ||
// String xuqiu = "管理宠物鸟"; | ||
String res = BotCall.call(moneCodeParser.readResourceFileContent("service.md") + xuqiu, new Gson().toJson(actual)); | ||
System.out.println(res); | ||
} | ||
|
||
|
||
@Test | ||
public void testJson() { | ||
Map<String, String> m = ImmutableMap.of("input", "a+b=?"); | ||
System.out.println(new Gson().toJson(m)); | ||
} | ||
|
||
|
||
@Test | ||
public void testReadResourceFileContent() { | ||
String fileName = "entity.md"; | ||
// Assuming the test resource file is already placed in the resources directory | ||
String actualContent = new MoneCodeParser().readResourceFileContent(fileName); | ||
|
||
assertNotNull(actualContent); | ||
} | ||
|
||
|
||
|
||
|
||
} |
8 changes: 8 additions & 0 deletions
8
jcommon/ai/neo4j/src/test/java/run/mone/neo4j/test/anno/Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package run.mone.neo4j.test.anno; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/8/21 16:06 | ||
*/ | ||
public @interface Service { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package run.mone.neo4j.test.m; | ||
|
||
import run.mone.neo4j.test.anno.RestController; | ||
import run.mone.neo4j.test.anno.Service; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
@@ -9,7 +10,7 @@ | |
* @author [email protected] | ||
* @date 2024/8/19 18:21 | ||
*/ | ||
@RestController | ||
@Service | ||
public class CatService { | ||
|
||
private Map<String,String> data = new HashMap<>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,7 @@ | |
*/ | ||
@Table | ||
public class Dog { | ||
|
||
private int id; | ||
|
||
} |
Oops, something went wrong.