UNit test and minor fixes for DB pars
[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
33 import org.eclipse.persistence.config.PersistenceUnitProperties;
34 import org.junit.After;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.policy.common.utils.coder.StandardCoder;
38 import org.onap.policy.common.utils.resources.ResourceUtils;
39 import org.onap.policy.models.base.PfModelException;
40 import org.onap.policy.models.dao.DaoParameters;
41 import org.onap.policy.models.dao.PfDao;
42 import org.onap.policy.models.dao.PfDaoFactory;
43 import org.onap.policy.models.dao.impl.DefaultPfDao;
44 import org.onap.policy.models.pdp.concepts.Pdp;
45 import org.onap.policy.models.pdp.concepts.PdpGroup;
46 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
47 import org.onap.policy.models.pdp.concepts.PdpGroups;
48 import org.onap.policy.models.pdp.concepts.PdpStatistics;
49 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
50 import org.onap.policy.models.pdp.enums.PdpHealthStatus;
51 import org.onap.policy.models.pdp.enums.PdpState;
52 import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
53 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
54 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
55 import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
56
57 /**
58  * Test the {@link SimpleToscaProvider} class.
59  *
60  * @author Liam Fallon (liam.fallon@est.tech)
61  */
62 public class PdpProviderTest {
63     private PfDao pfDao;
64     private StandardCoder standardCoder;
65
66
67     /**
68      * Set up the DAO towards the database.
69      *
70      * @throws Exception on database errors
71      */
72     @Before
73     public void setupDao() throws Exception {
74         final DaoParameters daoParameters = new DaoParameters();
75         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
76
77         daoParameters.setPersistenceUnit("ToscaConceptTest");
78
79         Properties jdbcProperties = new Properties();
80         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER, "policy");
81         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, "P01icY");
82
83         // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
84         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
85         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
86
87         daoParameters.setJdbcProperties(jdbcProperties );
88
89         pfDao = new PfDaoFactory().createPfDao(daoParameters);
90         pfDao.init(daoParameters);
91     }
92
93     /**
94      * Set up GSON.
95      */
96     @Before
97     public void setupGson() {
98         standardCoder = new StandardCoder();
99     }
100
101     @After
102     public void teardown() throws Exception {
103         pfDao.close();
104     }
105
106     @Test
107     public void testGroupsGet() throws Exception {
108         assertThatThrownBy(() -> {
109             new PdpProvider().getPdpGroups(null, null, null);
110         }).hasMessage("dao is marked @NonNull but is null");
111
112         assertThatThrownBy(() -> {
113             new PdpProvider().getPdpGroups(null, null, "version");
114         }).hasMessage("dao is marked @NonNull but is null");
115
116         assertThatThrownBy(() -> {
117             new PdpProvider().getPdpGroups(null, "name", "version");
118         }).hasMessage("dao is marked @NonNull but is null");
119
120         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
121         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
122
123         PdpGroups createdPdpGroups0 = new PdpGroups();
124         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
125         String createdJson = standardCoder.encode(createdPdpGroups0);
126         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
127
128         PdpGroups gotPdpGroups0 = new PdpGroups();
129         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
130
131         String gotJson = standardCoder.encode(gotPdpGroups0);
132
133         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
134     }
135
136     @Test
137     public void testFilteredPdpGroupGet() throws Exception {
138         assertThatThrownBy(() -> {
139             new PdpProvider().getFilteredPdpGroups(null, null);
140         }).hasMessage("dao is marked @NonNull but is null");
141
142         assertThatThrownBy(() -> {
143             new PdpProvider().getFilteredPdpGroups(null, PdpGroupFilter.builder().build());
144         }).hasMessage("dao is marked @NonNull but is null");
145
146         assertThatThrownBy(() -> {
147             new PdpProvider().getFilteredPdpGroups(pfDao, null);
148         }).hasMessage("filter is marked @NonNull but is null");
149
150         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsForFiltering.json");
151         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
152
153         assertEquals(5, new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()).size());
154
155         List<ToscaPolicyTypeIdentifier> policyTypeList = new ArrayList<>();
156         policyTypeList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
157
158         List<ToscaPolicyIdentifier> policyList = new ArrayList<>();
159         policyList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
160
161         // @formatter:off
162         final PdpGroupFilter filter = PdpGroupFilter.builder()
163                 .groupState(PdpState.PASSIVE)
164                 .name("PdpGroup0")
165                 .version("1.2.3")
166                 .matchPoliciesExactly(false)
167                 .matchPolicyTypesExactly(false)
168                 .pdpState(PdpState.PASSIVE)
169                 .pdpType("APEX")
170                 .policyTypeList(policyTypeList)
171                 .policyList(policyList)
172                 .build();
173         // @formatter:on
174         assertEquals(1, new PdpProvider().getFilteredPdpGroups(pfDao, filter).size());
175     }
176
177     @Test
178     public void testGroupsCreate() throws Exception {
179         assertThatThrownBy(() -> {
180             new PdpProvider().createPdpGroups(null, null);
181         }).hasMessage("dao is marked @NonNull but is null");
182
183         assertThatThrownBy(() -> {
184             new PdpProvider().createPdpGroups(null, new ArrayList<>());
185         }).hasMessage("dao is marked @NonNull but is null");
186
187         assertThatThrownBy(() -> {
188             new PdpProvider().createPdpGroups(pfDao, null);
189         }).hasMessage("pdpGroups is marked @NonNull but is null");
190
191         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
192         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
193
194         PdpGroups createdPdpGroups0 = new PdpGroups();
195         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
196         String createdJson = standardCoder.encode(createdPdpGroups0);
197         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
198
199         PdpGroups gotPdpGroups0 = new PdpGroups();
200         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
201
202         String gotJson = standardCoder.encode(gotPdpGroups0);
203         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
204
205         pdpGroups0.getGroups().get(0).setPdpGroupState(null);
206         assertThatThrownBy(() -> {
207             new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups());
208         }).hasMessageContaining("INVALID:pdpGroupState may not be null");
209     }
210
211     @Test
212     public void testGroupsCreateNoPdp() throws Exception {
213         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsNoPDPs.json");
214
215         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
216
217         PdpGroups createdPdpGroups0 = new PdpGroups();
218         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
219         assertNotEquals(pdpGroups0, createdPdpGroups0);
220         pdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).setPdpInstances(new ArrayList<>());
221         String originalTweakedJson = standardCoder.encode(pdpGroups0);
222         String createdJson = standardCoder.encode(createdPdpGroups0);
223         assertEquals(originalTweakedJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
224
225         PdpGroups gotPdpGroups0 = new PdpGroups();
226         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "TestPdpGroup", "1.2.3"));
227
228         String gotJson = standardCoder.encode(gotPdpGroups0);
229         assertEquals(originalTweakedJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
230     }
231
232     @Test
233     public void testGroupsUpdate() throws Exception {
234         assertThatThrownBy(() -> {
235             new PdpProvider().updatePdpGroups(null, null);
236         }).hasMessage("dao is marked @NonNull but is null");
237
238         assertThatThrownBy(() -> {
239             new PdpProvider().updatePdpGroups(null, new ArrayList<>());
240         }).hasMessage("dao is marked @NonNull but is null");
241
242         assertThatThrownBy(() -> {
243             new PdpProvider().updatePdpGroups(pfDao, null);
244         }).hasMessage("pdpGroups is marked @NonNull but is null");
245
246         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
247         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
248
249         PdpGroups createdPdpGroups0 = new PdpGroups();
250         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
251         String createdJson = standardCoder.encode(createdPdpGroups0);
252         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
253
254         PdpGroups gotPdpGroups0 = new PdpGroups();
255         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
256
257         String gotJson = standardCoder.encode(gotPdpGroups0);
258         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
259
260         String updateJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0Update.json");
261         PdpGroups updatePdpGroups0 = standardCoder.decode(updateJson, PdpGroups.class);
262
263         PdpGroups updatedPdpGroups0 = new PdpGroups();
264         updatedPdpGroups0.setGroups(new PdpProvider().updatePdpGroups(pfDao, updatePdpGroups0.getGroups()));
265
266         List<Pdp> beforePdpInstances = updatePdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
267         List<Pdp> afterPdpInstances = updatedPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
268         assertTrue(beforePdpInstances.containsAll(afterPdpInstances));
269
270         pdpGroups0.getGroups().get(0).setPdpGroupState(null);
271         assertThatThrownBy(() -> {
272             new PdpProvider().updatePdpGroups(pfDao, pdpGroups0.getGroups());
273         }).hasMessageContaining("INVALID:pdpGroupState may not be null");
274     }
275
276     @Test
277     public void testPoliciesDelete() throws Exception {
278         assertThatThrownBy(() -> {
279             new PdpProvider().deletePdpGroup(null, null, null);
280         }).hasMessage("dao is marked @NonNull but is null");
281
282         assertThatThrownBy(() -> {
283             new PdpProvider().deletePdpGroup(null, null, "version");
284         }).hasMessage("dao is marked @NonNull but is null");
285
286         assertThatThrownBy(() -> {
287             new PdpProvider().deletePdpGroup(null, "name", null);
288         }).hasMessage("dao is marked @NonNull but is null");
289
290         assertThatThrownBy(() -> {
291             new PdpProvider().deletePdpGroup(null, "name", "version");
292         }).hasMessage("dao is marked @NonNull but is null");
293
294         assertThatThrownBy(() -> {
295             new PdpProvider().deletePdpGroup(pfDao, null, "version");
296         }).hasMessage("name is marked @NonNull but is null");
297
298         assertThatThrownBy(() -> {
299             new PdpProvider().deletePdpGroup(pfDao, "name", null);
300         }).hasMessage("version is marked @NonNull but is null");
301
302         assertThatThrownBy(() -> {
303             new PdpProvider().deletePdpGroup(pfDao, "name", "version");
304         }).hasMessage("delete of PDP group \"name:version\" failed, PDP group does not exist");
305
306         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
307         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
308
309         PdpGroups createdPdpGroups0 = new PdpGroups();
310         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
311         String createdJson = standardCoder.encode(createdPdpGroups0);
312         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
313
314         PdpGroups gotPdpGroups0 = new PdpGroups();
315         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
316
317         String gotJson = standardCoder.encode(gotPdpGroups0);
318         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
319
320         PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3");
321
322         assertEquals(createdPdpGroups0.getGroups().get(0), deletedPdpGroup);
323
324         assertEquals(0, new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3").size());
325
326         assertThatThrownBy(() -> {
327             new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3");
328         }).hasMessage("delete of PDP group \"PdpGroup0:1.2.3\" failed, PDP group does not exist");
329     }
330
331     @Test
332     public void testPdpSubgroupUpdate() throws Exception {
333         assertThatThrownBy(() -> {
334             new PdpProvider().updatePdpSubGroup(null, null, null, null);
335         }).hasMessage("dao is marked @NonNull but is null");
336
337         assertThatThrownBy(() -> {
338             new PdpProvider().updatePdpSubGroup(null, null, null, new PdpSubGroup());
339         }).hasMessage("dao is marked @NonNull but is null");
340
341         assertThatThrownBy(() -> {
342             new PdpProvider().updatePdpSubGroup(null, null, "version", null);
343         }).hasMessage("dao is marked @NonNull but is null");
344
345         assertThatThrownBy(() -> {
346             new PdpProvider().updatePdpSubGroup(null, null, "version", new PdpSubGroup());
347         }).hasMessage("dao is marked @NonNull but is null");
348
349         assertThatThrownBy(() -> {
350             new PdpProvider().updatePdpSubGroup(null, "name", null, null);
351         }).hasMessage("dao is marked @NonNull but is null");
352
353         assertThatThrownBy(() -> {
354             new PdpProvider().updatePdpSubGroup(null, "name", null, new PdpSubGroup());
355         }).hasMessage("dao is marked @NonNull but is null");
356
357         assertThatThrownBy(() -> {
358             new PdpProvider().updatePdpSubGroup(null, "name", "version", null);
359         }).hasMessage("dao is marked @NonNull but is null");
360
361         assertThatThrownBy(() -> {
362             new PdpProvider().updatePdpSubGroup(null, "name", "version", new PdpSubGroup());
363         }).hasMessage("dao is marked @NonNull but is null");
364
365         assertThatThrownBy(() -> {
366             new PdpProvider().updatePdpSubGroup(pfDao, null, null, new PdpSubGroup());
367         }).hasMessage("pdpGroupName is marked @NonNull but is null");
368
369         assertThatThrownBy(() -> {
370             new PdpProvider().updatePdpSubGroup(pfDao, null, "version", null);
371         }).hasMessage("pdpGroupName is marked @NonNull but is null");
372
373         assertThatThrownBy(() -> {
374             new PdpProvider().updatePdpSubGroup(pfDao, null, "version", new PdpSubGroup());
375         }).hasMessage("pdpGroupName is marked @NonNull but is null");
376
377         assertThatThrownBy(() -> {
378             new PdpProvider().updatePdpSubGroup(pfDao, "name", null, null);
379         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
380
381         assertThatThrownBy(() -> {
382             new PdpProvider().updatePdpSubGroup(pfDao, "name", null, new PdpSubGroup());
383         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
384
385         assertThatThrownBy(() -> {
386             new PdpProvider().updatePdpSubGroup(pfDao, "name", "version", null);
387         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
388
389         assertThatThrownBy(() -> {
390             new PdpProvider().updatePdpSubGroup(pfDao, "name", "version", new PdpSubGroup());
391         }).hasMessage("parameter \"localName\" is null");
392
393         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
394         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
395
396         PdpGroups createdPdpGroups0 = new PdpGroups();
397         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
398         String createdJson = standardCoder.encode(createdPdpGroups0);
399         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
400
401         PdpGroups gotPdpGroups0 = new PdpGroups();
402         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
403
404         String gotJson = standardCoder.encode(gotPdpGroups0);
405         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
406
407         PdpSubGroup existingSubGroup = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0);
408         existingSubGroup.setCurrentInstanceCount(10);
409         existingSubGroup.setDesiredInstanceCount(10);
410         new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup);
411
412         List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3");
413         assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getCurrentInstanceCount());
414         assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
415
416         existingSubGroup.setDesiredInstanceCount(-1);
417         assertThatThrownBy(() -> {
418             new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup);
419         }).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative");
420         existingSubGroup.setDesiredInstanceCount(10);
421     }
422
423     @Test
424     public void testPdpUpdate() throws Exception {
425         assertThatThrownBy(() -> {
426             new PdpProvider().updatePdp(null, null, null, null, null);
427         }).hasMessage("dao is marked @NonNull but is null");
428
429         assertThatThrownBy(() -> {
430             new PdpProvider().updatePdp(null, null, null, null, new Pdp());
431         }).hasMessage("dao is marked @NonNull but is null");
432
433         assertThatThrownBy(() -> {
434             new PdpProvider().updatePdp(null, null, null, "TYPE", null);
435         }).hasMessage("dao is marked @NonNull but is null");
436
437         assertThatThrownBy(() -> {
438             new PdpProvider().updatePdp(null, null, null, "TYPE", new Pdp());
439         }).hasMessage("dao is marked @NonNull but is null");
440
441         assertThatThrownBy(() -> {
442             new PdpProvider().updatePdp(null, null, "version", null, null);
443         }).hasMessage("dao is marked @NonNull but is null");
444
445         assertThatThrownBy(() -> {
446             new PdpProvider().updatePdp(null, null, "version", null, new Pdp());
447         }).hasMessage("dao is marked @NonNull but is null");
448
449         assertThatThrownBy(() -> {
450             new PdpProvider().updatePdp(null, null, "version", "TYPE", null);
451         }).hasMessage("dao is marked @NonNull but is null");
452
453         assertThatThrownBy(() -> {
454             new PdpProvider().updatePdp(null, null, "version", "TYPE", new Pdp());
455         }).hasMessage("dao is marked @NonNull but is null");
456
457         assertThatThrownBy(() -> {
458             new PdpProvider().updatePdp(null, "name", null, null, null);
459         }).hasMessage("dao is marked @NonNull but is null");
460
461         assertThatThrownBy(() -> {
462             new PdpProvider().updatePdp(null, "name", null, null, new Pdp());
463         }).hasMessage("dao is marked @NonNull but is null");
464
465         assertThatThrownBy(() -> {
466             new PdpProvider().updatePdp(null, "name", null, "TYPE", null);
467         }).hasMessage("dao is marked @NonNull but is null");
468
469         assertThatThrownBy(() -> {
470             new PdpProvider().updatePdp(null, "name", null, "TYPE", new Pdp());
471         }).hasMessage("dao is marked @NonNull but is null");
472
473         assertThatThrownBy(() -> {
474             new PdpProvider().updatePdp(null, "name", "version", null, null);
475         }).hasMessage("dao is marked @NonNull but is null");
476
477         assertThatThrownBy(() -> {
478             new PdpProvider().updatePdp(null, "name", "version", null, new Pdp());
479         }).hasMessage("dao is marked @NonNull but is null");
480
481         assertThatThrownBy(() -> {
482             new PdpProvider().updatePdp(null, "name", "version", "TYPE", null);
483         }).hasMessage("dao is marked @NonNull but is null");
484
485         assertThatThrownBy(() -> {
486             new PdpProvider().updatePdp(null, "name", "version", "TYPE", new Pdp());
487         }).hasMessage("dao is marked @NonNull but is null");
488
489         assertThatThrownBy(() -> {
490             new PdpProvider().updatePdp(pfDao, null, null, null, null);
491         }).hasMessage("pdpGroupName is marked @NonNull but is null");
492
493         assertThatThrownBy(() -> {
494             new PdpProvider().updatePdp(pfDao, null, null, null, new Pdp());
495         }).hasMessage("pdpGroupName is marked @NonNull but is null");
496
497         assertThatThrownBy(() -> {
498             new PdpProvider().updatePdp(pfDao, null, null, "TYPE", null);
499         }).hasMessage("pdpGroupName is marked @NonNull but is null");
500
501         assertThatThrownBy(() -> {
502             new PdpProvider().updatePdp(pfDao, null, null, "TYPE", new Pdp());
503         }).hasMessage("pdpGroupName is marked @NonNull but is null");
504
505         assertThatThrownBy(() -> {
506             new PdpProvider().updatePdp(pfDao, null, "version", null, null);
507         }).hasMessage("pdpGroupName is marked @NonNull but is null");
508
509         assertThatThrownBy(() -> {
510             new PdpProvider().updatePdp(pfDao, null, "version", null, new Pdp());
511         }).hasMessage("pdpGroupName is marked @NonNull but is null");
512
513         assertThatThrownBy(() -> {
514             new PdpProvider().updatePdp(pfDao, null, "version", "TYPE", null);
515         }).hasMessage("pdpGroupName is marked @NonNull but is null");
516
517         assertThatThrownBy(() -> {
518             new PdpProvider().updatePdp(pfDao, null, "version", "TYPE", new Pdp());
519         }).hasMessage("pdpGroupName is marked @NonNull but is null");
520
521         assertThatThrownBy(() -> {
522             new PdpProvider().updatePdp(pfDao, "name", null, null, null);
523         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
524
525         assertThatThrownBy(() -> {
526             new PdpProvider().updatePdp(pfDao, "name", null, null, new Pdp());
527         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
528
529         assertThatThrownBy(() -> {
530             new PdpProvider().updatePdp(pfDao, "name", null, "TYPE", null);
531         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
532
533         assertThatThrownBy(() -> {
534             new PdpProvider().updatePdp(pfDao, "name", null, "TYPE", new Pdp());
535         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
536
537         assertThatThrownBy(() -> {
538             new PdpProvider().updatePdp(pfDao, "name", "version", null, null);
539         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
540
541         assertThatThrownBy(() -> {
542             new PdpProvider().updatePdp(pfDao, "name", "version", null, new Pdp());
543         }).hasMessage("pdpSubGroup is marked @NonNull but is null");
544
545         assertThatThrownBy(() -> {
546             new PdpProvider().updatePdp(pfDao, "name", "version", "TYPE", null);
547         }).hasMessage("pdp is marked @NonNull but is null");
548
549         assertThatThrownBy(() -> {
550             new PdpProvider().updatePdp(pfDao, "name", "version", "TYPE", new Pdp());
551         }).hasMessage("parameter \"localName\" is null");
552
553         String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
554         PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
555
556         PdpGroups createdPdpGroups0 = new PdpGroups();
557         createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
558         String createdJson = standardCoder.encode(createdPdpGroups0);
559         assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
560
561         PdpGroups gotPdpGroups0 = new PdpGroups();
562         gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
563
564         String gotJson = standardCoder.encode(gotPdpGroups0);
565         assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
566
567         Pdp existingPdp = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances().get(0);
568         existingPdp.setPdpState(PdpState.TEST);
569         existingPdp.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS);
570         new PdpProvider().updatePdp(pfDao, "PdpGroup0", "1.2.3", "APEX", existingPdp);
571
572         List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3");
573         assertEquals(PdpState.TEST,
574                 afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getPdpState());
575         assertEquals(PdpHealthStatus.TEST_IN_PROGRESS,
576                 afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getHealthy());
577
578         existingPdp.setMessage("");
579         assertThatThrownBy(() -> {
580             new PdpProvider().updatePdp(pfDao, "PdpGroup0", "1.2.3", "APEX", existingPdp);
581         }).hasMessageContaining("INVALID:message may not be blank");
582         existingPdp.setMessage("A Message");
583     }
584
585     @Test
586     public void testGetPdpStatistics() throws PfModelException {
587         assertThatThrownBy(() -> {
588             new PdpProvider().getPdpStatistics(null, null, null);
589         }).hasMessage("dao is marked @NonNull but is null");
590
591         assertThatThrownBy(() -> {
592             new PdpProvider().getPdpStatistics(null, null, "version");
593         }).hasMessage("dao is marked @NonNull but is null");
594
595         assertThatThrownBy(() -> {
596             new PdpProvider().getPdpStatistics(null, "name", null);
597         }).hasMessage("dao is marked @NonNull but is null");
598
599         assertEquals(0, new PdpProvider().getPdpStatistics(pfDao, "name", "version").size());
600     }
601
602     @Test
603     public void testUpdatePdpStatistics() throws PfModelException {
604         assertThatThrownBy(() -> {
605             new PdpProvider().updatePdpStatistics(null, null, null, null, null, null);
606         }).hasMessage("dao is marked @NonNull but is null");
607
608         assertThatThrownBy(() -> {
609             new PdpProvider().updatePdpStatistics(null, null, null, null, null, new PdpStatistics());
610         }).hasMessage("dao is marked @NonNull but is null");
611
612         assertThatThrownBy(() -> {
613             new PdpProvider().updatePdpStatistics(null, null, null, null, "inst", null);
614         }).hasMessage("dao is marked @NonNull but is null");
615
616         assertThatThrownBy(() -> {
617             new PdpProvider().updatePdpStatistics(null, null, null, null, "inst", new PdpStatistics());
618         }).hasMessage("dao is marked @NonNull but is null");
619
620         assertThatThrownBy(() -> {
621             new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", null, null);
622         }).hasMessage("dao is marked @NonNull but is null");
623
624         assertThatThrownBy(() -> {
625             new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", null, new PdpStatistics());
626         }).hasMessage("dao is marked @NonNull but is null");
627
628         assertThatThrownBy(() -> {
629             new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", "inst", null);
630         }).hasMessage("dao is marked @NonNull but is null");
631
632         assertThatThrownBy(() -> {
633             new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", "inst", new PdpStatistics());
634         }).hasMessage("dao is marked @NonNull but is null");
635
636         assertThatThrownBy(() -> {
637             new PdpProvider().updatePdpStatistics(null, null, "version", null, null, null);
638         }).hasMessage("dao is marked @NonNull but is null");
639
640         assertThatThrownBy(() -> {
641             new PdpProvider().updatePdpStatistics(null, null, "version", null, null, new PdpStatistics());
642         }).hasMessage("dao is marked @NonNull but is null");
643
644         assertThatThrownBy(() -> {
645             new PdpProvider().updatePdpStatistics(null, null, "version", null, "inst", null);
646         }).hasMessage("dao is marked @NonNull but is null");
647
648         assertThatThrownBy(() -> {
649             new PdpProvider().updatePdpStatistics(null, null, "version",  null, "inst", new PdpStatistics());
650         }).hasMessage("dao is marked @NonNull but is null");
651
652         assertThatThrownBy(() -> {
653             new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", null, null);
654         }).hasMessage("dao is marked @NonNull but is null");
655
656         assertThatThrownBy(() -> {
657             new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", null, new PdpStatistics());
658         }).hasMessage("dao is marked @NonNull but is null");
659
660         assertThatThrownBy(() -> {
661             new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", "inst", null);
662         }).hasMessage("dao is marked @NonNull but is null");
663
664         assertThatThrownBy(() -> {
665             new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", "inst", new PdpStatistics());
666         }).hasMessage("dao is marked @NonNull but is null");
667
668         assertThatThrownBy(() -> {
669             new PdpProvider().updatePdpStatistics(null, "name", null, null, null, null);
670         }).hasMessage("dao is marked @NonNull but is null");
671
672         assertThatThrownBy(() -> {
673             new PdpProvider().updatePdpStatistics(null, "name", null, null, null, new PdpStatistics());
674         }).hasMessage("dao is marked @NonNull but is null");
675
676         assertThatThrownBy(() -> {
677             new PdpProvider().updatePdpStatistics(null, "name", null, null, "inst", null);
678         }).hasMessage("dao is marked @NonNull but is null");
679
680         assertThatThrownBy(() -> {
681             new PdpProvider().updatePdpStatistics(null, "name", null, null, "inst", new PdpStatistics());
682         }).hasMessage("dao is marked @NonNull but is null");
683
684         assertThatThrownBy(() -> {
685             new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", null, null);
686         }).hasMessage("dao is marked @NonNull but is null");
687
688         assertThatThrownBy(() -> {
689             new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", null, new PdpStatistics());
690         }).hasMessage("dao is marked @NonNull but is null");
691
692         assertThatThrownBy(() -> {
693             new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", "inst", null);
694         }).hasMessage("dao is marked @NonNull but is null");
695
696         assertThatThrownBy(() -> {
697             new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", "inst", new PdpStatistics());
698         }).hasMessage("dao is marked @NonNull but is null");
699
700         assertThatThrownBy(() -> {
701             new PdpProvider().updatePdpStatistics(null, "name", "version", null, null, null);
702         }).hasMessage("dao is marked @NonNull but is null");
703
704         assertThatThrownBy(() -> {
705             new PdpProvider().updatePdpStatistics(null, "name", "version", null, null, new PdpStatistics());
706         }).hasMessage("dao is marked @NonNull but is null");
707
708         assertThatThrownBy(() -> {
709             new PdpProvider().updatePdpStatistics(null, "name", "version", null, "inst", null);
710         }).hasMessage("dao is marked @NonNull but is null");
711
712         assertThatThrownBy(() -> {
713             new PdpProvider().updatePdpStatistics(null, "name", "version", null, "inst", new PdpStatistics());
714         }).hasMessage("dao is marked @NonNull but is null");
715
716         assertThatThrownBy(() -> {
717             new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", null, null);
718         }).hasMessage("dao is marked @NonNull but is null");
719
720         assertThatThrownBy(() -> {
721             new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", null, new PdpStatistics());
722         }).hasMessage("dao is marked @NonNull but is null");
723
724         assertThatThrownBy(() -> {
725             new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", "inst", null);
726         }).hasMessage("dao is marked @NonNull but is null");
727
728         assertThatThrownBy(() -> {
729             new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", "inst", new PdpStatistics());
730         }).hasMessage("dao is marked @NonNull but is null");
731
732         assertThatThrownBy(() -> {
733             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null, null);
734         }).hasMessage("pdpGroupName is marked @NonNull but is null");
735
736         assertThatThrownBy(() -> {
737             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null, new PdpStatistics());
738         }).hasMessage("pdpGroupName is marked @NonNull but is null");
739
740         assertThatThrownBy(() -> {
741             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, "inst", null);
742         }).hasMessage("pdpGroupName is marked @NonNull but is null");
743
744         assertThatThrownBy(() -> {
745             new PdpProvider().updatePdpStatistics(pfDao, null, null, null, "inst", new PdpStatistics());
746         }).hasMessage("pdpGroupName is marked @NonNull but is null");
747
748         assertThatThrownBy(() -> {
749             new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", null, null);
750         }).hasMessage("pdpGroupName is marked @NonNull but is null");
751
752         assertThatThrownBy(() -> {
753             new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", null, new PdpStatistics());
754         }).hasMessage("pdpGroupName is marked @NonNull but is null");
755
756         assertThatThrownBy(() -> {
757             new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", "inst", null);
758         }).hasMessage("pdpGroupName is marked @NonNull but is null");
759
760         assertThatThrownBy(() -> {
761             new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", "inst", new PdpStatistics());
762         }).hasMessage("pdpGroupName is marked @NonNull but is null");
763
764         assertThatThrownBy(() -> {
765             new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, null, null);
766         }).hasMessage("pdpGroupName is marked @NonNull but is null");
767
768         assertThatThrownBy(() -> {
769             new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, null, new PdpStatistics());
770         }).hasMessage("pdpGroupName is marked @NonNull but is null");
771
772         assertThatThrownBy(() -> {
773             new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, "inst", null);
774         }).hasMessage("pdpGroupName is marked @NonNull but is null");
775
776         assertThatThrownBy(() -> {
777             new PdpProvider().updatePdpStatistics(pfDao, null, "version",  null, "inst", new PdpStatistics());
778         }).hasMessage("pdpGroupName is marked @NonNull but is null");
779
780         assertThatThrownBy(() -> {
781             new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", null, null);
782         }).hasMessage("pdpGroupName is marked @NonNull but is null");
783
784         assertThatThrownBy(() -> {
785             new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", null, new PdpStatistics());
786         }).hasMessage("pdpGroupName is marked @NonNull but is null");
787
788         assertThatThrownBy(() -> {
789             new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", "inst", null);
790         }).hasMessage("pdpGroupName is marked @NonNull but is null");
791
792         assertThatThrownBy(() -> {
793             new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", "inst", new PdpStatistics());
794         }).hasMessage("pdpGroupName is marked @NonNull but is null");
795
796         assertThatThrownBy(() -> {
797             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null, null);
798         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
799
800         assertThatThrownBy(() -> {
801             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null, new PdpStatistics());
802         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
803
804         assertThatThrownBy(() -> {
805             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, "inst", null);
806         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
807
808         assertThatThrownBy(() -> {
809             new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, "inst", new PdpStatistics());
810         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
811
812         assertThatThrownBy(() -> {
813             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", null, null);
814         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
815
816         assertThatThrownBy(() -> {
817             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", null, new PdpStatistics());
818         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
819
820         assertThatThrownBy(() -> {
821             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", "inst", null);
822         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
823
824         assertThatThrownBy(() -> {
825             new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", "inst", new PdpStatistics());
826         }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
827
828         assertThatThrownBy(() -> {
829             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, null, null);
830         }).hasMessage("pdpType is marked @NonNull but is null");
831
832         assertThatThrownBy(() -> {
833             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, null, new PdpStatistics());
834         }).hasMessage("pdpType is marked @NonNull but is null");
835
836         assertThatThrownBy(() -> {
837             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, "inst", null);
838         }).hasMessage("pdpType is marked @NonNull but is null");
839
840         assertThatThrownBy(() -> {
841             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, "inst", new PdpStatistics());
842         }).hasMessage("pdpType is marked @NonNull but is null");
843
844         assertThatThrownBy(() -> {
845             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", null, null);
846         }).hasMessage("pdpInstanceId is marked @NonNull but is null");
847
848         assertThatThrownBy(() -> {
849             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", null, new PdpStatistics());
850         }).hasMessage("pdpInstanceId is marked @NonNull but is null");
851
852         assertThatThrownBy(() -> {
853             new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", "inst", null);
854         }).hasMessage("pdpStatistics is marked @NonNull but is null");
855
856         new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", "inst", new PdpStatistics());
857     }
858 }