@@ -46,9 +46,11 @@ void beforeEach() {
4646 @ Test
4747 void createReadUpdateDeleteNotificationRules () {
4848 NotificationRuleMutableData notificationRuleMutableData1 =
49- getNotificationRuleMutableData ("rule1" , "channel1" );
49+ getNotificationRuleMutableData ("rule1" , "channel1" , false );
5050 NotificationRuleMutableData notificationRuleMutableData2 =
51- getNotificationRuleMutableData ("rule2" , "channel1" );
51+ getNotificationRuleMutableData ("rule2" , "channel1" , false );
52+ NotificationRuleMutableData notificationRuleMutableData3 =
53+ getNotificationRuleMutableData ("rule3" , "channel1" , false );
5254 when (notificationRuleStore .getAllObjects (any ())).thenReturn (List .of ());
5355
5456 NotificationRule notificationRule1 =
@@ -86,8 +88,25 @@ void createReadUpdateDeleteNotificationRules() {
8688 .build ())
8789 .getNotificationRule ());
8890
91+ NotificationRule notificationRule3 =
92+ notificationStub
93+ .createNotificationRule (
94+ CreateNotificationRuleRequest .newBuilder ()
95+ .setNotificationRuleMutableData (notificationRuleMutableData3 )
96+ .build ())
97+ .getNotificationRule ();
98+
8999 assertEquals (
90- List .of (notificationRule2 , notificationRule1 ),
100+ notificationRule3 ,
101+ notificationStub
102+ .getNotificationRule (
103+ GetNotificationRuleRequest .newBuilder ()
104+ .setNotificationRuleId (notificationRule3 .getId ())
105+ .build ())
106+ .getNotificationRule ());
107+
108+ assertEquals (
109+ List .of (notificationRule3 , notificationRule2 , notificationRule1 ),
91110 notificationStub
92111 .getAllNotificationRules (
93112 GetAllNotificationRulesRequest .newBuilder ()
@@ -114,7 +133,35 @@ void createReadUpdateDeleteNotificationRules() {
114133 .build ())
115134 .getNotificationRule ();
116135 assertEquals (ruleToUpdate , updatedRule );
136+ // disable rule
137+ NotificationRule ruleToUpdate3 =
138+ notificationRule3 .toBuilder ()
139+ .setNotificationRuleMutableData (
140+ notificationRule3 .getNotificationRuleMutableData ().toBuilder ()
141+ .setDisabled (true )
142+ .build ())
143+ .build ();
144+ NotificationRule updatedRule3 =
145+ notificationStub
146+ .updateNotificationRule (
147+ UpdateNotificationRuleRequest .newBuilder ()
148+ .setNotificationRuleMutableData (ruleToUpdate3 .getNotificationRuleMutableData ())
149+ .setId (ruleToUpdate3 .getId ())
150+ .build ())
151+ .getNotificationRule ();
152+ assertEquals (ruleToUpdate3 , updatedRule3 );
117153
154+ assertEquals (
155+ List .of (updatedRule3 , notificationRule2 , updatedRule ),
156+ notificationStub
157+ .getAllNotificationRules (
158+ GetAllNotificationRulesRequest .newBuilder ()
159+ .setFilter (
160+ NotificationRuleFilter .newBuilder ()
161+ .addEventConditionType ("metricAnomalyEventCondition" )
162+ .build ())
163+ .build ())
164+ .getNotificationRulesList ());
118165 assertEquals (
119166 List .of (notificationRule2 , updatedRule ),
120167 notificationStub
@@ -123,6 +170,7 @@ void createReadUpdateDeleteNotificationRules() {
123170 .setFilter (
124171 NotificationRuleFilter .newBuilder ()
125172 .addEventConditionType ("metricAnomalyEventCondition" )
173+ .setEnabled (true )
126174 .build ())
127175 .build ())
128176 .getNotificationRulesList ());
@@ -131,6 +179,18 @@ void createReadUpdateDeleteNotificationRules() {
131179 DeleteNotificationRuleRequest .newBuilder ()
132180 .setNotificationRuleId (notificationRule2 .getId ())
133181 .build ());
182+ assertEquals (
183+ List .of (updatedRule3 , updatedRule ),
184+ notificationStub
185+ .getAllNotificationRules (
186+ GetAllNotificationRulesRequest .newBuilder ()
187+ .setFilter (
188+ NotificationRuleFilter .newBuilder ()
189+ .addEventConditionType ("metricAnomalyEventCondition" )
190+ .build ())
191+ .build ())
192+ .getNotificationRulesList ());
193+
134194 assertEquals (
135195 List .of (updatedRule ),
136196 notificationStub
@@ -139,19 +199,21 @@ void createReadUpdateDeleteNotificationRules() {
139199 .setFilter (
140200 NotificationRuleFilter .newBuilder ()
141201 .addEventConditionType ("metricAnomalyEventCondition" )
202+ .setEnabled (true )
142203 .build ())
143204 .build ())
144205 .getNotificationRulesList ());
145206 }
146207
147208 private NotificationRuleMutableData getNotificationRuleMutableData (
148- String name , String channelId ) {
209+ String name , String channelId , boolean disabled ) {
149210 return NotificationRuleMutableData .newBuilder ()
150211 .setRuleName (name )
151212 .setDescription ("sample rule" )
152213 .setChannelId (channelId )
153214 .setEventConditionType ("metricAnomalyEventCondition" )
154215 .setEventConditionId ("rule-1" )
216+ .setDisabled (disabled )
155217 .build ();
156218 }
157219
0 commit comments