2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.api.impl.subscriptions
23 import com.fasterxml.jackson.databind.ObjectMapper
24 import org.onap.cps.api.CpsDataService
25 import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent
26 import org.onap.cps.utils.JsonObjectMapper
27 import spock.lang.Specification
29 import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NO_TIMESTAMP
31 class SubscriptionPersistenceSpec extends Specification {
33 private static final String SUBSCRIPTION_DATASPACE_NAME = "NCMP-Admin";
34 private static final String SUBSCRIPTION_ANCHOR_NAME = "AVC-Subscriptions";
35 private static final String SUBSCRIPTION_REGISTRY_PARENT = "/subscription-registry";
37 def jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
39 def mockCpsDataService = Mock(CpsDataService)
41 def objectUnderTest = new SubscriptionPersistenceImpl(jsonObjectMapper, mockCpsDataService)
43 def 'save a subscription event' () {
44 given: 'a yang model subscription event'
45 def yangModelSubscriptionEvent = new YangModelSubscriptionEvent();
46 yangModelSubscriptionEvent.setClientId('some-client-id')
47 yangModelSubscriptionEvent.setSubscriptionName('some-subscription-name')
48 yangModelSubscriptionEvent.setTagged(true)
49 yangModelSubscriptionEvent.setTopic('some-topic')
50 def predicates = new YangModelSubscriptionEvent.Predicates(datastore: 'some-datastore',
51 targetCmHandles: [new YangModelSubscriptionEvent.TargetCmHandle('cmhandle1'), new YangModelSubscriptionEvent.TargetCmHandle('cmhandle2')])
52 yangModelSubscriptionEvent.setPredicates(predicates)
53 when: 'the yangModelSubscriptionEvent is saved'
54 objectUnderTest.saveSubscriptionEvent(yangModelSubscriptionEvent)
55 then: 'the cpsDataService is called with the correct data'
56 1 * mockCpsDataService.saveListElements(SUBSCRIPTION_DATASPACE_NAME, SUBSCRIPTION_ANCHOR_NAME,
57 SUBSCRIPTION_REGISTRY_PARENT,
58 '{"subscription":[{' +
59 '"topic":"some-topic",' +
60 '"predicates":{"datastore":"some-datastore","targetCmHandles":[{"cmHandleId":"cmhandle1","status":"PENDING"},{"cmHandleId":"cmhandle2","status":"PENDING"}]},' +
61 '"clientID":"some-client-id","subscriptionName":"some-subscription-name","isTagged":true}]}',