4
4
import com .ctrip .framework .apollo .biz .entity .Namespace ;
5
5
import com .ctrip .framework .apollo .biz .entity .Release ;
6
6
import com .ctrip .framework .apollo .biz .service .ItemService ;
7
+ import com .ctrip .framework .apollo .biz .service .NamespaceService ;
7
8
import com .ctrip .framework .apollo .biz .service .ReleaseService ;
8
9
9
10
import org .junit .Assert ;
@@ -26,6 +27,8 @@ public class NamespaceUnlockAspectTest {
26
27
private ReleaseService releaseService ;
27
28
@ Mock
28
29
private ItemService itemService ;
30
+ @ Mock
31
+ private NamespaceService namespaceService ;
29
32
30
33
@ InjectMocks
31
34
private NamespaceUnlockAspect namespaceUnlockAspect ;
@@ -55,6 +58,7 @@ public void testNamespaceAddItem() {
55
58
56
59
when (releaseService .findLatestActiveRelease (namespace )).thenReturn (release );
57
60
when (itemService .findItems (namespaceId )).thenReturn (items );
61
+ when (namespaceService .findParentNamespace (namespace )).thenReturn (null );
58
62
59
63
boolean isModified = namespaceUnlockAspect .isModified (namespace );
60
64
@@ -71,6 +75,7 @@ public void testNamespaceModifyItem() {
71
75
72
76
when (releaseService .findLatestActiveRelease (namespace )).thenReturn (release );
73
77
when (itemService .findItems (namespaceId )).thenReturn (items );
78
+ when (namespaceService .findParentNamespace (namespace )).thenReturn (null );
74
79
75
80
boolean isModified = namespaceUnlockAspect .isModified (namespace );
76
81
@@ -87,12 +92,54 @@ public void testNamespaceDeleteItem() {
87
92
88
93
when (releaseService .findLatestActiveRelease (namespace )).thenReturn (release );
89
94
when (itemService .findItems (namespaceId )).thenReturn (items );
95
+ when (namespaceService .findParentNamespace (namespace )).thenReturn (null );
90
96
91
97
boolean isModified = namespaceUnlockAspect .isModified (namespace );
92
98
93
99
Assert .assertTrue (isModified );
94
100
}
95
101
102
+ @ Test
103
+ public void testChildNamespaceModified () {
104
+ long childNamespaceId = 1 , parentNamespaceId = 2 ;
105
+ Namespace childNamespace = createNamespace (childNamespaceId );
106
+ Namespace parentNamespace = createNamespace (childNamespaceId );
107
+
108
+ Release childRelease = createRelease ("{\" k1\" :\" v1\" , \" k2\" :\" v2\" }" );
109
+ List <Item > childItems = Arrays .asList (createItem ("k1" , "v3" ));
110
+ List <Item > parentItems = Arrays .asList (createItem ("k1" , "v1" ), createItem ("k2" , "v2" ));
111
+
112
+ when (releaseService .findLatestActiveRelease (childNamespace )).thenReturn (childRelease );
113
+ when (itemService .findItems (childNamespaceId )).thenReturn (childItems );
114
+ when (itemService .findItems (parentNamespaceId )).thenReturn (parentItems );
115
+ when (namespaceService .findParentNamespace (parentNamespace )).thenReturn (parentNamespace );
116
+
117
+ boolean isModified = namespaceUnlockAspect .isModified (parentNamespace );
118
+
119
+ Assert .assertTrue (isModified );
120
+ }
121
+
122
+ @ Test
123
+ public void testChildNamespaceNotModified () {
124
+ long childNamespaceId = 1 , parentNamespaceId = 2 ;
125
+ Namespace childNamespace = createNamespace (childNamespaceId );
126
+ Namespace parentNamespace = createNamespace (childNamespaceId );
127
+
128
+ Release childRelease = createRelease ("{\" k1\" :\" v1\" , \" k2\" :\" v2\" }" );
129
+ List <Item > childItems = Arrays .asList (createItem ("k1" , "v1" ));
130
+ List <Item > parentItems = Arrays .asList (createItem ("k2" , "v2" ));
131
+
132
+ when (releaseService .findLatestActiveRelease (childNamespace )).thenReturn (childRelease );
133
+ when (itemService .findItems (childNamespaceId )).thenReturn (childItems );
134
+ when (itemService .findItems (parentNamespaceId )).thenReturn (parentItems );
135
+ when (namespaceService .findParentNamespace (parentNamespace )).thenReturn (parentNamespace );
136
+
137
+ boolean isModified = namespaceUnlockAspect .isModified (parentNamespace );
138
+
139
+ Assert .assertTrue (isModified );
140
+ }
141
+
142
+
96
143
private Namespace createNamespace (long namespaceId ) {
97
144
Namespace namespace = new Namespace ();
98
145
namespace .setId (namespaceId );
0 commit comments