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
+ }
0 commit comments