c06e16aa866595e48c247e306f89525128c1d832
[cps.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an 'AS IS' BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20 package org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp
21
22 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionPredicate
23 import org.onap.cps.ncmp.impl.cmnotificationsubscription.utils.CmDataJobSubscriptionPersistenceService
24 import spock.lang.Specification
25
26 import static org.onap.cps.ncmp.api.data.models.DatastoreType.PASSTHROUGH_OPERATIONAL
27
28 class CmSubscriptionComparatorSpec extends Specification {
29
30     def mockCmSubscriptionPersistenceService = Mock(CmDataJobSubscriptionPersistenceService)
31     def objectUnderTest = new CmSubscriptionComparator(mockCmSubscriptionPersistenceService)
32
33     def 'Find the difference based on the provided predicates'() {
34         given: 'A list of predicates'
35             def predicates = [new DmiCmSubscriptionPredicate(['ch-1', 'ch-2'].toSet(), PASSTHROUGH_OPERATIONAL, ['a/1/', 'b/2'].toSet())]
36         and: '1 positive and 1 negative response.'
37             mockCmSubscriptionPersistenceService.hasAtLeastOneSubscription(PASSTHROUGH_OPERATIONAL.getDatastoreName(), 'ch-1') >> true
38             mockCmSubscriptionPersistenceService.hasAtLeastOneSubscription(PASSTHROUGH_OPERATIONAL.getDatastoreName(), 'ch-2') >> false
39         when: 'method to extract only NEW predicates for dmi is called'
40             def result = objectUnderTest.getNewDmiSubscriptionPredicates(predicates)
41         then: 'from 2 predicates only 1 remains'
42             assert result.size() == 1
43             assert result[0].targetCmHandleIds[0] == 'ch-2'
44     }
45
46     def 'Find the difference based on the provided predicates when it is an ongoing Cm Subscription'() {
47         given: 'A list of predicates'
48             def predicates = [new DmiCmSubscriptionPredicate(['ch-1'].toSet(), PASSTHROUGH_OPERATIONAL, ['a/1/'].toSet())]
49         and: 'its already present'
50             mockCmSubscriptionPersistenceService.hasAtLeastOneSubscription(PASSTHROUGH_OPERATIONAL.getDatastoreName(), 'ch-1') >> true
51         when: 'method to extract only NEW predicates for dmi is called'
52             def result = objectUnderTest.getNewDmiSubscriptionPredicates(predicates)
53         then: 'from 1 predicate, none remains'
54             assert result.size() == 0
55     }
56
57 }