From aed2f990e1a5f0089ddd201e10b68ce9878750cf Mon Sep 17 00:00:00 2001 From: waynedunican Date: Mon, 25 Aug 2025 13:30:39 +0100 Subject: [PATCH] Add logging for clamp REST APIs Issue-ID: POLICY-5450 Change-Id: I982a3d56b9b58d4b81eca694381adb9b8176c02f Signed-off-by: waynedunican --- .../commissioning/CommissioningProvider.java | 16 +++++-- .../acm/runtime/config/InterceptorConfig.java | 52 ++++++++++++++++++++++ ...AutomationCompositionInstantiationProvider.java | 11 ++++- .../runtime/main/utils/EndPointInterceptor.java | 44 ++++++++++++++++++ .../participants/AcmParticipantProvider.java | 6 ++- .../runtime/supervision/SupervisionAcHandler.java | 19 +++++--- .../acm/runtime/config/InterceptorConfigTest.java | 48 ++++++++++++++++++++ .../acm/runtime/util/EndPointInterceptorTest.java | 51 +++++++++++++++++++++ 8 files changed, 234 insertions(+), 13 deletions(-) create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfig.java create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EndPointInterceptor.java create mode 100644 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java create mode 100644 runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index a1540d373..431176ab6 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -45,6 +45,8 @@ import org.onap.policy.clamp.models.acm.utils.TimestampHelper; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -67,6 +69,9 @@ public class CommissioningProvider { private final ExecutorService executor = Context.taskWrapping(Executors.newFixedThreadPool(1, new AcmThreadFactory())); + private static final Logger LOGGER = + LoggerFactory.getLogger(CommissioningProvider.class); + private CommissioningResponse createCommissioningResponse(UUID compositionId, ToscaServiceTemplate serviceTemplate) { var response = new CommissioningResponse(); @@ -91,11 +96,11 @@ public class CommissioningProvider { */ @Transactional public CommissioningResponse createAutomationCompositionDefinition(ToscaServiceTemplate serviceTemplate) { - var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate, acRuntimeParameterGroup.getAcmParameters().getToscaElementName(), acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); serviceTemplate = acmDefinition.getServiceTemplate(); + LOGGER.info("Create request received for ID: {}", acmDefinition.getCompositionId()); return createCommissioningResponse(acmDefinition.getCompositionId(), serviceTemplate); } @@ -108,6 +113,7 @@ public class CommissioningProvider { */ @Transactional public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) { + LOGGER.info("Update request received for ID: {}", compositionId); if (verifyIfInstanceExists(compositionId)) { throw new PfModelRuntimeException(Status.BAD_REQUEST, "There are ACM instances, Update of ACM Definition not allowed"); @@ -120,7 +126,6 @@ public class CommissioningProvider { acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate, acRuntimeParameterGroup.getAcmParameters().getToscaElementName(), acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); - return createCommissioningResponse(compositionId, serviceTemplate); } @@ -132,6 +137,7 @@ public class CommissioningProvider { */ @Transactional public CommissioningResponse deleteAutomationCompositionDefinition(UUID compositionId) { + LOGGER.info("Delete request received for ID: {}", compositionId); if (verifyIfInstanceExists(compositionId)) { throw new PfModelRuntimeException(Status.BAD_REQUEST, "Delete instances, to commission automation composition definitions"); @@ -156,6 +162,8 @@ public class CommissioningProvider { @Transactional(readOnly = true) public ToscaServiceTemplates getAutomationCompositionDefinitions(String acName, String acVersion, @NonNull Pageable pageable) { + LOGGER.info("Get automation compositions request received for name: {} " + + "and version: {}", acName, acVersion); var result = new ToscaServiceTemplates(); result.setServiceTemplates(acDefinitionProvider.getServiceTemplateList(acName, acVersion, pageable)); return result; @@ -169,7 +177,7 @@ public class CommissioningProvider { */ @Transactional(readOnly = true) public AutomationCompositionDefinition getAutomationCompositionDefinition(UUID compositionId) { - + LOGGER.info("Get automation composition definition request received for ID: {}", compositionId); return acDefinitionProvider.getAcDefinition(compositionId); } @@ -210,6 +218,7 @@ public class CommissioningProvider { } private void prime(AutomationCompositionDefinition acmDefinition) { + LOGGER.info("Prime request received for ID: {}", acmDefinition.getCompositionId()); var preparation = participantPrimePublisher.prepareParticipantPriming(acmDefinition); acDefinitionProvider.updateAcDefinition(acmDefinition, acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); @@ -220,6 +229,7 @@ public class CommissioningProvider { } private void deprime(AutomationCompositionDefinition acmDefinition) { + LOGGER.info("Deprime request received for ID: {}", acmDefinition.getCompositionId()); acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR); var participantIds = new HashSet(); for (var elementState : acmDefinition.getElementStateMap().values()) { diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfig.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfig.java new file mode 100644 index 000000000..f0d829ef1 --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfig.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * 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.policy.clamp.acm.runtime.config; + +import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * Interceptor Config. + */ +@Profile("Logging") +@Configuration +public class InterceptorConfig { + + /** + * Create WebMvcConfigurer to add EndPointInterceptor. + * + * @param endPointInterceptor the end-point Interceptor + * @return the WebMvcConfigurer + */ + @Bean + public WebMvcConfigurer getWebMvcConfigurer(EndPointInterceptor endPointInterceptor) { + return new WebMvcConfigurer() { + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(endPointInterceptor); + } + }; + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index 6e262e4d8..d79a84f40 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -91,6 +91,7 @@ public class AutomationCompositionInstantiationProvider { */ public InstantiationResponse createAutomationComposition(UUID compositionId, AutomationComposition automationComposition) { + LOGGER.info("Create instance request received for compositionId {}", compositionId); AutomationCompositionProvider.validateInstanceEndpoint(compositionId, automationComposition); automationCompositionProvider.validateNameVersion(automationComposition.getKey().asIdentifier()); @@ -128,6 +129,7 @@ public class AutomationCompositionInstantiationProvider { var acDefinition = acDefinitionProvider.getAcDefinition(compositionId); AcDefinitionProvider.checkPrimedComposition(acDefinition); if (DeployState.UNDEPLOYED.equals(acToUpdate.getDeployState())) { + LOGGER.info("Updating undeployed instance with id {}", instanceId); acToUpdate.setElements(automationComposition.getElements()); acToUpdate.setName(automationComposition.getName()); acToUpdate.setVersion(automationComposition.getVersion()); @@ -182,6 +184,7 @@ public class AutomationCompositionInstantiationProvider { AutomationCompositionDefinition acDefinition) { // save copy in case of a rollback automationCompositionProvider.copyAcElementsBeforeUpdate(acToBeUpdated); + LOGGER.info("Updating deployed instance with id {}", automationComposition.getInstanceId()); // Iterate and update the element property values for (var element : automationComposition.getElements().entrySet()) { @@ -211,7 +214,7 @@ public class AutomationCompositionInstantiationProvider { private InstantiationResponse migrateAutomationComposition( AutomationComposition automationComposition, AutomationComposition acToBeUpdated, AutomationCompositionDefinition acDefinition) { - + LOGGER.info("Migrating instance with id {}", automationComposition.getInstanceId()); if (!DeployState.DEPLOYED.equals(acToBeUpdated.getDeployState())) { throw new PfModelRuntimeException(Status.BAD_REQUEST, "Not allowed to migrate in the state " + acToBeUpdated.getDeployState()); @@ -265,6 +268,7 @@ public class AutomationCompositionInstantiationProvider { AutomationCompositionDefinition acDefinition) { acToBeUpdated.setPrecheck(true); + LOGGER.info("Running migrate precheck for id: {}", automationComposition.getInstanceId()); var copyAc = new AutomationComposition(acToBeUpdated); var acDefinitionTarget = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionTargetId()); AcDefinitionProvider.checkPrimedComposition(acDefinitionTarget); @@ -347,6 +351,8 @@ public class AutomationCompositionInstantiationProvider { public InstantiationResponse deleteAutomationComposition(UUID compositionId, UUID instanceId) { var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId); var acDefinition = getAcDefinition(compositionId, automationComposition); + LOGGER.info("Delete automation composition request received for name: {} and version: {}", + automationComposition.getName(), automationComposition.getVersion()); var result = acInstanceStateResolver.resolve(DeployOrder.DELETE, null, null, automationComposition.getDeployState(), automationComposition.getLockState(), @@ -435,6 +441,8 @@ public class AutomationCompositionInstantiationProvider { * @param instanceId The UUID of the automation composition instance */ public void rollback(UUID compositionId, UUID instanceId) { + LOGGER.info("Rollback automation composition request received for CompositionID: {} and InstanceID: {}", + compositionId, instanceId); var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId); AutomationCompositionProvider.validateInstanceEndpoint(compositionId, automationComposition); @@ -521,6 +529,7 @@ public class AutomationCompositionInstantiationProvider { final String instanceIds, final String stateChangeResults, final String deployStates, final Pageable pageable) { + LOGGER.info("Get automation compositions request received with filters"); List acIds = new ArrayList<>(); if (instanceIds != null) { Arrays.stream(instanceIds.split(",")).forEach(acId -> acIds.add(acId.trim())); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EndPointInterceptor.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EndPointInterceptor.java new file mode 100644 index 000000000..6e316a31b --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EndPointInterceptor.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * 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.policy.clamp.acm.runtime.main.utils; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.web.servlet.HandlerInterceptor; + +/** + * EndPoint Interceptor. + */ +@Slf4j +@Profile("Logging") +@Component +public class EndPointInterceptor implements HandlerInterceptor { + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) + throws Exception { + log.info(request.getMethod() + " " + request.getRequestURI()); + return true; + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java index c4ddbd011..9833fdb59 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java @@ -58,6 +58,7 @@ public class AcmParticipantProvider { * @return A list of available participants */ public List getAllParticipants(final Pageable pageable) { + LOGGER.info("Get request received for all participants"); var participants = this.participantProvider.getParticipants(); return participants.stream().map(participant -> createParticipantInformation(participant, pageable)).toList(); } @@ -80,6 +81,7 @@ public class AcmParticipantProvider { * @return The participant */ public ParticipantInformation getParticipantById(final UUID participantId, final Pageable pageable) { + LOGGER.info("Get participant by participantID request received: {}", participantId); var participant = this.participantProvider.getParticipantById(participantId); return createParticipantInformation(participant, pageable); } @@ -129,7 +131,7 @@ public class AcmParticipantProvider { "Participant Not Found with ID: " + participantId); } supervisionParticipantHandler.handleRestart(participantId, null); - LOGGER.debug("Restarting participant with ID: {}", participantId); + LOGGER.debug("Sync participant cache request received with ID: {}", participantId); } @@ -138,6 +140,6 @@ public class AcmParticipantProvider { */ public void restartAllParticipants() { supervisionParticipantHandler.handleRestartOfAllParticipants(); - LOGGER.debug("Restarting all participants"); + LOGGER.debug("Sync participant cache request received for all participants"); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java index 9d6529dd2..5ca376ea7 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java @@ -83,6 +83,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void deploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Deployment request received for instanceID: {}", automationComposition.getInstanceId()); if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult()) && DeployState.DEPLOYING.equals(automationComposition.getDeployState()) && automationComposition.getElements().size() > 1) { @@ -115,6 +116,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void undeploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Undeployment request received for instanceID: {}", automationComposition.getInstanceId()); if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult()) && DeployState.UNDEPLOYING.equals(automationComposition.getDeployState()) && automationComposition.getElements().size() > 1) { @@ -133,9 +135,8 @@ public class SupervisionAcHandler { var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate()); automationComposition.setPhase(startPhase); automationCompositionProvider.updateAutomationComposition(automationComposition); - executor.execute( - () -> automationCompositionStateChangePublisher.send( - automationComposition, startPhase, true, acDefinition.getRevisionId())); + executor.execute(() -> automationCompositionStateChangePublisher.send(automationComposition, + startPhase, true, acDefinition.getRevisionId())); } /** @@ -145,6 +146,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void unlock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Unlock request received for instanceID: {}", automationComposition.getInstanceId()); if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult()) && LockState.UNLOCKING.equals(automationComposition.getLockState()) && automationComposition.getElements().size() > 1) { @@ -162,8 +164,8 @@ public class SupervisionAcHandler { automationComposition.setPhase(startPhase); automationCompositionProvider.updateAutomationComposition(automationComposition); executor.execute( - () -> automationCompositionStateChangePublisher.send( - automationComposition, startPhase, true, acDefinition.getRevisionId())); + () -> automationCompositionStateChangePublisher.send(automationComposition, + startPhase, true, acDefinition.getRevisionId())); } /** @@ -173,6 +175,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void prepare(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Prepare pre-deploy request received for instanceID: {}", automationComposition.getInstanceId()); AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE, SubState.PREPARING); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); var stage = ParticipantUtils.getFirstStage(automationComposition, acDefinition.getServiceTemplate()); @@ -192,6 +195,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void review(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Prepare post-deploy request received for instanceID: {}", automationComposition.getInstanceId()); AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKED, SubState.REVIEWING); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); @@ -205,6 +209,7 @@ public class SupervisionAcHandler { * @param acDefinition the AutomationCompositionDefinition */ public void lock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) { + LOGGER.info("Lock request received for instanceID: {}", automationComposition.getInstanceId()); if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult()) && LockState.LOCKING.equals(automationComposition.getLockState()) && automationComposition.getElements().size() > 1) { @@ -222,8 +227,8 @@ public class SupervisionAcHandler { automationComposition.setPhase(startPhase); automationCompositionProvider.updateAutomationComposition(automationComposition); executor.execute( - () -> automationCompositionStateChangePublisher.send( - automationComposition, startPhase, true, acDefinition.getRevisionId())); + () -> automationCompositionStateChangePublisher.send(automationComposition, + startPhase, true, acDefinition.getRevisionId())); } /** diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java new file mode 100644 index 000000000..8608e0c6b --- /dev/null +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * 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.policy.clamp.acm.runtime.config; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +public class InterceptorConfigTest { + + @Test + public void testGetWebMvcConfigurerAddsInterceptor() { + InterceptorConfig config = new InterceptorConfig(); + EndPointInterceptor interceptor = mock(EndPointInterceptor.class); + InterceptorRegistry registry = mock(InterceptorRegistry.class); + + when(registry.addInterceptor(interceptor)).thenReturn(null); + + WebMvcConfigurer webMvcConfigurer = config.getWebMvcConfigurer(interceptor); + webMvcConfigurer.addInterceptors(registry); + + verify(registry, times(1)).addInterceptor(interceptor); + } +} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java new file mode 100644 index 000000000..a36625b69 --- /dev/null +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved. + * ================================================================================ + * 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.policy.clamp.acm.runtime.util; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor; + +public class EndPointInterceptorTest { + + @Test + public void testPreHandleReturnsTrueAndLogs() throws Exception { + EndPointInterceptor interceptor = new EndPointInterceptor(); + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + + when(request.getMethod()).thenReturn("GET"); + when(request.getRequestURI()).thenReturn("/test/uri"); + + boolean result = interceptor.preHandle(request, response, new Object()); + + assertTrue(result); + + verify(request).getMethod(); + verify(request).getRequestURI(); + } +} \ No newline at end of file -- 2.16.6