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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.cps.architecture;
23 import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
24 import static com.tngtech.archunit.library.freeze.FreezingArchRule.freeze;
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;
32 * Test class responsible for layered architecture.
34 @AnalyzeClasses(packages = "org.onap.cps", importOptions = {ImportOption.DoNotIncludeTests.class})
35 public class LayeredArchitectureTest {
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 private static final String NCMP_INIT_PACKAGE = "org.onap.cps.ncmp.init..";
49 static final ArchRule restControllerShouldOnlyDependOnRestController =
50 classes().that().resideInAPackage(REST_CONTROLLER_PACKAGE).should().onlyHaveDependentClassesThat()
51 .resideInAPackage(REST_CONTROLLER_PACKAGE);
54 static final ArchRule apiOrSpiServiceShouldOnlyBeDependedOnByControllerAndServicesAndCommonUtilityPackages =
55 freeze(classes().that().resideInAPackage(API_SERVICE_PACKAGE)
56 .or().resideInAPackage(SPI_SERVICE_PACKAGE).should().onlyHaveDependentClassesThat()
57 .resideInAnyPackage(REST_CONTROLLER_PACKAGE, API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, NCMP_REST_PACKAGE,
58 NCMP_SERVICE_PACKAGE, YANG_SCHEMA_PACKAGE, NOTIFICATION_PACKAGE, CPS_UTILS_PACKAGE, NCMP_INIT_PACKAGE));
61 static final ArchRule repositoryShouldOnlyBeDependedOnByServicesAndRepository =
62 classes().that().resideInAPackage(SPI_REPOSITORY_PACKAGE).should().onlyHaveDependentClassesThat()
63 .resideInAnyPackage(API_SERVICE_PACKAGE, SPI_SERVICE_PACKAGE, SPI_REPOSITORY_PACKAGE);