From 5ffa821df5f88ef21c7e70c1cd1185f71267d9d7 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Sat, 12 Jul 2025 11:14:56 +0200 Subject: [PATCH] Fix NullPointerException in cnf-adaper - add @ComponentScan annotation that was removed in one of the last changes. It is required to pick up beans from the so common lib Issue-ID: SO-4205 Change-Id: I1620cd983924dc1d45a0029444967ea9671dcb96 Signed-off-by: Fiete Ostkamp --- .../onap/so/adapters/cnf/MSOCnfApplication.java | 2 + .../so/adapters/cnf/SpringContextHelperTest.java | 43 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/SpringContextHelperTest.java diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java index 5984192..577ecf5 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/MSOCnfApplication.java @@ -28,8 +28,10 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; @SpringBootApplication +@ComponentScan(basePackages = {"org.onap.so.adapters.cnf", "org.onap.so.spring"}) @EnableAutoConfiguration(exclude = {LiquibaseAutoConfiguration.class, HibernateJpaAutoConfiguration.class, DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, SecurityAutoConfiguration.class}) diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/SpringContextHelperTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/SpringContextHelperTest.java new file mode 100644 index 0000000..e05f491 --- /dev/null +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/SpringContextHelperTest.java @@ -0,0 +1,43 @@ +/* + * Copyright © 2025 Deutsche Telekom + * + * 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. + */ +package org.onap.so.adapters.cnf; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.spring.SpringContextHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class SpringContextHelperTest { + + @Autowired + SpringContextHelper helper; + + @Test + // The SpringContextHelper is part of the so common library + // and is in a package that would normally not be picked up + // by spring's context scanning. + // This test thus essentially assures that the spring boot app + // has a @ComponentScan that includes org.onap.so.spring + public void thatSpringContextHelperIsAvailable() { + assertNotNull(helper); + } +} -- 2.16.6