diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2023-06-12 16:24:02 +0100 |
---|---|---|
committer | Sourabh Sourabh <sourabh.sourabh@est.tech> | 2023-06-19 09:01:16 +0000 |
commit | 08898672e0de04238acdedea4266c58f17c2b7e0 (patch) | |
tree | b0266435c84d1fe5b333b0b95fa70b37638f554e /integration-test | |
parent | 75dff29f61825b44a8bf09a3a95cb8ceea2ce444 (diff) |
Move integration test (clean-up, last phase)
- Moved session manager test
- Improved schemaset concurrency test (retry testing)
- Cleaned up all ri (container based) integration test (setup)
- Applied some groovy best practice where needed
- internal ri module cover now down to 29%, covred by integration instead with
- Line coverage up by 41 lines to 99% (was 97%)
- Branch coverage up by 3 branches to 96% (was 93%)
Issue-ID: CPS-1687
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: Ifb77a053e5a5db62a3f6a32ae60a3a8b10918efd
Diffstat (limited to 'integration-test')
3 files changed, 90 insertions, 10 deletions
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy index b942a43af2..a1e03529c3 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/CpsIntegrationSpecBase.groovy @@ -25,10 +25,12 @@ import org.onap.cps.api.impl.CpsAdminServiceImpl import org.onap.cps.api.impl.CpsDataServiceImpl import org.onap.cps.api.impl.CpsModuleServiceImpl import org.onap.cps.integration.DatabaseTestContainer +import org.onap.cps.spi.config.CpsSessionFactory import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.model.DataNode import org.onap.cps.spi.repository.DataspaceRepository import org.onap.cps.spi.impl.utils.CpsValidatorImpl +import org.onap.cps.spi.utils.SessionManager import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.autoconfigure.domain.EntityScan @@ -42,12 +44,12 @@ import spock.lang.Specification import java.time.OffsetDateTime -@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl]) +@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl, SessionManager, CpsSessionFactory]) @Testcontainers @EnableAutoConfiguration @EnableJpaRepositories(basePackageClasses = [DataspaceRepository]) -@ComponentScan(basePackages = ["org.onap.cps.api", "org.onap.cps.spi.repository"]) -@EntityScan("org.onap.cps.spi.entities") +@ComponentScan(basePackages = ['org.onap.cps.api', 'org.onap.cps.spi.repository']) +@EntityScan('org.onap.cps.spi.entities') class CpsIntegrationSpecBase extends Specification { @Shared @@ -69,6 +71,10 @@ class CpsIntegrationSpecBase extends Specification { @Lazy CpsQueryService cpsQueryService + @Autowired + @Lazy + SessionManager sessionManager + def static GENERAL_TEST_DATASPACE = 'generalTestDataspace' def static BOOKSTORE_SCHEMA_SET = 'bookstoreSchemaSet' diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy index 18a2941615..e39e114405 100644 --- a/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy +++ b/integration-test/src/test/groovy/org/onap/cps/integration/base/TestConfig.groovy @@ -34,6 +34,7 @@ import org.onap.cps.spi.repository.ModuleReferenceRepository import org.onap.cps.spi.repository.SchemaSetRepository import org.onap.cps.spi.repository.YangResourceRepository import org.onap.cps.spi.utils.SessionManager +import org.onap.cps.spi.utils.TimeLimiterProvider import org.onap.cps.utils.JsonObjectMapper import org.onap.cps.utils.TimedYangParser import org.onap.cps.yang.TimedYangTextSchemaSourceSetBuilder @@ -75,7 +76,7 @@ class TestConfig extends Specification{ @Autowired @Lazy - SessionManager stubbedSessionManager + SessionManager sessionManager @Bean CpsAdminPersistenceServiceImpl cpsAdminPersistenceService() { @@ -84,7 +85,7 @@ class TestConfig extends Specification{ @Bean CpsDataPersistenceService cpsDataPersistenceService() { - return (CpsDataPersistenceService) new CpsDataPersistenceServiceImpl(dataspaceRepository, anchorRepository, fragmentRepository, jsonObjectMapper, stubbedSessionManager) + return (CpsDataPersistenceService) new CpsDataPersistenceServiceImpl(dataspaceRepository, anchorRepository, fragmentRepository, jsonObjectMapper, sessionManager) } @Bean @@ -103,11 +104,6 @@ class TestConfig extends Specification{ } @Bean - SessionManager sessionManager() { - return Stub(SessionManager) - } - - @Bean TimedYangParser timedYangParser() { return new TimedYangParser() } @@ -117,4 +113,9 @@ class TestConfig extends Specification{ return new TimedYangTextSchemaSourceSetBuilder() } + @Bean + TimeLimiterProvider timeLimiterProvider() { + return new TimeLimiterProvider() + } + } diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy new file mode 100644 index 0000000000..e0a2602b23 --- /dev/null +++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/SessionManagerIntegrationSpec.groovy @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022-2023 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.integration.functional + +import org.onap.cps.integration.base.FunctionalSpecBase +import org.onap.cps.spi.exceptions.SessionManagerException +import org.onap.cps.spi.utils.SessionManager + +class SessionManagerIntegrationSpec extends FunctionalSpecBase { + + SessionManager objectUnderTest + + def shortTimeoutForTesting = 300L + def sessionId + + def setup() { + objectUnderTest = sessionManager + sessionId = objectUnderTest.startSession() + } + + def cleanup(){ + objectUnderTest.closeSession(sessionId, objectUnderTest.WITH_COMMIT) + } + + def 'Lock anchor.'(){ + when: 'session tries to acquire anchor lock by passing anchor entity details' + objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting) + then: 'no exception is thrown' + noExceptionThrown() + } + + def 'Attempt to lock anchor when another session is holding the lock.'(){ + given: 'another session that holds an anchor lock' + def otherSessionId = objectUnderTest.startSession() + objectUnderTest.lockAnchor(otherSessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting) + when: 'a session tries to acquire the same anchor lock' + objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting) + then: 'a session manager exception is thrown specifying operation reached timeout' + def thrown = thrown(SessionManagerException) + thrown.message.contains('Timeout') + then: 'when the other session holding the lock is closed, lock can finally be acquired' + objectUnderTest.closeSession(otherSessionId, objectUnderTest.WITH_COMMIT) + objectUnderTest.lockAnchor(sessionId,FUNCTIONAL_TEST_DATASPACE_1,BOOKSTORE_ANCHOR_1,shortTimeoutForTesting) + } + + def 'Lock anchor twice using the same session.'(){ + given: 'session that already holds an anchor lock' + objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting) + when: 'same session tries to acquire same anchor lock' + objectUnderTest.lockAnchor(sessionId, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, shortTimeoutForTesting) + then: 'no exception is thrown' + noExceptionThrown() + } + +} |