--- /dev/null
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. 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.
+ * ============LICENSE_END=========================================================
+ */
+ package org.onap.aai.modelloader.notification;
+
+ import org.junit.jupiter.api.Test;
+ import org.onap.sdc.api.IDistributionClient;
+ import org.onap.sdc.api.consumer.IComponentDoneStatusMessage;
+ import org.onap.sdc.api.consumer.IConfiguration;
+ import org.onap.sdc.api.notification.INotificationData;
+ import org.onap.sdc.utils.DistributionStatusEnum;
+ import org.springframework.boot.test.context.SpringBootTest;
+ import org.springframework.test.context.TestPropertySource;
+ import static org.mockito.Mockito.*;
+ import static org.junit.jupiter.api.Assertions.*;
+
+ @SpringBootTest
+ @TestPropertySource(properties = {"CONFIG_HOME=src/test/resources"})
+ public class CompDoneStatusMessageBuilderTest {
+
+ @Test
+ public void testBuild() {
+ IDistributionClient mockClient = mock(IDistributionClient.class);
+ INotificationData mockData = mock(INotificationData.class);
+
+ IConfiguration mockConfig = mock(IConfiguration.class);
+ when(mockClient.getConfiguration()).thenReturn(mockConfig);
+ when(mockConfig.getConsumerID()).thenReturn("consumer123");
+
+ when(mockData.getDistributionID()).thenReturn("distID456");
+
+ DistributionStatusEnum status = DistributionStatusEnum.DEPLOY_OK;
+ IComponentDoneStatusMessage result = CompDoneStatusMessageBuilder.build(mockClient, mockData, status);
+
+ assertNotNull(result);
+ assertTrue(result instanceof CompDoneStatusMsg);
+ CompDoneStatusMsg statusMsg = (CompDoneStatusMsg) result;
+
+ assertEquals("distID456", statusMsg.getDistributionID());
+ assertEquals("consumer123", statusMsg.getConsumerID());
+ assertEquals(DistributionStatusEnum.DEPLOY_OK, statusMsg.getStatus());
+ }
+
+ @Test
+ public void testBuildWithFailureStatus() {
+ IDistributionClient mockClient = mock(IDistributionClient.class);
+ INotificationData mockData = mock(INotificationData.class);
+
+ IConfiguration mockConfig = mock(IConfiguration.class);
+ when(mockClient.getConfiguration()).thenReturn(mockConfig);
+ when(mockConfig.getConsumerID()).thenReturn("consumer123");
+
+ when(mockData.getDistributionID()).thenReturn("distID456");
+
+ DistributionStatusEnum status = DistributionStatusEnum.DEPLOY_ERROR;
+ IComponentDoneStatusMessage result = CompDoneStatusMessageBuilder.build(mockClient, mockData, status);
+
+ assertNotNull(result);
+ assertTrue(result instanceof CompDoneStatusMsg);
+ CompDoneStatusMsg statusMsg = (CompDoneStatusMsg) result;
+
+ assertEquals("distID456", statusMsg.getDistributionID());
+ assertEquals("consumer123", statusMsg.getConsumerID());
+ assertEquals(DistributionStatusEnum.DEPLOY_ERROR, statusMsg.getStatus());
+ }
+
+ @Test
+ public void testBuildHandlesNullValues() {
+ IDistributionClient mockClient = mock(IDistributionClient.class);
+ INotificationData mockData = mock(INotificationData.class);
+
+ IConfiguration mockConfig = mock(IConfiguration.class);
+ when(mockClient.getConfiguration()).thenReturn(mockConfig);
+ when(mockConfig.getConsumerID()).thenReturn(null);
+ when(mockData.getDistributionID()).thenReturn(null);
+
+ DistributionStatusEnum status = DistributionStatusEnum.DEPLOY_OK;
+ IComponentDoneStatusMessage result = CompDoneStatusMessageBuilder.build(mockClient, mockData, status);
+
+ assertNotNull(result);
+ assertTrue(result instanceof CompDoneStatusMsg);
+ CompDoneStatusMsg statusMsg = (CompDoneStatusMsg) result;
+
+ assertNull(statusMsg.getDistributionID());
+ assertNull(statusMsg.getConsumerID());
+ assertEquals(DistributionStatusEnum.DEPLOY_OK, statusMsg.getStatus());
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.notification;
+
+import org.junit.jupiter.api.Test;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.consumer.IConfiguration;
+import org.onap.sdc.api.consumer.IDistributionStatusMessage;
+import org.onap.sdc.api.notification.IArtifactInfo;
+import org.onap.sdc.api.notification.INotificationData;
+import static org.mockito.Mockito.*;
+import org.onap.sdc.utils.DistributionStatusEnum;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+import static org.junit.jupiter.api.Assertions.*;
+import org.springframework.test.context.TestPropertySource;
+
+@SpringBootTest
+@TestPropertySource(properties = {"CONFIG_HOME=src/test/resources"})
+public class DistributionStatusMessageBuilderTest {
+
+ @Test
+ public void testBuild() {
+ IDistributionClient mockClient = mock(IDistributionClient.class);
+ IConfiguration mockConfig = mock(IConfiguration.class);
+ when(mockClient.getConfiguration()).thenReturn(mockConfig);
+ when(mockConfig.getConsumerID()).thenReturn("testConsumerID");
+
+ INotificationData mockData = mock(INotificationData.class);
+ when(mockData.getDistributionID()).thenReturn("testDistributionID");
+
+ IArtifactInfo mockArtifact = mock(IArtifactInfo.class);
+ when(mockArtifact.getArtifactURL()).thenReturn("http://example.com/artifact");
+
+ DistributionStatusEnum status = DistributionStatusEnum.DEPLOY_OK;
+ IDistributionStatusMessage result = DistributionStatusMessageBuilder.build(mockClient, mockData, mockArtifact, status);
+
+ assertNotNull(result);
+ assertEquals("testDistributionID", result.getDistributionID());
+ assertEquals("testConsumerID", result.getConsumerID());
+ assertEquals("http://example.com/artifact", result.getArtifactURL());
+ assertEquals(DistributionStatusEnum.DEPLOY_OK, result.getStatus());
+ }
+
+ @Test
+ public void testBuildWithoutArtifactInfo() {
+ IDistributionClient mockClient = mock(IDistributionClient.class);
+ IConfiguration mockConfig = mock(IConfiguration.class);
+ when(mockClient.getConfiguration()).thenReturn(mockConfig);
+ when(mockConfig.getConsumerID()).thenReturn("testConsumerID");
+
+ INotificationData mockData = mock(INotificationData.class);
+ when(mockData.getDistributionID()).thenReturn("testDistributionID");
+
+ DistributionStatusEnum status = DistributionStatusEnum.DEPLOY_OK;
+ IDistributionStatusMessage result = DistributionStatusMessageBuilder.build(mockClient, mockData, status);
+
+ assertNotNull(result);
+ assertEquals("testDistributionID", result.getDistributionID());
+ assertEquals("testConsumerID", result.getConsumerID());
+ assertEquals("", result.getArtifactURL());
+ assertEquals(DistributionStatusEnum.DEPLOY_OK, result.getStatus());
+ }
+}
+
+
*/
package org.onap.aai.modelloader.notification;
-import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
-
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
+import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
import org.onap.sdc.api.IDistributionClient;
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)
- )).thenThrow(DownloadFailureException.class);
+ )).thenThrow(DownloadFailureException.class);
eventCallback.activateCallback(data);
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)))
- .thenReturn(Collections.emptyList());
+ .thenReturn(Collections.emptyList());
when(mockArtifactDeploymentManager.deploy(any(String.class), any(List.class), any(List.class)))
.thenReturn(true);
verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class));
verify(mockArtifactDeploymentManager).deploy(any(String.class), any(List.class), any(List.class));
}
+ @Test
+ public void testActivateCallback_withVnfCatalogArtifacts() throws Exception {
+ INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithCatalogFile();
+
+ List<Artifact> downloadedArtifacts = new ArrayList<>();
+ downloadedArtifacts.add(new Artifact(ArtifactType.MODEL));
+ downloadedArtifacts.add(new Artifact(ArtifactType.VNF_CATALOG));
+
+ when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class)))
+ .thenReturn(downloadedArtifacts);
+
+ eventCallback.activateCallback(data);
+
+ verify(mockArtifactDeploymentManager).deploy(eq("ID"),
+ argThat(list -> list.stream().anyMatch(a -> a.getType() == ArtifactType.MODEL)),
+ anyList());
+ }
}
--- /dev/null
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.restclient;
+
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+
+public class BabelServiceClientExceptionTest {
+
+ @Test
+ public void testConstructorWithMessage() {
+ String expectedMessage = "This is a test error message";
+ BabelServiceClientException exception = new BabelServiceClientException(expectedMessage);
+ assertNotNull(exception);
+ assertEquals(expectedMessage, exception.getMessage(), "The exception message should match.");
+ }
+
+ @Test
+ public void testConstructorWithException() {
+ Exception underlyingException = new Exception("Underlying exception");
+ BabelServiceClientException exception = new BabelServiceClientException(underlyingException);
+
+ // Assert
+ assertNotNull(exception);
+ assertEquals(underlyingException, exception.getCause(), "The cause should match the passed exception.");
+ }
+}
--- /dev/null
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.service;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
+import org.springframework.test.web.servlet.MockMvc;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+
+@WebMvcTest(EchoService.class)
+public class EchoServiceTest {
+
+ @Autowired
+ private MockMvc mockMvc;
+
+ @Test
+ public void testEcho() throws Exception {
+ String input = "hello";
+ mockMvc.perform(get("/services/model-loader/v1/echo-service/echo/{input}", input))
+ .andExpect(status().isOk())
+ .andExpect(content().string(input));
+ }
+
+ @Test
+ public void testEchoSpecialCharacters() throws Exception {
+ String input = "!@#$%^&*()";
+ mockMvc.perform(get("/services/model-loader/v1/echo-service/echo/{input}", input))
+ .andExpect(status().isOk())
+ .andExpect(content().string(input));
+ }
+}
--- /dev/null
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2025 Deutsche Telekom. 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.modelloader.service;
+
+import static org.mockito.Mockito.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.*;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.modelloader.config.ModelLoaderConfig;
+import org.onap.aai.modelloader.notification.EventCallback;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.TestPropertySource;
+
+import java.util.Timer;
+
+@SpringBootTest
+@TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
+public class TestSdcConnectionJob {
+
+ @Mock
+ private IDistributionClient client;
+
+ @Mock
+ private ModelLoaderConfig config;
+
+ @Mock
+ private EventCallback callback;
+
+ @Mock
+ private Timer timer;
+
+ @Mock
+ private IDistributionClientResult clientResult;
+
+ @Mock
+ private Logger logger;
+
+ private SdcConnectionJob connectionJob;
+
+ @BeforeEach
+ public void setUp() {
+ MockitoAnnotations.openMocks(this);
+ LoggerFactory loggerFactorySpy = mock(LoggerFactory.class);
+ when(loggerFactorySpy.getLogger(SdcConnectionJob.class.getName())).thenReturn(logger);
+ connectionJob = new SdcConnectionJob(client, config, callback, timer);
+ }
+
+ @Test
+ public void testRunWhenASDCConnectionDisabled() {
+ when(config.getASDCConnectionDisabled()).thenReturn(true);
+ connectionJob.run();
+ verify(client, never()).init(any(), any());
+ verify(client, never()).start();
+ verify(config, times(1)).getASDCConnectionDisabled();
+ }
+
+ @Test
+ public void testRunInitializationFails() {
+ when(config.getASDCConnectionDisabled()).thenReturn(false);
+ when(client.init(config, callback)).thenReturn(clientResult);
+ when(clientResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.FAIL);
+ connectionJob.run();
+ verify(client).init(config, callback);
+ verify(client, never()).start();
+ verify(config, times(1)).getASDCConnectionDisabled();
+ }
+
+ @Test
+ public void testRunInitializationSucceedsButStartFails() {
+ when(config.getASDCConnectionDisabled()).thenReturn(false);
+ when(client.init(config, callback)).thenReturn(clientResult);
+ when(clientResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS);
+
+ IDistributionClientResult startResult = mock(IDistributionClientResult.class);
+ when(client.start()).thenReturn(startResult);
+ when(startResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.FAIL);
+
+ connectionJob.run();
+ verify(client,times(1)).start();
+ verify(timer, never()).cancel();
+ verify(config, times(1)).getASDCConnectionDisabled();
+ }
+
+ @Test
+ public void testRunInitializationAndStartBothSucceed() {
+ when(config.getASDCConnectionDisabled()).thenReturn(false);
+ when(client.init(config, callback)).thenReturn(clientResult);
+ when(clientResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS);
+
+ IDistributionClientResult startResult = mock(IDistributionClientResult.class);
+ when(client.start()).thenReturn(startResult);
+ when(startResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS);
+
+ connectionJob.run();
+ verify(client).init(config, callback);
+ verify(client,times(1)).start();
+ verify(timer).cancel();
+ }
+
+}
spring.kafka.consumer.group-id=aai
spring.kafka.consumer.client-id=aai-model-loader
topics.distribution.notification=SDC-DISTR-NOTIF-TOPIC-AUTO
-
spring.sleuth.enabled=false
ml.distribution.connection.enabled=false # avoid having the distribution client running in the background (requires active kafka)