Fixed SonarQube issues and removed not used delete Participant.
Issue-ID: POLICY-5403
Change-Id: Ie21a2aa1536611ae90b69bd9154fbe3653a1a822
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
return result.toAuthorative();
}
- /**
- * Delete a participant.
- *
- * @param participantId the Id of the participant to delete
- * @return the participant deleted
- */
- public Participant deleteParticipant(@NonNull final UUID participantId) {
- var jpaDeleteParticipantOpt = participantRepository.findById(participantId.toString());
-
- if (jpaDeleteParticipantOpt.isEmpty()) {
- String errorMessage =
- "delete of participant \"" + participantId + "\" failed, participant does not exist";
- throw new PfModelRuntimeException(Status.BAD_REQUEST, errorMessage);
- }
- participantRepository.delete(jpaDeleteParticipantOpt.get());
-
- return jpaDeleteParticipantOpt.get().toAuthorative();
- }
-
/**
* Get a map with SupportedElement as key and the participantId as value.
*
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@Test
void testAutomationCompositionLombok() {
- assertDoesNotThrow(() -> new AutomationComposition());
var ac0 = new AutomationComposition();
ac0.setElements(new LinkedHashMap<>());
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@Test
void testParticipantLombok() {
- assertDoesNotThrow(() -> new ParticipantReplica());
var p0 = new ParticipantReplica();
assertThat(p0.toString()).contains("ParticipantReplica(");
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-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.
package org.onap.policy.clamp.models.acm.concepts;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@Test
void testParticipantLombok() {
- assertDoesNotThrow(() -> new Participant());
var p0 = new Participant();
assertThat(p0.toString()).contains("Participant(");
new JpaAutomationCompositionElement(null, null);
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
- assertDoesNotThrow(() -> new JpaAutomationCompositionElement());
assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY));
}
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;\r
import static org.junit.jupiter.api.Assertions.assertEquals;\r
\r
-import java.util.LinkedHashMap;\r
import java.util.Map;\r
import java.util.UUID;\r
import org.junit.jupiter.api.Test;\r
new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, null);\r
}).hasMessageMatching("elements" + NULL_ERROR);\r
\r
- assertDoesNotThrow(() -> new JpaAutomationCompositionRollback());\r
- Map<String, Object> map = new LinkedHashMap<>();\r
- map.put("test", "test");\r
+ Map<String, Object> map = Map.of("test", "test");\r
assertDoesNotThrow(() -> new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, map));\r
}\r
\r
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
assertThatThrownBy(() -> {
new JpaAutomationComposition((AutomationComposition) null);
}).hasMessageMatching("authorativeConcept" + NULL_ERROR);
-
- assertDoesNotThrow(() -> new JpaAutomationComposition());
}
@Test
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-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.
assertThatThrownBy(() -> new JpaParticipantReplica(null, UUID.randomUUID().toString()))
.hasMessageMatching("replicaId is marked .*ull but is null");
- assertDoesNotThrow(() -> new JpaParticipantReplica());
assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023,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.
new JpaParticipantSupportedElementType("key", "key", "name", null);
}).hasMessageMatching("typeVersion" + NULL_ERROR);
- assertDoesNotThrow(() -> new JpaParticipantSupportedElementType());
assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key"));
assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key", "name",
"1.0.0"));
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-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.
assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), new ArrayList<>(), null))
.hasMessageMatching("replicas is marked .*ull but is null");
- assertDoesNotThrow(() -> new JpaParticipant());
assertDoesNotThrow(() -> new JpaParticipant(UUID.randomUUID().toString(),
new ArrayList<>(), new ArrayList<>()));
}
PfModelRuntimeException.class).hasMessageMatching("Participant Not Found with ID:.*.");
}
- @Test
- void testDeleteParticipant() {
- var participantRepository = mock(ParticipantRepository.class);
- var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
- var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
- var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository,
- mock(ParticipantReplicaRepository.class));
-
- var participantId = inputParticipants.get(0).getParticipantId();
- assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId))
- .hasMessageMatching(".*.failed, participant does not exist");
-
- when(participantRepository.findById(participantId.toString()))
- .thenReturn(Optional.of(jpaParticipantList.get(0)));
-
- var deletedParticipant = participantProvider.deleteParticipant(participantId);
- assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(deletedParticipant);
- }
-
@Test
void testGetAutomationCompositionElements() {
var participantRepository = mock(ParticipantRepository.class);
assertThrows(NullPointerException.class, () -> participantProvider.getParticipantById(null));
assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.saveParticipant(null));
- assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
var pageable = Pageable.unpaged();
assertThrows(NullPointerException.class, () ->
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
import org.onap.policy.common.message.bus.event.Topic;
import org.onap.policy.common.message.bus.event.TopicSink;
-import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
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 {
+class InterceptorConfigTest {
@Test
- public void testGetWebMvcConfigurerAddsInterceptor() {
- InterceptorConfig config = new InterceptorConfig();
- EndPointInterceptor interceptor = mock(EndPointInterceptor.class);
- InterceptorRegistry registry = mock(InterceptorRegistry.class);
+ void testGetWebMvcConfigurerAddsInterceptor() {
+ var config = new InterceptorConfig();
+ var interceptor = mock(EndPointInterceptor.class);
+ var registry = mock(InterceptorRegistry.class);
when(registry.addInterceptor(interceptor)).thenReturn(null);
- WebMvcConfigurer webMvcConfigurer = config.getWebMvcConfigurer(interceptor);
+ var webMvcConfigurer = config.getWebMvcConfigurer(interceptor);
webMvcConfigurer.addInterceptors(registry);
verify(registry, times(1)).addInterceptor(interceptor);
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
-public class EndPointInterceptorTest {
+class EndPointInterceptorTest {
@Test
- public void testPreHandleReturnsTrueAndLogs() throws Exception {
- EndPointInterceptor interceptor = new EndPointInterceptor();
- HttpServletRequest request = mock(HttpServletRequest.class);
- HttpServletResponse response = mock(HttpServletResponse.class);
+ void testPreHandleReturnsTrueAndLogs() throws Exception {
+ var interceptor = new EndPointInterceptor();
+ var request = mock(HttpServletRequest.class);
+ var response = mock(HttpServletResponse.class);
when(request.getMethod()).thenReturn("GET");
when(request.getRequestURI()).thenReturn("/test/uri");
- boolean result = interceptor.preHandle(request, response, new Object());
+ var result = interceptor.preHandle(request, response, new Object());
assertTrue(result);
verify(request).getMethod();
verify(request).getRequestURI();
}
-}
\ No newline at end of file
+}