Skip to content

Commit a1bf19c

Browse files
committed
添加单测
1 parent b49d35c commit a1bf19c

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-1
lines changed

core/src/main/java/com/taobao/arthas/core/command/express/ArthasObjectPropertyAccessor.java

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import ognl.OgnlException;
1010
import ognl.OgnlRuntime;
1111

12-
import java.util.Map;
1312

1413
/**
1514
* @author hengyunabc 2022-03-24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.taobao.arthas.core.command.express;
2+
3+
import com.taobao.arthas.core.advisor.Advice;
4+
import ognl.OgnlException;
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
import static org.junit.jupiter.api.Assertions.*;
12+
13+
class ArthasObjectPropertyAccessorTest {
14+
15+
private Express express;
16+
17+
@BeforeEach
18+
public void setUp () {
19+
Fetcher fetcher = new Fetcher().add(new Fetcher.Fetch()
20+
.add(new FlowContext("aa"))
21+
.add(new FlowContext("bb"))
22+
).add(new Fetcher.Fetch()
23+
.add(new FlowContext("cc"))
24+
.add(new FlowContext("dd"))
25+
.add(new FlowContext("ee"))
26+
);
27+
28+
Object[] params = new Object[4];
29+
params[0] = fetcher;
30+
Advice advice = Advice.newForAfterReturning(null, getClass(), null, null, params, null);
31+
express = ExpressFactory.unpooledExpress(null).bind(advice);
32+
}
33+
34+
@Test
35+
void getPossibleProperty() throws ExpressException {
36+
assertInstanceOf(List.class, express.get("params[0].completedFetches"));
37+
assertEquals(2, ((List<?>) express.get("params[0].completedFetches")).size());
38+
assertThrows(ExpressException.class, () -> express.is("params[0].hasCompletedFetches"));
39+
assertTrue(express.is("params[0].hasCompletedFetches()"));
40+
assertThrows(ExpressException.class, () -> express.is("params[0].getCompletedFetches"));
41+
assertTrue(express.is("params[0].getCompletedFetches()"));
42+
assertInstanceOf(Fetcher.Fetch.class, express.get("params[0].completedFetches[1]"));
43+
assertInstanceOf(List.class, express.get("params[0].completedFetches[1].flowContexts"));
44+
assertEquals(3, ((List) express.get("params[0].completedFetches[1].flowContexts")).size());
45+
assertTrue(express.is("params[0].completedFetches[1].hasFlowContexts()"));
46+
assertTrue(express.is("params[0].completedFetches[1].getFlowContexts()"));
47+
assertInstanceOf(List.class, express.get("params[0].completedFetches[1].getFlowContexts1()"));
48+
assertInstanceOf(List.class, express.get("params[0].completedFetches.{flowContexts.{flowAttribute.bxApp}}"));
49+
assertIterableEquals(Arrays.asList(
50+
Arrays.asList("aa", "bb"),
51+
Arrays.asList("cc", "dd", "ee")
52+
), (Iterable<?>) express.get("params[0].completedFetches.{flowContexts.{flowAttribute.bxApp}}"));
53+
}
54+
55+
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.taobao.arthas.core.command.express;
2+
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
public class Fetcher {
8+
private final List<Fetch> completedFetches = new ArrayList<>();
9+
10+
public boolean hasCompletedFetches() {
11+
return !completedFetches.isEmpty();
12+
}
13+
14+
public boolean getCompletedFetches() {
15+
return hasCompletedFetches();
16+
}
17+
18+
public Fetcher add(Fetch fetch) {
19+
completedFetches.add(fetch);
20+
return this;
21+
}
22+
23+
public static class Fetch {
24+
private final List<FlowContext> flowContexts = new ArrayList<>();
25+
public boolean hasFlowContexts() {
26+
return !flowContexts.isEmpty();
27+
}
28+
29+
public boolean getFlowContexts() {
30+
return !flowContexts.isEmpty();
31+
}
32+
33+
public List<FlowContext> getFlowContexts1() {
34+
return flowContexts;
35+
}
36+
37+
public Fetch add(FlowContext flowContext) {
38+
flowContexts.add(flowContext);
39+
return this;
40+
}
41+
42+
}
43+
}
44+
45+

core/src/test/java/com/taobao/arthas/core/command/express/FlowAttribute.java

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
public class FlowAttribute {
44
private String bxApp = "aaa";
55

6+
public FlowAttribute() {
7+
}
8+
9+
public FlowAttribute(String bxApp) {
10+
this.bxApp = bxApp;
11+
}
12+
613
public String getBxApp() {
714
return this.bxApp ;
815
}

core/src/test/java/com/taobao/arthas/core/command/express/FlowContext.java

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
public class FlowContext {
44
private FlowAttribute flowAttribute = new FlowAttribute();
55

6+
7+
public FlowContext() {
8+
}
9+
10+
public FlowContext(String app) {
11+
this.flowAttribute = new FlowAttribute(app);
12+
}
13+
614
public FlowAttribute getFlowAttribute() {
715
return this.flowAttribute ;
816
}

0 commit comments

Comments
 (0)