summaryrefslogtreecommitdiffstats
path: root/cps-application
diff options
context:
space:
mode:
authorleventecsanyi <levente.csanyi@est.tech>2024-10-17 14:59:49 +0200
committerLevente Csanyi <levente.csanyi@est.tech>2024-10-24 11:38:14 +0000
commit2a4e96f23458e0ff56cc9ed4487b5339b809d388 (patch)
treef3b8ce3f7bcf6fe8607375b247f7ed5349297c39 /cps-application
parente0c537f4463b6664e108e12962e1f4b34544776c (diff)
Added arcitecture tests for CPS (REST and service and RI)
- added Base class and extracted common method for 3pp checks - added ArchTests for cps REST and cps service Issue-ID: CPS-2423 Change-Id: Icf70b79d1397b002d75ec5c8761775dfd7a6c6d9 Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-application')
-rw-r--r--cps-application/src/test/java/org/onap/cps/architecture/ArchitectureTestBase.java47
-rw-r--r--cps-application/src/test/java/org/onap/cps/architecture/CpsArchitectureTest.java69
-rw-r--r--cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java81
3 files changed, 149 insertions, 48 deletions
diff --git a/cps-application/src/test/java/org/onap/cps/architecture/ArchitectureTestBase.java b/cps-application/src/test/java/org/onap/cps/architecture/ArchitectureTestBase.java
new file mode 100644
index 0000000000..1d39060024
--- /dev/null
+++ b/cps-application/src/test/java/org/onap/cps/architecture/ArchitectureTestBase.java
@@ -0,0 +1,47 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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 org.apache.commons.lang3.ArrayUtils;
+
+public class ArchitectureTestBase {
+
+ 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.."
+ };
+
+ static String[] commonAndListedPackages(final String... packageIdentifiers) {
+ return ArrayUtils.addAll(ACCEPTED_3PP_PACKAGES, packageIdentifiers);
+ }
+}
diff --git a/cps-application/src/test/java/org/onap/cps/architecture/CpsArchitectureTest.java b/cps-application/src/test/java/org/onap/cps/architecture/CpsArchitectureTest.java
new file mode 100644
index 0000000000..7e96447252
--- /dev/null
+++ b/cps-application/src/test/java/org/onap/cps/architecture/CpsArchitectureTest.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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;
+
+@AnalyzeClasses(packages = "org.onap.cps", importOptions = {ImportOption.DoNotIncludeTests.class})
+public class CpsArchitectureTest extends ArchitectureTestBase {
+
+ @ArchTest
+ static final ArchRule cpsRestControllerShouldOnlyDependOnCpsService =
+ classes().that().resideInAPackage("org.onap.cps.rest..").should().onlyDependOnClassesThat()
+ .resideInAnyPackage(commonAndListedPackages("org.onap.cps.rest..",
+ "org.onap.cps.api..",
+ "org.onap.cps.utils..",
+ // Breaks arch rules
+ "org.onap.cps.spi.."));
+
+ @ArchTest
+ static final ArchRule cpsServiceApiShouldNotDependOnAnything =
+ classes().that().resideInAPackage("org.onap.cps.api.").should().onlyDependOnClassesThat()
+ .resideInAnyPackage(commonAndListedPackages()).allowEmptyShould(true);
+
+ @ArchTest
+ static final ArchRule cpsServiceImplShouldDependOnServiceAndEventsAndPathParserPackages =
+ // I think impl package should be moved from the api package.
+ // So in a way this whole rule is breaking our architecture goals
+ classes().that().resideInAPackage("org.onap.cps.api.impl..").should().onlyDependOnClassesThat()
+ .resideInAnyPackage(commonAndListedPackages("org.onap.cps.api..",
+ "org.onap.cps.api.impl..",
+ "org.onap.cps.events..",
+ "org.onap.cps.impl.utils..",
+ "org.onap.cps.spi..",
+ "org.onap.cps.utils..",
+ "org.onap.cps.cpspath.parser..",
+ "org.onap.cps.yang.."));
+
+ @ArchTest
+ static final ArchRule cpsReferenceImplShouldHaveNoDependants =
+ classes().that().resideInAPackage("org.onap.cps.ri..").should().onlyHaveDependentClassesThat()
+ .resideInAnyPackage("org.onap.cps.ri..");
+
+ @ArchTest
+ static final ArchRule referenceImplShouldOnlyHaveDependantsInReferenceImpl =
+ classes().that().resideInAPackage("org.onap.cps.ri.repository..").should().onlyHaveDependentClassesThat()
+ .resideInAnyPackage("org.onap.cps.ri..");
+}
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
index 4c0b82fec8..5d8c534e35 100644
--- a/cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java
+++ b/cps-application/src/test/java/org/onap/cps/architecture/NcmpArchitectureTest.java
@@ -25,31 +25,9 @@ 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.."
- };
+public class NcmpArchitectureTest extends ArchitectureTestBase {
@ArchTest
static final ArchRule nothingDependsOnCpsNcmpRest =
@@ -61,38 +39,45 @@ public class NcmpArchitectureTest {
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.."));
+ .resideInAnyPackage(commonAndListedPackages("org.onap.cps.ncmp.api..",
+ "org.onap.cps.ncmp.rest..",
+ // 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.."));
+ .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.ncmp.api..",
+ "org.onap.cps.ncmp.impl..",
+ "org.onap.cps.ncmp.config",
+ "org.onap.cps.spi..",
+ "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);
- }
-
+ .resideInAnyPackage(commonAndListedPackages("org.onap.cps.api..",
+ "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.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.cpspath..",
+ "org.onap.cps.events..",
+ "org.onap.cps.impl..",
+ "org.onap.cps.spi..",
+ "org.onap.cps.utils.."));
}