diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-07 16:05:17 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2022-02-10 10:31:15 +0000 |
commit | 873803eca00830dc3ecb61e610d90710f64a8242 (patch) | |
tree | 31531d76a87c300577da83bdf86563b78a015fce /main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java | |
parent | ed116b0d61f3195a1b0ed9d38f23e494260977fd (diff) |
Move PAP database provider to spring boot default
This review makes PAP talk to DB directly using the spring repositories
instead of going to policy-models-provider.
The models-provider methods that were just used by PAP (and not used
anymore) will be removed in a different review.
Also a bug identified with the usage of GeneratedValue in
PfGeneratedIdKey (which is just used by PAP in statistics & audit) will
also be fixed in a separate review as part of POLICY-3897.
CSIT changes: https://gerrit.onap.org/r/c/policy/docker/+/127033
WIP OOM review: https://gerrit.onap.org/r/c/oom/+/127035
Change-Id: Idb13ba7eb2767cc718672b582a6518fcfc95320f
Issue-ID: POLICY-3867
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java')
-rw-r--r-- | main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java index 26e44d80..153a2bfa 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,13 +50,15 @@ import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; -import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; import org.onap.policy.pap.main.PapConstants; -import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper; import org.onap.policy.pap.main.comm.PdpModifyRequestMap; import org.onap.policy.pap.main.notification.PolicyNotifier; +import org.onap.policy.pap.main.service.PdpGroupService; +import org.onap.policy.pap.main.service.PolicyAuditService; +import org.onap.policy.pap.main.service.PolicyStatusService; +import org.onap.policy.pap.main.service.ToscaServiceTemplateService; /** * Super class for TestPdpGroupDeployProviderXxx classes. @@ -65,11 +68,19 @@ public class ProviderSuper { public static final String DEFAULT_USER = "PAP_TEST"; @Mock - protected PolicyModelsProvider dao; + protected PdpGroupService pdpGroupService; @Mock - protected PolicyNotifier notifier; + protected PolicyStatusService policyStatusService; + + @Mock + protected PolicyAuditService policyAuditService; + @Mock + protected ToscaServiceTemplateService toscaService; + + @Mock + protected PolicyNotifier notifier; /** * Used to capture input to dao.updatePdpGroups() and dao.createPdpGroups(). @@ -79,7 +90,6 @@ public class ProviderSuper { protected Object lockit; protected PdpModifyRequestMap reqmap; - protected PolicyModelsProviderFactoryWrapper daofact; protected ToscaPolicy policy1; protected PapStatisticsManager statsmanager; @@ -96,26 +106,35 @@ public class ProviderSuper { reqmap = mock(PdpModifyRequestMap.class); lockit = new Object(); - daofact = mock(PolicyModelsProviderFactoryWrapper.class); policy1 = loadPolicy("policy.json"); statsmanager = mock(PapStatisticsManager.class); - when(daofact.create()).thenReturn(dao); - List<PdpGroup> groups = loadGroups("groups.json"); - when(dao.getFilteredPdpGroups(any())).thenReturn(groups); + when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(groups); - when(dao.createPdpGroups(any())).thenAnswer(answer -> answer.getArgument(0, List.class)); - when(dao.updatePdpGroups(any())).thenAnswer(answer -> answer.getArgument(0, List.class)); + when(pdpGroupService.createPdpGroups(any())).thenAnswer(answer -> answer.getArgument(0, List.class)); + when(pdpGroupService.updatePdpGroups(any())).thenAnswer(answer -> answer.getArgument(0, List.class)); Registry.register(PapConstants.REG_PDP_MODIFY_LOCK, lockit); Registry.register(PapConstants.REG_PDP_MODIFY_MAP, reqmap); - Registry.register(PapConstants.REG_PAP_DAO_FACTORY, daofact); - Registry.register(PapConstants.REG_POLICY_NOTIFIER, notifier); Registry.register(PapConstants.REG_STATISTICS_MANAGER, statsmanager); } + /** + * Initialize services to the provider for tests. + * + * @param prov the provider + */ + public void initialize(ProviderBase prov) { + prov.setPdpGroupService(pdpGroupService); + prov.setPolicyAuditService(policyAuditService); + prov.setPolicyStatusService(policyStatusService); + prov.setToscaService(toscaService); + prov.setPolicyNotifier(notifier); + prov.initialize(); + } + protected void assertGroup(List<PdpGroup> groups, String name) { PdpGroup group = groups.remove(0); @@ -138,7 +157,7 @@ public class ProviderSuper { * @throws Exception if an error occurred */ protected List<PdpGroup> getGroupCreates() throws Exception { - verify(dao).createPdpGroups(updateCaptor.capture()); + verify(pdpGroupService).createPdpGroups(updateCaptor.capture()); return copyList(updateCaptor.getValue()); } @@ -150,7 +169,7 @@ public class ProviderSuper { * @throws Exception if an error occurred */ protected List<PdpGroup> getGroupUpdates() throws Exception { - verify(dao).updatePdpGroups(updateCaptor.capture()); + verify(pdpGroupService).updatePdpGroups(updateCaptor.capture()); return copyList(updateCaptor.getValue()); } |