[TECHDEBT] Align CPS Core REST API Specification and Implementation
[cps.git] / cps-application / src / test / java / org / onap / cps / architecture / LayeredArchitectureTest.java
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.cps.architecture;
21
22
23 import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
24 import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
25
26 import com.tngtech.archunit.core.importer.ImportOption;
27 import com.tngtech.archunit.junit.AnalyzeClasses;
28 import com.tngtech.archunit.junit.ArchTest;
29 import com.tngtech.archunit.lang.ArchRule;
30
31 /**
32  * Test class responsible for layered architecture.
33  */
34 @AnalyzeClasses(packages = "org.onap.cps", importOptions = {ImportOption.DoNotIncludeTests.class})
35 public class LayeredArchitectureTest {
36
37     private static final String REST_CONTROLLER_PACKAGE = "org.onap.cps.rest..";
38     private static final String NCMP_REST_PACKAGE = "org.onap.cps.ncmp.rest..";
39     private static final String API_SERVICE_PACKAGE = "org.onap.cps.api..";
40     private static final String SPI_SERVICE_PACKAGE = "org.onap.cps.spi..";
41     private static final String NCMP_SERVICE_PACKAGE = "org.onap.cps.ncmp.api..";
42     private static final String SPI_REPOSITORY_PACKAGE = "org.onap.cps.spi.repository..";
43     private static final String YANG_SCHEMA_PACKAGE = "org.onap.cps.yang..";
44     private static final String NOTIFICATION_PACKAGE = "org.onap.cps.notification..";
45     private static final String CPS_UTILS_PACKAGE = "org.onap.cps.utils..";
46
47     @ArchTest
48     static final ArchRule restControllerShouldOnlyDependOnRestController =
49         classes().that().resideInAPackage(REST_CONTROLLER_PACKAGE).should().onlyHaveDependentClassesThat()
50             .resideInAPackage(REST_CONTROLLER_PACKAGE);
51
52     @ArchTest
53     static final ArchRule apiOrSpiServiceShouldOnlyBeDependedOnByControllerAndServicesAndCommonUtilityPackages =
54         freeze(classes().that().resideInAPackage(API_SERVICE_PACKAGE)
55             .or().resideInAPackage(SPI_SERVICE_PACKAGE).should().onlyHaveDependentClassesThat()
56             .resideInAnyPackage(REST_CONTROLLER_PACKAGE, API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, NCMP_REST_PACKAGE,
57                 NCMP_SERVICE_PACKAGE, YANG_SCHEMA_PACKAGE, NOTIFICATION_PACKAGE, CPS_UTILS_PACKAGE));
58
59     @ArchTest
60     static final ArchRule repositoryShouldOnlyBeDependedOnByServicesAndRepository =
61         classes().that().resideInAPackage(SPI_REPOSITORY_PACKAGE).should().onlyHaveDependentClassesThat()
62             .resideInAnyPackage(API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, SPI_REPOSITORY_PACKAGE);
63 }