Merge "Fix simple sonar issues in models-tosca"
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / persistence / provider / PdpProviderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.pdp.persistence.provider;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Properties;
32 import org.eclipse.persistence.config.PersistenceUnitProperties;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.common.utils.coder.StandardCoder;
37 import org.onap.policy.common.utils.resources.ResourceUtils;
38 import org.onap.policy.models.base.PfModelException;
39 import org.onap.policy.models.dao.DaoParameters;
40 import org.onap.policy.models.dao.PfDao;
41 import org.onap.policy.models.dao.PfDaoFactory;
42 import org.onap.policy.models.dao.impl.DefaultPfDao;
43 import org.onap.policy.models.pdp.concepts.Pdp;
44 import org.onap.policy.models.pdp.concepts.PdpGroup;
45 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
46 import org.onap.policy.models.pdp.concepts.PdpGroups;
47 import org.onap.policy.models.pdp.concepts.PdpStatistics;
48 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
49 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
50 import org.onap.policy.models.pdp.enums.PdpState;
51 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
52 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
53 import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
54
55 /**
56  * Test the {@link SimpleToscaProvider} class.
57  *
58  * @author Liam Fallon (liam.fallon@est.tech)
59  */
60 public class PdpProviderTest {
61     private PfDao pfDao;
62     private StandardCoder standardCoder;
63
64
65     /**
66      * Set up the DAO towards the database.
67      *
68      * @throws Exception on database errors
69      */
70     @Before
71     public void setupDao() throws Exception {
72         final DaoParameters daoParameters = new DaoParameters();
73         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
74
75         daoParameters.setPersistenceUnit("ToscaConceptTest");
76
77         Properties jdbcProperties = new Properties();
78         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy");
79         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY");
80
81         // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
82         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
83         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
84
85         daoParameters.setJdbcProperties(jdbcProperties );
86
87         pfDao = new PfDaoFactory().createPfDao(daoParameters);
88         pfDao.init(daoParameters);
89     }
90
91     /**
92      * Set up GSON.
93      */
94     @Before
95     public void setupGson() {
96         standardCoder = new StandardCoder();
97     }
98
99     @After
100     public void teardown() {
101         pfDao.close();
102     }
103
104     @Test
105     public void testGroupsGet() throws Exception {
106         assertThatThrownBy(() -> {
107             new PdpProvider().getPdpGroups(null, null);
108         }).hasMessage("dao is marked @NonNull but is null");
109
110         assertThatThrownBy(() -> {
111             new PdpProvider().getPdpGroups(null, "name");
112         }).hasMessage("dao is marked @NonNull but is null");
113
114         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
115         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
116
117         PdpGroups createdPdpGroups0 = new PdpGroups();
118         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
119         String createdJson = standardCoder.encode(createdPdpGroups0);
120         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
121
122         PdpGroups gotPdpGroups0 = new PdpGroups();
123         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
124
125         String gotJson = standardCoder.encode(gotPdpGroups0);
126
127         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
128     }
129
130     @Test
131     public void testFilteredPdpGroupGet() throws Exception {
132         assertThatThrownBy(() -> {
133             new PdpProvider().getFilteredPdpGroups(null, null);
134         }).hasMessage("dao is marked @NonNull but is null");
135
136         assertThatThrownBy(() -> {
137             new PdpProvider().getFilteredPdpGroups(null, PdpGroupFilter.builder().build());
138         }).hasMessage("dao is marked @NonNull but is null");
139
140         assertThatThrownBy(() -> {
141             new PdpProvider().getFilteredPdpGroups(pfDao, null);
142         }).hasMessage("filter is marked @NonNull but is null");
143
144         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsForFiltering.json");
145         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
146
147         assertEquals(5, new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()).size());
148
149         List<ToscaPolicyTypeIdentifier> policyTypeList = new ArrayList<>();
150         policyTypeList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
151
152         List<ToscaPolicyIdentifier> policyList = new ArrayList<>();
153         policyList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
154
155         // @formatter:off
156         final PdpGroupFilter filter = PdpGroupFilter.builder()
157                 .groupState(PdpState.PASSIVE)
158                 .name("PdpGroup0")
159                 .matchPoliciesExactly(false)
160                 .matchPolicyTypesExactly(false)
161                 .pdpState(PdpState.PASSIVE)
162                 .pdpType("APEX")
163                 .policyTypeList(policyTypeList)
164                 .policyList(policyList)
165                 .build();
166         // @formatter:on
167         assertEquals(1, new PdpProvider().getFilteredPdpGroups(pfDao, filter).size());
168     }
169
170     @Test
171     public void testGroupsCreate() throws Exception {
172         assertThatThrownBy(() -> {
173             new PdpProvider().createPdpGroups(null, null);
174         }).hasMessage("dao is marked @NonNull but is null");
175
176         assertThatThrownBy(() -> {
177             new PdpProvider().createPdpGroups(null, new ArrayList<>());
178         }).hasMessage("dao is marked @NonNull but is null");
179
180         assertThatThrownBy(() -> {
181             new PdpProvider().createPdpGroups(pfDao, null);
182         }).hasMessage("pdpGroups is marked @NonNull but is null");
183
184         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
185         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
186
187         PdpGroups createdPdpGroups0 = new PdpGroups();
188         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
189         String createdJson = standardCoder.encode(createdPdpGroups0);
190         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
191
192         PdpGroups gotPdpGroups0 = new PdpGroups();
193         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
194
195         String gotJson = standardCoder.encode(gotPdpGroups0);
196         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
197
198         pdpGroups0.getGroups().get(0).setPdpGroupState(null);
199         assertThatThrownBy(() -> {
200             new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups());
201         }).hasMessageContaining("INVALID:pdpGroupState may not be null");
202     }
203
204     @Test
205     public void testGroupsCreateNoPdp() throws Exception {
206         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsNoPDPs.json");
207
208         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
209
210         PdpGroups createdPdpGroups0 = new PdpGroups();
211         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
212         assertNotEquals(pdpGroups0, createdPdpGroups0);
213         pdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).setPdpInstances(new ArrayList<>());
214         String originalTweakedJson = standardCoder.encode(pdpGroups0);
215         String createdJson = standardCoder.encode(createdPdpGroups0);
216         assertEquals(originalTweakedJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
217
218         PdpGroups gotPdpGroups0 = new PdpGroups();
219         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "TestPdpGroup"));
220
221         String gotJson = standardCoder.encode(gotPdpGroups0);
222         assertEquals(originalTweakedJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
223     }
224
225     @Test
226     public void testGroupsUpdate() throws Exception {
227         assertThatThrownBy(() -> {
228             new PdpProvider().updatePdpGroups(null, null);
229         }).hasMessage("dao is marked @NonNull but is null");
230
231         assertThatThrownBy(() -> {
232             new PdpProvider().updatePdpGroups(null, new ArrayList<>());
233         }).hasMessage("dao is marked @NonNull but is null");
234
235         assertThatThrownBy(() -> {
236             new PdpProvider().updatePdpGroups(pfDao, null);
237         }).hasMessage("pdpGroups is marked @NonNull but is null");
238
239         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
240         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
241
242         PdpGroups createdPdpGroups0 = new PdpGroups();
243         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
244         String createdJson = standardCoder.encode(createdPdpGroups0);
245         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
246
247         PdpGroups gotPdpGroups0 = new PdpGroups();
248         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
249
250         String gotJson = standardCoder.encode(gotPdpGroups0);
251         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
252
253         String updateJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0Update.json");
254         PdpGroups updatePdpGroups0 = standardCoder.decode(updateJson, PdpGroups.class);
255
256         PdpGroups updatedPdpGroups0 = new PdpGroups();
257         updatedPdpGroups0.setGroups(new PdpProvider().updatePdpGroups(pfDao, updatePdpGroups0.getGroups()));
258
259         List<Pdp> beforePdpInstances = updatePdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
260         List<Pdp> afterPdpInstances = updatedPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
261         assertTrue(beforePdpInstances.containsAll(afterPdpInstances));
262
263         pdpGroups0.getGroups().get(0).setPdpGroupState(null);
264         assertThatThrownBy(() -> {
265             new PdpProvider().updatePdpGroups(pfDao, pdpGroups0.getGroups());
266         }).hasMessageContaining("INVALID:pdpGroupState may not be null");
267     }
268
269     @Test
270     public void testPoliciesDelete() throws Exception {
271         assertThatThrownBy(() -> {
272             new PdpProvider().deletePdpGroup(null, null);
273         }).hasMessage("dao is marked @NonNull but is null");
274
275         assertThatThrownBy(() -> {
276             new PdpProvider().deletePdpGroup(null, "name");
277         }).hasMessage("dao is marked @NonNull but is null");
278
279         assertThatThrownBy(() -> {
280             new PdpProvider().deletePdpGroup(pfDao, null);
281         }).hasMessage("name is marked @NonNull but is null");
282
283         assertThatThrownBy(() -> {
284             new PdpProvider().deletePdpGroup(pfDao, "name");
285         }).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
286
287         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
288         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
289
290         PdpGroups createdPdpGroups0 = new PdpGroups();
291         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
292         String createdJson = standardCoder.encode(createdPdpGroups0);
293         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
294
295         PdpGroups gotPdpGroups0 = new PdpGroups();
296         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
297
298         String gotJson = standardCoder.encode(gotPdpGroups0);
299         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
300
301         PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0");
302
303         assertEquals(createdPdpGroups0.getGroups().get(0), deletedPdpGroup);
304
305         assertEquals(0, new PdpProvider().getPdpGroups(pfDao, "PdpGroup0").size());
306
307         assertThatThrownBy(() -> {
308             new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0");
309         }).hasMessage("delete of PDP group \"PdpGroup0:0.0.0\" failed, PDP group does not exist");
310     }
311
312     @Test
313     public void testPdpSubgroupUpdate() throws Exception {
314         assertThatThrownBy(() -> {
315             new PdpProvider().updatePdpSubGroup(null, null, null);
316         }).hasMessage("dao is marked @NonNull but is null");
317
318         assertThatThrownBy(() -> {
319             new PdpProvider().updatePdpSubGroup(null, null, new PdpSubGroup());
320         }).hasMessage("dao is marked @NonNull but is null");
321
322         assertThatThrownBy(() -> {
323             new PdpProvider().updatePdpSubGroup(null, "name", null);
324         }).hasMessage("dao is marked @NonNull but is null");
325
326         assertThatThrownBy(() -> {
327             new PdpProvider().updatePdpSubGroup(null, "name", new PdpSubGroup());
328         }).hasMessage("dao is marked @NonNull but is null");
329
330         assertThatThrownBy(() -> {
331             new PdpProvider().updatePdpSubGroup(pfDao, null, null);
332         }).hasMessage("pdpGroupName is marked @NonNull but is null");
333
334         assertThatThrownBy(() -> {
335             new PdpProvider().updatePdpSubGroup(pfDao, null, new PdpSubGroup());
336         }).hasMessage("pdpGroupName is marked @NonNull but is null");
337
338         assertThatThrownBy(() -> {
339             new PdpProvider().updatePdpSubGroup(pfDao, "name", null);
340         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
341
342         assertThatThrownBy(() -> {
343             new PdpProvider().updatePdpSubGroup(pfDao, "name", new PdpSubGroup());
344         }).hasMessage("parameter \"localName\" is null");
345
346         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
347         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
348
349         PdpGroups createdPdpGroups0 = new PdpGroups();
350         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
351         String createdJson = standardCoder.encode(createdPdpGroups0);
352         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
353
354         PdpGroups gotPdpGroups0 = new PdpGroups();
355         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
356
357         String gotJson = standardCoder.encode(gotPdpGroups0);
358         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
359
360         PdpSubGroup existingSubGroup = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0);
361         existingSubGroup.setCurrentInstanceCount(10);
362         existingSubGroup.setDesiredInstanceCount(10);
363         new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", existingSubGroup);
364
365         List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0");
366         assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getCurrentInstanceCount());
367         assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
368
369         existingSubGroup.setDesiredInstanceCount(-1);
370         assertThatThrownBy(() -> {
371             new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", existingSubGroup);
372         }).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative");
373         existingSubGroup.setDesiredInstanceCount(10);
374     }
375
376     @Test
377     public void testPdpUpdate() throws Exception {
378         assertThatThrownBy(() -> {
379             new PdpProvider().updatePdp(null, null, null, null);
380         }).hasMessage("dao is marked @NonNull but is null");
381
382         assertThatThrownBy(() -> {
383             new PdpProvider().updatePdp(null, null, null, new Pdp());
384         }).hasMessage("dao is marked @NonNull but is null");
385
386         assertThatThrownBy(() -> {
387             new PdpProvider().updatePdp(null, null, "TYPE", null);
388         }).hasMessage("dao is marked @NonNull but is null");
389
390         assertThatThrownBy(() -> {
391             new PdpProvider().updatePdp(null, null, "TYPE", new Pdp());
392         }).hasMessage("dao is marked @NonNull but is null");
393
394         assertThatThrownBy(() -> {
395             new PdpProvider().updatePdp(null, "name", null, null);
396         }).hasMessage("dao is marked @NonNull but is null");
397
398         assertThatThrownBy(() -> {
399             new PdpProvider().updatePdp(null, "name", null, new Pdp());
400         }).hasMessage("dao is marked @NonNull but is null");
401
402         assertThatThrownBy(() -> {
403             new PdpProvider().updatePdp(null, "name", "TYPE", null);
404         }).hasMessage("dao is marked @NonNull but is null");
405
406         assertThatThrownBy(() -> {
407             new PdpProvider().updatePdp(null, "name", "TYPE", new Pdp());
408         }).hasMessage("dao is marked @NonNull but is null");
409
410         assertThatThrownBy(() -> {
411             new PdpProvider().updatePdp(pfDao, null, null, null);
412         }).hasMessage("pdpGroupName is marked @NonNull but is null");
413
414         assertThatThrownBy(() -> {
415             new PdpProvider().updatePdp(pfDao, null, null, new Pdp());
416         }).hasMessage("pdpGroupName is marked @NonNull but is null");
417
418         assertThatThrownBy(() -> {
419             new PdpProvider().updatePdp(pfDao, null, "TYPE", null);
420         }).hasMessage("pdpGroupName is marked @NonNull but is null");
421
422         assertThatThrownBy(() -> {
423             new PdpProvider().updatePdp(pfDao, null, "TYPE", new Pdp());
424         }).hasMessage("pdpGroupName is marked @NonNull but is null");
425
426         assertThatThrownBy(() -> {
427             new PdpProvider().updatePdp(pfDao, "name", null, null);
428         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
429
430         assertThatThrownBy(() -> {
431             new PdpProvider().updatePdp(pfDao, "name", null, new Pdp());
432         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
433
434         assertThatThrownBy(() -> {
435             new PdpProvider().updatePdp(pfDao, "name", "TYPE", null);
436         }).hasMessage("pdp is marked @NonNull but is null");
437
438         assertThatThrownBy(() -> {
439             new PdpProvider().updatePdp(pfDao, "name", "TYPE", new Pdp());
440         }).hasMessage("parameter \"localName\" is null");
441
442         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
443         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
444
445         PdpGroups createdPdpGroups0 = new PdpGroups();
446         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
447         String createdJson = standardCoder.encode(createdPdpGroups0);
448         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
449
450         PdpGroups gotPdpGroups0 = new PdpGroups();
451         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0"));
452
453         String gotJson = standardCoder.encode(gotPdpGroups0);
454         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
455
456         Pdp existingPdp = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances().get(0);
457         existingPdp.setPdpState(PdpState.TEST);
458         existingPdp.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
459         new PdpProvider().updatePdp(pfDao, "PdpGroup0", "APEX", existingPdp);
460
461         List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0");
462         assertEquals(PdpState.TEST,
463                 afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getPdpState());
464         assertEquals(PdpHealthStatus.TEST_IN_PROGRESS,
465                 afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getHealthy());
466
467         existingPdp.setMessage("");
468         assertThatThrownBy(() -> {
469             new PdpProvider().updatePdp(pfDao, "PdpGroup0", "APEX", existingPdp);
470         }).hasMessageContaining("INVALID:message may not be blank");
471         existingPdp.setMessage("A Message");
472     }
473
474     @Test
475     public void testGetPdpStatistics() throws PfModelException {
476         assertThatThrownBy(() -> {
477             new PdpProvider().getPdpStatistics(null, null);
478         }).hasMessage("dao is marked @NonNull but is null");
479
480         assertThatThrownBy(() -> {
481             new PdpProvider().getPdpStatistics(null, "name");
482         }).hasMessage("dao is marked @NonNull but is null");
483
484         assertEquals(0, new PdpProvider().getPdpStatistics(pfDao, "name").size());
485     }
486
487     @Test
488     public void testUpdatePdpStatistics() throws PfModelException {
489         assertThatThrownBy(() -> {
490             new PdpProvider().updatePdpStatistics(null, null, null, null, null);
491         }).hasMessage("dao is marked @NonNull but is null");
492
493         assertThatThrownBy(() -> {
494             new PdpProvider().updatePdpStatistics(null, null, null, null, new PdpStatistics());
495         }).hasMessage("dao is marked @NonNull but is null");
496
497         assertThatThrownBy(() -> {
498             new PdpProvider().updatePdpStatistics(null, null, null, "inst", null);
499         }).hasMessage("dao is marked @NonNull but is null");
500
501         assertThatThrownBy(() -> {
502             new PdpProvider().updatePdpStatistics(null, null, null, "inst", new PdpStatistics());
503         }).hasMessage("dao is marked @NonNull but is null");
504
505         assertThatThrownBy(() -> {
506             new PdpProvider().updatePdpStatistics(null, null, "TYPE", null, null);
507         }).hasMessage("dao is marked @NonNull but is null");
508
509         assertThatThrownBy(() -> {
510             new PdpProvider().updatePdpStatistics(null, null, "TYPE", null, new PdpStatistics());
511         }).hasMessage("dao is marked @NonNull but is null");
512
513         assertThatThrownBy(() -> {
514             new PdpProvider().updatePdpStatistics(null, null, "TYPE", "inst", null);
515         }).hasMessage("dao is marked @NonNull but is null");
516
517         assertThatThrownBy(() -> {
518             new PdpProvider().updatePdpStatistics(null, null, "TYPE", "inst", new PdpStatistics());
519         }).hasMessage("dao is marked @NonNull but is null");
520
521         assertThatThrownBy(() -> {
522             new PdpProvider().updatePdpStatistics(null, "name", null, null, null);
523         }).hasMessage("dao is marked @NonNull but is null");
524
525         assertThatThrownBy(() -> {
526             new PdpProvider().updatePdpStatistics(null, "name", null, null, new PdpStatistics());
527         }).hasMessage("dao is marked @NonNull but is null");
528
529         assertThatThrownBy(() -> {
530             new PdpProvider().updatePdpStatistics(null, "name", null, "inst", null);
531         }).hasMessage("dao is marked @NonNull but is null");
532
533         assertThatThrownBy(() -> {
534             new PdpProvider().updatePdpStatistics(null, "name", null, "inst", new PdpStatistics());
535         }).hasMessage("dao is marked @NonNull but is null");
536
537         assertThatThrownBy(() -> {
538             new PdpProvider().updatePdpStatistics(null, "name", "TYPE", null, null);
539         }).hasMessage("dao is marked @NonNull but is null");
540
541         assertThatThrownBy(() -> {
542             new PdpProvider().updatePdpStatistics(null, "name", "TYPE", null, new PdpStatistics());
543         }).hasMessage("dao is marked @NonNull but is null");
544
545         assertThatThrownBy(() -> {
546             new PdpProvider().updatePdpStatistics(null, "name", "TYPE", "inst", null);
547         }).hasMessage("dao is marked @NonNull but is null");
548
549         assertThatThrownBy(() -> {
550             new PdpProvider().updatePdpStatistics(null, "name", "TYPE", "inst", new PdpStatistics());
551         }).hasMessage("dao is marked @NonNull but is null");
552
553         assertThatThrownBy(() -> {
554             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null);
555         }).hasMessage("pdpGroupName is marked @NonNull but is null");
556
557         assertThatThrownBy(() -> {
558             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, new PdpStatistics());
559         }).hasMessage("pdpGroupName is marked @NonNull but is null");
560
561         assertThatThrownBy(() -> {
562             new PdpProvider().updatePdpStatistics(pfDao, null, null, "inst", null);
563         }).hasMessage("pdpGroupName is marked @NonNull but is null");
564
565         assertThatThrownBy(() -> {
566             new PdpProvider().updatePdpStatistics(pfDao, null, null, "inst", new PdpStatistics());
567         }).hasMessage("pdpGroupName is marked @NonNull but is null");
568
569         assertThatThrownBy(() -> {
570             new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", null, null);
571         }).hasMessage("pdpGroupName is marked @NonNull but is null");
572
573         assertThatThrownBy(() -> {
574             new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", null, new PdpStatistics());
575         }).hasMessage("pdpGroupName is marked @NonNull but is null");
576
577         assertThatThrownBy(() -> {
578             new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", "inst", null);
579         }).hasMessage("pdpGroupName is marked @NonNull but is null");
580
581         assertThatThrownBy(() -> {
582             new PdpProvider().updatePdpStatistics(pfDao, null, "TYPE", "inst", new PdpStatistics());
583         }).hasMessage("pdpGroupName is marked @NonNull but is null");
584
585         assertThatThrownBy(() -> {
586             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null);
587         }).hasMessage("pdpType is marked @NonNull but is null");
588
589         assertThatThrownBy(() -> {
590             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, new PdpStatistics());
591         }).hasMessage("pdpType is marked @NonNull but is null");
592
593         assertThatThrownBy(() -> {
594             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "inst", null);
595         }).hasMessage("pdpType is marked @NonNull but is null");
596
597         assertThatThrownBy(() -> {
598             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "inst", new PdpStatistics());
599         }).hasMessage("pdpType is marked @NonNull but is null");
600
601         assertThatThrownBy(() -> {
602             new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", null, null);
603         }).hasMessage("pdpInstanceId is marked @NonNull but is null");
604
605         assertThatThrownBy(() -> {
606             new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", null, new PdpStatistics());
607         }).hasMessage("pdpInstanceId is marked @NonNull but is null");
608
609         assertThatThrownBy(() -> {
610             new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", "inst", null);
611         }).hasMessage("pdpStatistics is marked @NonNull but is null");
612
613         new PdpProvider().updatePdpStatistics(pfDao, "name", "TYPE", "inst", new PdpStatistics());
614     }
615 }