Replace deprecated WebSecurityConfigurerAdapter
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / SessionManagerIntegrationSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2022-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
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
21 package org.onap.cps.integration.functional
22
23 import org.onap.cps.integration.base.FunctionalSpecBase
24 import org.onap.cps.spi.exceptions.SessionManagerException
25 import org.onap.cps.spi.utils.SessionManager
26
27 class SessionManagerIntegrationSpec extends FunctionalSpecBase {
28
29     SessionManager objectUnderTest
30
31     def shortTimeoutForTesting = 300L
32     def sessionId
33
34     def setup() {
35         objectUnderTest = sessionManager
36         sessionId = objectUnderTest.startSession()
37     }
38
39     def cleanup(){
40         objectUnderTest.closeSession(sessionId, objectUnderTest.WITH_COMMIT)
41     }
42
43     def 'Lock anchor.'(){
44         when: 'session tries to acquire anchor lock by passing anchor entity details'
45             objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
46         then: 'no exception is thrown'
47             noExceptionThrown()
48     }
49
50     def 'Attempt to lock anchor when another session is holding the lock.'(){
51         given: 'another session that holds an anchor lock'
52             def otherSessionId = objectUnderTest.startSession()
53             objectUnderTest.lockAnchor(otherSessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
54         when: 'a session tries to acquire the same anchor lock'
55             objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
56         then: 'a session manager exception is thrown specifying operation reached timeout'
57             def thrown = thrown(SessionManagerException)
58             thrown.message.contains('Timeout')
59         then: 'when the other session holding the lock is closed, lock can finally be acquired'
60             objectUnderTest.closeSession(otherSessionId, objectUnderTest.WITH_COMMIT)
61             objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting)
62     }
63
64     def 'Lock anchor twice using the same session.'(){
65         given: 'session that already holds an anchor lock'
66             objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
67         when: 'same session tries to acquire same anchor lock'
68             objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting)
69         then: 'no exception is thrown'
70             noExceptionThrown()
71     }
72
73 }