diff options
author | leventecsanyi <levente.csanyi@est.tech> | 2024-09-23 16:01:03 +0200 |
---|---|---|
committer | leventecsanyi <levente.csanyi@est.tech> | 2024-10-09 16:06:55 +0200 |
commit | dac4c1efc44b5341f803ccd4a79a3a24320698c6 (patch) | |
tree | cbb8a6948244d6a60c294d9df657816b0d152e68 | |
parent | 89bfabfda2afeeedd1e6cdcba41705469d406f48 (diff) |
Added architecture tests to validate ONLY NCMP REST/Service dependencies
- removed old tests and added new test cases for the NCMP controller and service layers
- other dependencies will be added in later commits
Issue-ID: CPS-2422
Change-Id: Iabc4b53e9414477cf3d0b2e1e5a03ba8b4995169
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
-rw-r--r-- | cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java | 72 | ||||
-rw-r--r-- | cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java | 98 |
2 files changed, 98 insertions, 72 deletions
diff --git a/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java b/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java deleted file mode 100644 index 82fdc7f487..0000000000 --- a/cps-application/src/test/java/org/onap/cps/architecture/LayeredArchitectureTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2024 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.architecture; - - -import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; -import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze; - -import com.tngtech.archunit.core.importer.ImportOption; -import com.tngtech.archunit.junit.AnalyzeClasses; -import com.tngtech.archunit.junit.ArchIgnore; -import com.tngtech.archunit.junit.ArchTest; -import com.tngtech.archunit.lang.ArchRule; - -/** - * Test class responsible for layered architecture. - */ -@AnalyzeClasses(packages = "org.onap.cps", importOptions = {ImportOption.DoNotIncludeTests.class}) -public class LayeredArchitectureTest { - - private static final String REST_CONTROLLER_PACKAGE = "org.onap.cps.rest.."; - private static final String NCMP_REST_PACKAGE = "org.onap.cps.ncmp.rest.."; - private static final String API_SERVICE_PACKAGE = "org.onap.cps.api.."; - private static final String SPI_SERVICE_PACKAGE = "org.onap.cps.ri.."; - private static final String NCMP_SERVICE_PACKAGE = "org.onap.cps.ncmp.api.."; - private static final String SPI_REPOSITORY_PACKAGE = "org.onap.cps.ri.repository.."; - private static final String YANG_SCHEMA_PACKAGE = "org.onap.cps.yang.."; - private static final String NOTIFICATION_PACKAGE = "org.onap.cps.notification.."; - private static final String CPS_UTILS_PACKAGE = "org.onap.cps.utils.."; - private static final String NCMP_INIT_PACKAGE = "org.onap.cps.ncmp.init.."; - private static final String CPS_CACHE_PACKAGE = "org.onap.cps.cache.."; - private static final String CPS_EVENTS_PACKAGE = "org.onap.cps.events.."; - - //TODO We need to revisit these rules, the first one doesn't even make any sense: CPS-2293 - - @ArchTest - static final ArchRule restControllerShouldOnlyDependOnRestController = - classes().that().resideInAPackage(REST_CONTROLLER_PACKAGE).should().onlyHaveDependentClassesThat() - .resideInAPackage(REST_CONTROLLER_PACKAGE); - - @ArchTest - @ArchIgnore - static final ArchRule apiOrSpiServiceShouldOnlyBeDependedOnByControllerAndServicesAndCommonUtilityPackages = - freeze(classes().that().resideInAPackage(API_SERVICE_PACKAGE) - .or().resideInAPackage(SPI_SERVICE_PACKAGE).should().onlyHaveDependentClassesThat() - .resideInAnyPackage(REST_CONTROLLER_PACKAGE, API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, NCMP_REST_PACKAGE, - NCMP_SERVICE_PACKAGE, YANG_SCHEMA_PACKAGE, NOTIFICATION_PACKAGE, CPS_UTILS_PACKAGE, NCMP_INIT_PACKAGE, - CPS_CACHE_PACKAGE, CPS_EVENTS_PACKAGE)); - - - @ArchTest - static final ArchRule repositoryShouldOnlyBeDependedOnByServicesAndRepository = - classes().that().resideInAPackage(SPI_REPOSITORY_PACKAGE).should().onlyHaveDependentClassesThat() - .resideInAnyPackage(API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, SPI_REPOSITORY_PACKAGE); -} diff --git a/cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java b/cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java new file mode 100644 index 0000000000..4c0b82fec8 --- /dev/null +++ b/cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java @@ -0,0 +1,98 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2024 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.architecture; + +import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; + +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.junit.AnalyzeClasses; +import com.tngtech.archunit.junit.ArchTest; +import com.tngtech.archunit.lang.ArchRule; +import org.apache.commons.lang3.ArrayUtils; + +/** + * These test verify the correct use of dependencies in all CPS modules. + */ +@AnalyzeClasses(packages = "org.onap.cps", importOptions = {ImportOption.DoNotIncludeTests.class}) +public class NcmpArchitectureTest { + + private static final String[] ACCEPTED_3PP_PACKAGES = { "com.fasterxml..", + "com.google..", + "com.hazelcast..", + "edu..", + "io.cloudevents..", + "io.micrometer..", + "io.netty..", + "io.swagger..", + "jakarta..", + "java..", + "lombok..", + "org.apache..", + "org.mapstruct..", + "org.slf4j..", + "org.springframework..", + "reactor.." + }; + + @ArchTest + static final ArchRule nothingDependsOnCpsNcmpRest = + classes().that().resideInAPackage("org.onap.cps.ncmp.rest..").should().onlyHaveDependentClassesThat() + .resideInAPackage("org.onap.cps.ncmp.rest.."); + + @ArchTest + static final ArchRule ncmpRestControllerShouldOnlyDependOnNcmpService = + classes().that().resideInAPackage("org.onap.cps.ncmp.rest..") + .should() + .onlyDependOnClassesThat() + .resideInAnyPackage(commonAndListedPackages("org.onap.cps.ncmp.rest..", "org.onap.cps.ncmp.api..", + // Below packages are breaking the agreed dependencies + // and need to be removed from this rule. + // This will be handled in a separate user story + "org.onap.cps.spi..", "org.onap.cps.utils..", "org.onap.cps.ncmp.impl..")); + + @ArchTest + static final ArchRule ncmpServiceApiShouldOnlyDependOnThirdPartyPackages = + classes().that().resideInAPackage("org.onap.cps.ncmp.api..").should().onlyDependOnClassesThat() + .resideInAnyPackage(commonAndListedPackages( + // Below packages are breaking the agreed dependencies + // and need to be removed from this rule. + // This will be handled in a separate user story + "org.onap.cps.spi..", "org.onap.cps.ncmp.api..", "org.onap.cps.ncmp.impl..", + "org.onap.cps.ncmp.config", "org.onap.cps.utils..")); + + @ArchTest + static final ArchRule ncmpServiceImplShouldOnlyDependOnCpsServiceAndNcmpEvents = + classes().that().resideInAPackage("org.onap.cps.ncmp.impl..").should().onlyDependOnClassesThat() + .resideInAnyPackage(commonAndListedPackages( + "org.onap.cps.ncmp.api..", "org.onap.cps.ncmp.impl..", + "org.onap.cps.ncmp.event..", "org.onap.cps.ncmp.events..", "org.onap.cps.ncmp.utils..", + "org.onap.cps.ncmp.config..", "org.onap.cps.api..", "org.onap.cps.ncmp.exceptions..", + // Below packages are breaking the agreed dependencies + // and need to be removed from this rule. + // This will be handled in a separate user story + "org.onap.cps.spi..", "org.onap.cps.events..", "org.onap.cps.cpspath..", + "org.onap.cps.impl..", "org.onap.cps.utils..")); + + static String[] commonAndListedPackages(final String... packageIdentifiers) { + return ArrayUtils.addAll(ACCEPTED_3PP_PACKAGES, packageIdentifiers); + } + +} + |