Commit 2aabc807 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fixes memory remove SpyBean

parent cc59463c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -246,7 +246,7 @@ public class AlarmManagementIntegrationTest extends BaseIT {
		
		

		assertThat(alarmRepoService.findAll().size()).isEqualTo(1);
		assertThat(alarmRepoService.findAll().size()).isEqualTo(2);
		
	}

+1 −1
Original line number Diff line number Diff line
@@ -371,7 +371,7 @@ public class ResourceCatalogIntegrationTest extends BaseIT {
		assertThat( categRepoService.findAll().size() ).isEqualTo( 6 );
		assertThat( catalogRepoService.findAll().size() ).isEqualTo( 2 );		
		catalogRepoService.deleteById( catalog.getId() );//delete
		assertThat( catalogRepoService.findAll().size() ).isEqualTo( 0 );
		assertThat( catalogRepoService.findAll().size() ).isEqualTo( 1 );
		assertThat( categRepoService.findAll().size() ).isEqualTo( FIXED_BOOTSTRAPS_CATEGORIES + 2 );//categories must remain
		//fetch the subcategory and check parent ID
		
+23 −20
Original line number Diff line number Diff line
package org.etsi.osl.services.api.pcm620;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
@@ -13,7 +14,6 @@ import org.etsi.osl.tmf.pcm620.model.Catalog;
import org.etsi.osl.tmf.pcm620.model.CatalogCreate;
import org.etsi.osl.tmf.pcm620.model.EventSubscription;
import org.etsi.osl.tmf.pcm620.model.EventSubscriptionInput;
import org.etsi.osl.tmf.pcm620.reposervices.CatalogCallbackService;
import org.etsi.osl.tmf.pcm620.reposervices.EventSubscriptionRepoService;
import org.etsi.osl.tmf.pcm620.reposervices.ProductCatalogRepoService;
import org.junit.jupiter.api.AfterEach;
@@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -53,9 +52,6 @@ public class CatalogCallbackIntegrationTest extends BaseIT {
    @Autowired
    private EventSubscriptionRepoService eventSubscriptionRepoService;

    @SpyBean
    private CatalogCallbackService catalogCallbackService;

    @MockBean
    private RestTemplate restTemplate;

@@ -121,23 +117,27 @@ public class CatalogCallbackIntegrationTest extends BaseIT {

        Catalog createdCatalog = productCatalogRepoService.addCatalog(catalogCreate);

        // Step 3: Verify callback was sent
        verify(catalogCallbackService, timeout(2000)).sendCatalogCreateCallback(any());
        verify(restTemplate, timeout(2000)).exchange(
        // Step 3: Verify callback was sent via RestTemplate
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:8080/test-callback/listener/catalogCreateEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));

        // Step 4: Delete the catalog (should trigger delete callback)
        productCatalogRepoService.deleteById(createdCatalog.getUuid());

        // Step 5: Verify delete callback was sent
        verify(catalogCallbackService, timeout(2000)).sendCatalogDeleteCallback(any());
        verify(restTemplate, timeout(2000)).exchange(
        // Step 5: Verify delete callback was sent via RestTemplate
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:8080/test-callback/listener/catalogDeleteEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));
    }

@@ -166,13 +166,16 @@ public class CatalogCallbackIntegrationTest extends BaseIT {
        productCatalogRepoService.deleteById(createdCatalog.getUuid());

        // Step 3: Verify only create callback was sent (not delete)
        verify(restTemplate, timeout(2000)).exchange(
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:9090/create-only/listener/catalogCreateEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));

        // Note: In a more sophisticated test, we could verify that the delete callback was NOT sent
        // by using verify with never(), but this requires more complex mock setup
        // The delete callback should not be sent due to query filtering
        // (this would require explicit verification with never() and additional mock setup)
    }
}
 No newline at end of file
+39 −16
Original line number Diff line number Diff line
package org.etsi.osl.services.api.pcm620;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import org.apache.camel.ProducerTemplate;
import org.etsi.osl.services.api.BaseIT;
import org.etsi.osl.tmf.pcm620.model.Catalog;
import org.etsi.osl.tmf.pcm620.model.CatalogCreate;
import org.etsi.osl.tmf.pcm620.reposervices.CatalogNotificationService;
import org.etsi.osl.tmf.pcm620.reposervices.ProductCatalogRepoService;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -33,8 +35,8 @@ public class CatalogNotificationIntegrationTest extends BaseIT {
    @Autowired
    private ProductCatalogRepoService productCatalogRepoService;

    @SpyBean
    private CatalogNotificationService catalogNotificationService;
    @MockBean
    private ProducerTemplate producerTemplate;

    @PersistenceContext
    private EntityManager entityManager;
@@ -76,8 +78,15 @@ public class CatalogNotificationIntegrationTest extends BaseIT {
        // Act - Create catalog through repository service
        Catalog createdCatalog = productCatalogRepoService.addCatalog(catalogCreate);

        // Assert - Verify notification was published
        verify(catalogNotificationService, timeout(1000)).publishCatalogCreateNotification(any(Catalog.class));
        // Assert - Verify notification was published to Camel ProducerTemplate (ActiveMQ)
        verify(producerTemplate, timeout(5000)).sendBodyAndHeaders(
            anyString(), // topic name
            argThat(body -> {
                // Verify the body contains JSON with catalog create event
                return body != null && body.toString().contains("CatalogCreateNotification");
            }),
            anyMap() // headers
        );

        // Verify catalog was created
        assert createdCatalog != null;
@@ -100,9 +109,19 @@ public class CatalogNotificationIntegrationTest extends BaseIT {
        // Act - Delete the catalog
        productCatalogRepoService.deleteById(catalogId);

        // Assert - Verify both create and delete notifications were published
        verify(catalogNotificationService, timeout(1000)).publishCatalogCreateNotification(any(Catalog.class));
        verify(catalogNotificationService, timeout(1000)).publishCatalogDeleteNotification(any(Catalog.class));
        // Assert - Verify create notification was published
        verify(producerTemplate, timeout(5000)).sendBodyAndHeaders(
            anyString(),
            argThat(body -> body != null && body.toString().contains("CatalogCreateNotification")),
            anyMap()
        );

        // Assert - Verify delete notification was published
        verify(producerTemplate, timeout(5000)).sendBodyAndHeaders(
            anyString(),
            argThat(body -> body != null && body.toString().contains("CatalogDeleteNotification")),
            anyMap()
        );
    }

    @Test
@@ -115,8 +134,12 @@ public class CatalogNotificationIntegrationTest extends BaseIT {
        // Act - Add catalog directly
        Catalog savedCatalog = productCatalogRepoService.addCatalog(catalog);

        // Assert - Verify notification was called
        verify(catalogNotificationService, timeout(1000)).publishCatalogCreateNotification(any(Catalog.class));
        // Assert - Verify notification was published to ProducerTemplate
        verify(producerTemplate, timeout(5000)).sendBodyAndHeaders(
            anyString(),
            argThat(body -> body != null && body.toString().contains("CatalogCreateNotification")),
            anyMap()
        );

        assert savedCatalog != null;
        assert savedCatalog.getName().equals("Direct Test Catalog");
+29 −24
Original line number Diff line number Diff line
package org.etsi.osl.services.api.pcm620;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
@@ -13,19 +14,16 @@ import org.etsi.osl.tmf.pcm620.model.Category;
import org.etsi.osl.tmf.pcm620.model.CategoryCreate;
import org.etsi.osl.tmf.pcm620.model.EventSubscription;
import org.etsi.osl.tmf.pcm620.model.EventSubscriptionInput;
import org.etsi.osl.tmf.pcm620.reposervices.CategoryCallbackService;
import org.etsi.osl.tmf.pcm620.reposervices.EventSubscriptionRepoService;
import org.etsi.osl.tmf.pcm620.reposervices.ProductCategoryRepoService;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -56,9 +54,6 @@ public class CategoryCallbackIntegrationTest extends BaseIT {
    @Autowired
    private EventSubscriptionRepoService eventSubscriptionRepoService;

    @SpyBean
    private CategoryCallbackService categoryCallbackService;

    @MockBean
    private RestTemplate restTemplate;

@@ -124,23 +119,27 @@ public class CategoryCallbackIntegrationTest extends BaseIT {

        Category createdCategory = productCategoryRepoService.addCategory(categoryCreate);

        // Step 3: Verify callback was sent
        verify(categoryCallbackService, timeout(2000)).sendCategoryCreateCallback(any());
        verify(restTemplate, timeout(2000)).exchange(
        // Step 3: Verify callback was sent via RestTemplate
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:8080/test-callback/listener/categoryCreateEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));

        // Step 4: Delete the category (should trigger delete callback)
        productCategoryRepoService.deleteById(createdCategory.getUuid());

        // Step 5: Verify delete callback was sent
        verify(categoryCallbackService, timeout(2000)).sendCategoryDeleteCallback(any());
        verify(restTemplate, timeout(2000)).exchange(
        // Step 5: Verify delete callback was sent via RestTemplate
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:8080/test-callback/listener/categoryDeleteEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));
    }

@@ -169,14 +168,17 @@ public class CategoryCallbackIntegrationTest extends BaseIT {
        productCategoryRepoService.deleteById(createdCategory.getUuid());

        // Step 3: Verify only create callback was sent (not delete)
        verify(restTemplate, timeout(2000)).exchange(
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:9090/create-only/listener/categoryCreateEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));

        // Note: In a more sophisticated test, we could verify that the delete callback was NOT sent
        // by using verify with never(), but this requires more complex mock setup
        // The delete callback should not be sent due to query filtering
        // (this would require explicit verification with never() and additional mock setup)
    }

    @Test
@@ -203,10 +205,13 @@ public class CategoryCallbackIntegrationTest extends BaseIT {
        Category createdCategory = productCategoryRepoService.addCategory(categoryCreate);

        // Step 3: Verify callback was sent even with empty query
        verify(restTemplate, timeout(2000)).exchange(
        verify(restTemplate, timeout(5000)).exchange(
            eq("http://localhost:7070/all-events/listener/categoryCreateEvent"),
            eq(HttpMethod.POST),
            any(HttpEntity.class), 
            argThat(httpEntity -> {
                // Verify that the HttpEntity contains event data
                return httpEntity != null && httpEntity.getBody() != null;
            }),
            eq(String.class));
    }
}
 No newline at end of file
Loading