forked from XiaoMi/mone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'XiaoMi:master' into master
- Loading branch information
Showing
10 changed files
with
297 additions
and
4 deletions.
There are no files selected for viewing
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,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>run.mone</groupId> | ||
<artifactId>docean-plugin</artifactId> | ||
<version>1.5.0-jdk21</version> | ||
</parent> | ||
|
||
<artifactId>docean-plugin-junit</artifactId> | ||
<version>1.5.0-jdk21-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>run.mone</groupId> | ||
<artifactId>docean</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.10.2</version> | ||
</dependency> | ||
|
||
|
||
|
||
</dependencies> | ||
|
||
|
||
</project> |
16 changes: 16 additions & 0 deletions
16
...n/docean-plugin/docean-plugin-junit/src/main/java/run/mone/junit/DoceanConfiguration.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,16 @@ | ||
package run.mone.junit; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/3 09:19 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) // 应用于类 | ||
public @interface DoceanConfiguration { | ||
String[] basePackage(); | ||
} |
52 changes: 52 additions & 0 deletions
52
jcommon/docean-plugin/docean-plugin-junit/src/main/java/run/mone/junit/DoceanExtension.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,52 @@ | ||
package run.mone.junit; | ||
|
||
import com.xiaomi.youpin.docean.Ioc; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeEachCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import javax.annotation.Resource; | ||
import java.util.Arrays; | ||
|
||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/3 09:14 | ||
*/ | ||
public class DoceanExtension implements BeforeAllCallback,BeforeEachCallback { | ||
|
||
private Ioc container; | ||
|
||
|
||
@Override | ||
public void beforeAll(ExtensionContext extensionContext) throws Exception { | ||
// 获取测试类 | ||
Class<?> testClass = extensionContext.getRequiredTestClass(); | ||
DoceanConfiguration iocConfig = testClass.getAnnotation(DoceanConfiguration.class); | ||
if (iocConfig == null) { | ||
throw new IllegalStateException("Missing @IocConfiguration on test class " + testClass.getName()); | ||
} | ||
// 从注解中获取包名 | ||
String[] basePackage = iocConfig.basePackage(); | ||
// 初始化IoC容器 | ||
this.container = Ioc.ins().init(basePackage); | ||
} | ||
|
||
@Override | ||
public void beforeEach(ExtensionContext extensionContext) throws Exception { | ||
Object testInstance = extensionContext.getRequiredTestInstance(); | ||
Arrays.stream(testInstance.getClass().getDeclaredFields()) | ||
.filter(field -> field.isAnnotationPresent(Resource.class)) | ||
.forEach(field -> { | ||
Object bean = container.getBean(field.getType()); | ||
if (bean != null) { | ||
field.setAccessible(true); | ||
try { | ||
field.set(testInstance, bean); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
jcommon/docean-plugin/docean-plugin-junit/src/test/java/run/mone/junit/test/ServiceTest.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,27 @@ | ||
package run.mone.junit.test; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import run.mone.junit.DoceanConfiguration; | ||
import run.mone.junit.DoceanExtension; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/3 17:37 | ||
*/ | ||
@ExtendWith(DoceanExtension.class) | ||
@DoceanConfiguration(basePackage = {"run.mone.junit.test"}) | ||
public class ServiceTest { | ||
|
||
@Resource | ||
private TestService ts; | ||
|
||
|
||
@Test | ||
public void test1() { | ||
System.out.println(ts.hi()); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
jcommon/docean-plugin/docean-plugin-junit/src/test/java/run/mone/junit/test/TestService.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,16 @@ | ||
package run.mone.junit.test; | ||
|
||
import com.xiaomi.youpin.docean.anno.Service; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/3 17:36 | ||
*/ | ||
@Service | ||
public class TestService { | ||
|
||
public String hi() { | ||
return "hello"; | ||
} | ||
|
||
} |
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
22 changes: 22 additions & 0 deletions
22
jcommon/struct/src/test/java/run/mone/struct/test/GraphContext.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,22 @@ | ||
package run.mone.struct.test; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/1 14:01 | ||
*/ | ||
@Data | ||
@Builder | ||
public class GraphContext { | ||
|
||
|
||
@Builder.Default | ||
private Map<Integer, Map<String, String>> input = new HashMap<>(); | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
jcommon/struct/src/test/java/run/mone/struct/test/GraphTest.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,48 @@ | ||
package run.mone.struct.test; | ||
|
||
import com.xiaomi.data.push.graph.Graph; | ||
import com.xiaomi.data.push.graph.Vertex; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/1 10:53 | ||
*/ | ||
public class GraphTest { | ||
|
||
@Test | ||
public void initializeAndTopologicallySortGraph() { | ||
Graph<VertexData> graph = new Graph<>(5); | ||
graph.addVertex(new Vertex<>(0, VertexData.builder().data("开始").id(0).build())); | ||
graph.addVertex(new Vertex<>(1, VertexData.builder().data("代码").id(1).build())); | ||
graph.addVertex(new Vertex<>(2, VertexData.builder().data("大模型").id(2).build())); | ||
graph.addVertex(new Vertex<>(3, VertexData.builder().data("选择器").id(3).param("abc").build())); | ||
graph.addVertex(new Vertex<>(4, VertexData.builder().data("结束").id(4).build())); | ||
|
||
graph.addEdge(0, 1); | ||
graph.addEdge(1, 3); | ||
graph.addEdge(3, 2); | ||
graph.addEdge(3, 4); | ||
|
||
List<Integer> list = graph.topologicalSort(); | ||
System.out.println(list); | ||
|
||
GraphContext context = GraphContext.builder().build(); | ||
list.stream().forEach(it -> { | ||
VertexData data = graph.getVertexData(it); | ||
if (!data.isFinish()) { | ||
data.execute(graph); | ||
context.getInput().put(data.getId(),data.getOutput()); | ||
System.out.println(data.getData()); | ||
data.setFinish(true); | ||
} | ||
}); | ||
|
||
System.out.println(context); | ||
|
||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
jcommon/struct/src/test/java/run/mone/struct/test/VertexData.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,58 @@ | ||
package run.mone.struct.test; | ||
|
||
import com.xiaomi.data.push.graph.Graph; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2024/3/1 10:55 | ||
*/ | ||
@Data | ||
@Builder | ||
public class VertexData implements Serializable { | ||
|
||
private String data; | ||
|
||
boolean finish; | ||
|
||
private int id; | ||
|
||
private String param; | ||
|
||
@Builder.Default | ||
private Map<String, String> input = new HashMap<>(); | ||
|
||
@Builder.Default | ||
private Map<String, String> output = new HashMap<>(); | ||
|
||
|
||
public void execute(Graph<VertexData> graph) { | ||
if (data.equals("选择器")) { | ||
List[] listArray = graph.getAdj(); | ||
List<Integer> list = listArray[id]; | ||
|
||
if (param.equals("abc")) { | ||
graph.getVertexData(2).setFinish(true); | ||
} | ||
|
||
System.out.println(list); | ||
|
||
} | ||
|
||
if (data.equals("开始")) { | ||
this.output.put("name", "zzy"); | ||
} | ||
|
||
if (data.equals("代码")) { | ||
this.output.put("name1","aaaa"); | ||
} | ||
} | ||
|
||
|
||
} |