/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2025 Nordix Foundation.
+ * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.springframework.data.domain.Example;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;
*
* @param name the name of the automation composition to get, null to get all automation compositions
* @param version the version of the automation composition to get, null to get all automation compositions
+ * @param pageable the Pageable
* @return the automation compositions found
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions(final UUID compositionId, final String name,
- final String version) {
-
- return ProviderUtils
- .asEntityList(automationCompositionRepository.findAll(createExample(compositionId, name, version)));
+ public List<AutomationComposition> getAutomationCompositions(@NonNull final UUID compositionId, final String name,
+ final String version, @NonNull final Pageable pageable) {
+ return ProviderUtils.asEntityList(automationCompositionRepository
+ .findAll(createExample(compositionId, name, version), pageable).toList());
}
private Example<JpaAutomationComposition> createExample(final UUID compositionId, final String name,
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2025 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.
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.springframework.data.domain.Example;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
class AutomationCompositionProviderTest {
assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition);
}
+ @Test
+ void testGetAutomationCompositionsWithNull() {
+ var automationCompositionProvider = new AutomationCompositionProvider(
+ mock(AutomationCompositionRepository.class), mock(AutomationCompositionElementRepository.class));
+
+ assertThatThrownBy(() -> automationCompositionProvider
+ .getAutomationCompositions(UUID.randomUUID(), null, null, null))
+ .hasMessage("pageable is marked non-null but is null");
+
+ assertThatThrownBy(() -> automationCompositionProvider
+ .getAutomationCompositions(null, null, null, Pageable.unpaged()))
+ .hasMessage("compositionId is marked non-null but is null");
+ }
+
@Test
void testGetAutomationCompositions() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ when(automationCompositionRepository
+ .findAll(Mockito.<Example<JpaAutomationComposition>>any(), any(Pageable.class)))
+ .thenReturn(new PageImpl<>(inputAutomationCompositionsJpa));
var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
- automationComposition.getName(), automationComposition.getVersion());
- assertThat(acList).isEmpty();
+ automationComposition.getName(), automationComposition.getVersion(), Pageable.unpaged());
+ assertThat(acList).hasSize(2);
- when(automationCompositionRepository.findAll(Mockito.<Example<JpaAutomationComposition>>any()))
- .thenReturn(inputAutomationCompositionsJpa);
acList = automationCompositionProvider.getAutomationCompositions(automationComposition.getCompositionId(), null,
- null);
+ null, Pageable.unpaged());
+ assertThat(acList).hasSize(2);
+
+ when(automationCompositionRepository
+ .findAll(Mockito.<Example<JpaAutomationComposition>>any(), Mockito.any(Pageable.class)))
+ .thenReturn(new PageImpl<>(inputAutomationCompositionsJpa));
+ acList = automationCompositionProvider.getAutomationCompositions(automationComposition.getCompositionId(), null,
+ null, PageRequest.of(0, 10));
assertThat(acList).hasSize(2);
}
import org.onap.policy.models.base.PfModelRuntimeException;
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;
*
* @param name the name of the automation composition to get, null for all automation compositions
* @param version the version of the automation composition to get, null for all automation compositions
+ * @param pageable the Pageable
* @return the automation compositions
*/
@Transactional(readOnly = true)
- public AutomationCompositions getAutomationCompositions(UUID compositionId, String name, String version) {
+ public AutomationCompositions getAutomationCompositions(@NonNull final UUID compositionId,
+ final String name, final String version, @NonNull final Pageable pageable) {
var automationCompositions = new AutomationCompositions();
automationCompositions.setAutomationCompositionList(
- automationCompositionProvider.getAutomationCompositions(compositionId, name, version));
+ automationCompositionProvider.getAutomationCompositions(compositionId, name, version, pageable));
return automationCompositions;
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2023,2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.springframework.context.annotation.Profile;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
*/
@Override
public ResponseEntity<AutomationCompositions> queryCompositionInstances(UUID compositionId, String name,
- String version, UUID requestId) {
-
- return ResponseEntity.ok().body(provider.getAutomationCompositions(compositionId, name, version));
+ String version, Integer page, Integer size, UUID requestId) {
+ var pageable = page != null && size != null ? PageRequest.of(page, size) : Pageable.unpaged();
+ return ResponseEntity.ok().body(provider.getAutomationCompositions(compositionId, name, version, pageable));
}
/**
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
@Override
public ResponseEntity<AutomationCompositions> queryCompositionInstances(UUID compositionId, String name,
- String version, UUID xonaprequestid) {
+ String version, Integer page, Integer size, UUID xonaprequestid) {
return stubUtils.getResponse(pathToAllInstances, AutomationCompositions.class);
}
parameter is not specified, all automation composition instances for the specified definition that match the "name" filter are are returned.
schema:
type: string
+ - name: page
+ in: query
+ required: false
+ description: Zero-based page number, must not be negative.
+ schema:
+ type: integer
+ - name: size
+ in: query
+ required: false
+ description: The size of the page to be returned, must be greater than 0.
+ schema:
+ type: integer
- name: X-onap-RequestId
in: header
description: RequestID for http transaction
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.springframework.data.domain.Pageable;
/**
* Class to perform unit test of {@link AutomationCompositionInstantiationProvider}}.
private static final String DO_NOT_MATCH = " do not match with ";
-
-
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
@BeforeAll
serviceTemplate = jpa.toAuthorative();
}
+ @Test
+ void testGetAutomationCompositionsWithNull() {
+ var instantiationProvider = new AutomationCompositionInstantiationProvider(
+ mock(AutomationCompositionProvider.class), mock(AcDefinitionProvider.class),
+ new AcInstanceStateResolver(), mock(SupervisionAcHandler.class), mock(ParticipantProvider.class),
+ CommonTestData.getTestParamaterGroup(), new EncryptionUtils(CommonTestData.getTestParamaterGroup()));
+ assertThatThrownBy(() -> instantiationProvider
+ .getAutomationCompositions(null, null, null, Pageable.unpaged()))
+ .hasMessage("compositionId is marked non-null but is null");
+ assertThatThrownBy(() -> instantiationProvider
+ .getAutomationCompositions(UUID.randomUUID(), null, null, null))
+ .hasMessage("pageable is marked non-null but is null");
+ }
+
@Test
void testInstantiationCrud() {
var acDefinitionProvider = mock(AcDefinitionProvider.class);
verify(acProvider).createAutomationComposition(automationCompositionCreate);
when(acProvider.getAutomationCompositions(compositionId, automationCompositionCreate.getName(),
- automationCompositionCreate.getVersion())).thenReturn(List.of(automationCompositionCreate));
+ automationCompositionCreate.getVersion(), Pageable.unpaged()))
+ .thenReturn(List.of(automationCompositionCreate));
var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId,
- automationCompositionCreate.getName(), automationCompositionCreate.getVersion());
+ automationCompositionCreate.getName(), automationCompositionCreate.getVersion(), Pageable.unpaged());
assertThat(automationCompositionCreate)
.isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
verify(supervisionAcHandler).migrate(any());
InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionTarget);
-
}
@Test
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2024 Nordix Foundation.
+ * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ActiveProfiles({ "test", "default" })
class InstantiationControllerTest extends CommonRestController {
+ private static final int NUMBER_ISTANCES = 10;
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
private static final String AC_VERSIONING_YAML = "src/test/resources/rest/acm/AutomationCompositionVersioning.yaml";
void testQuery_NoResultWithThisName() {
var invocationBuilder =
super.sendRequest(getInstanceEndPoint(UUID.randomUUID()) + "?name=noResultWithThisName");
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- var resp = rawresp.readEntity(AutomationCompositions.class);
- assertThat(resp.getAutomationCompositionList()).isEmpty();
+ try (var rawresp = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ var resp = rawresp.readEntity(AutomationCompositions.class);
+ assertThat(resp.getAutomationCompositionList()).isEmpty();
+ }
}
@Test
var invocationBuilder = super.sendRequest(
getInstanceEndPoint(compositionId) + "?name=" + automationComposition.getKey().getName());
- var rawresp = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- var automationCompositionsQuery = rawresp.readEntity(AutomationCompositions.class);
- assertNotNull(automationCompositionsQuery);
- assertThat(automationCompositionsQuery.getAutomationCompositionList()).hasSize(1);
- var automationCompositionRc = automationCompositionsQuery.getAutomationCompositionList().get(0);
- automationComposition.setLastMsg(automationCompositionRc.getLastMsg());
- assertEquals(automationComposition, automationCompositionRc);
+ try (var rawresp = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ var automationCompositionsQuery = rawresp.readEntity(AutomationCompositions.class);
+ assertNotNull(automationCompositionsQuery);
+ assertThat(automationCompositionsQuery.getAutomationCompositionList()).hasSize(1);
+ var automationCompositionRc = automationCompositionsQuery.getAutomationCompositionList().get(0);
+ automationComposition.setLastMsg(automationCompositionRc.getLastMsg());
+ assertEquals(automationComposition, automationCompositionRc);
+ }
+ }
+
+ @Test
+ void testQueryPageable() {
+ var compositionId = createAcDefinitionInDB("Query");
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Query");
+ automationComposition.setCompositionId(compositionId);
+ for (var i = 0; i < NUMBER_ISTANCES; i++) {
+ automationComposition.setName("acm_" + i);
+ instantiationProvider.createAutomationComposition(compositionId, automationComposition);
+ }
+ var endpoint = getInstanceEndPoint(compositionId);
+ validateQueryPageable(endpoint + "?name=wrong_name", 0);
+ validateQueryPageable(endpoint + "?name=acm_1", 1);
+ validateQueryPageable(endpoint + "?page=1&size=4", 4);
+
+ validateQueryNotPageable(endpoint + "?page=0");
+ validateQueryNotPageable(endpoint + "?size=5");
+ validateQueryNotPageable(endpoint);
+ }
+
+ private void validateQueryNotPageable(String link) {
+ var invocationBuilder = super.sendRequest(link);
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ var resultList = response.readEntity(AutomationCompositions.class);
+ assertNotNull(resultList);
+ assertThat(resultList.getAutomationCompositionList()).hasSizeGreaterThanOrEqualTo(NUMBER_ISTANCES);
+ }
+ }
+
+ private void validateQueryPageable(String link, int size) {
+ var invocationBuilder = super.sendRequest(link);
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ var resultList = response.readEntity(AutomationCompositions.class);
+ assertNotNull(resultList);
+ assertThat(resultList.getAutomationCompositionList()).hasSize(size);
+ }
}
@Test
var instResponse = resp.readEntity(InstantiationResponse.class);
InstantiationUtils.assertInstantiationResponse(instResponse, automationComposition);
- var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(compositionId,
- automationComposition.getKey().getName(), automationComposition.getKey().getVersion());
+ var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
+ compositionId, automationComposition.getKey().getName(),
+ automationComposition.getKey().getVersion(), Pageable.unpaged());
assertNotNull(automationCompositionsFromDb);
assertThat(automationCompositionsFromDb.getAutomationCompositionList()).hasSize(1);
InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc);
var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(compositionId,
- automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion());
+ automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion(),
+ Pageable.unpaged());
assertEquals(DeployState.DELETING,
automationCompositionsFromDb.getAutomationCompositionList().get(0).getDeployState());
}