/*-
* ============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.
import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
* Retrieve a list of automation composition elements associated with a participantId.
*
* @param participantId the participant id associated with the automation composition elements
+ * @param pageable the Pageable
* @return the list of associated elements
*/
- public List<AutomationCompositionElement> getAutomationCompositionElements(@NonNull final UUID participantId) {
+ public List<AutomationCompositionElement> getAutomationCompositionElements(
+ @NonNull final UUID participantId, @NonNull final Pageable pageable) {
return ProviderUtils.asEntityList(automationCompositionElementRepository
- .findByParticipantId(participantId.toString()));
+ .findByParticipantId(participantId.toString(), pageable));
}
/**
* Retrieve a list of node template states elements associated with a participantId from ac definitions.
*
* @param participantId the participant id associated with the automation composition elements
+ * @param pageable the Pageable
* @return the list of associated elements
*/
- public List<NodeTemplateState> getAcNodeTemplateStates(@NonNull final UUID participantId) {
+ public List<NodeTemplateState> getAcNodeTemplateStates(
+ @NonNull final UUID participantId, @NonNull final Pageable pageable) {
return ProviderUtils.asEntityList(nodeTemplateStateRepository
- .findByParticipantId(participantId.toString()));
+ .findByParticipantId(participantId.toString(), pageable));
}
/**
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2025 Nordix Foundation.
+ * 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.
import java.util.List;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AutomationCompositionElementRepository extends JpaRepository<JpaAutomationCompositionElement, String> {
- List<JpaAutomationCompositionElement> findByParticipantId(String participantId);
+ List<JpaAutomationCompositionElement> findByParticipantId(String participantId, Pageable pageable);
}
/*-
* ============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.
import java.util.List;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-public interface NodeTemplateStateRepository extends
- JpaRepository<JpaNodeTemplateState, String>,
- QueryByExampleExecutor<JpaNodeTemplateState> {
+public interface NodeTemplateStateRepository extends JpaRepository<JpaNodeTemplateState, String> {
List<JpaNodeTemplateState> findByParticipantId(String participantId);
+
+ List<JpaNodeTemplateState> findByParticipantId(String participantId, Pageable pageable);
}
/*-
* ============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.
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
class ParticipantProviderTest {
var acElementList = inputAutomationCompositionsJpa.get(0).getElements();
var participantId = UUID.randomUUID();
- when(automationCompositionElementRepository.findByParticipantId(participantId.toString()))
- .thenReturn(acElementList);
+ var pageable = PageRequest.of(0, 5);
+ when(automationCompositionElementRepository.findByParticipantId(participantId.toString(), pageable))
+ .thenReturn(acElementList);
- var listOfAcElements = participantProvider.getAutomationCompositionElements(participantId);
+ var listOfAcElements = participantProvider.getAutomationCompositionElements(participantId, pageable);
assertThat(listOfAcElements).hasSameSizeAs(acElementList);
assertEquals(UUID.fromString(acElementList.get(0).getElementId()), listOfAcElements.get(0).getId());
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantId = jpaParticipantList.get(0).getParticipantId();
- when(nodeTemplateStateRepository.findByParticipantId(participantId)).thenReturn(jpaNodeTemplateStateList);
+ var pageable = PageRequest.of(0, 5);
+ when(nodeTemplateStateRepository
+ .findByParticipantId(participantId, pageable)).thenReturn(jpaNodeTemplateStateList);
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository,
mock(ParticipantReplicaRepository.class));
- var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(UUID.fromString(participantId));
+ var listOfNodeTemplateState =
+ participantProvider.getAcNodeTemplateStates(UUID.fromString(participantId), pageable);
assertEquals(listOfNodeTemplateState, nodeTemplateStateList);
}
assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.saveParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
- assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null));
- assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null));
+
+ var pageable = Pageable.unpaged();
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAutomationCompositionElements(null, pageable));
+ var participantId = UUID.randomUUID();
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAutomationCompositionElements(participantId, null));
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAcNodeTemplateStates(null, pageable));
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAcNodeTemplateStates(participantId, null));
+
assertThrows(NullPointerException.class, () -> participantProvider.findParticipantReplica(null));
assertThrows(NullPointerException.class, () -> participantProvider.saveParticipantReplica(null));
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipantReplica(null));
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAutomationCompositionElements(null, pageable));
+ assertThrows(NullPointerException.class, () ->
+ participantProvider.getAutomationCompositionElements(participantId, null));
+ assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null, null));
}
@Test
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
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<ToscaServiceTemplates> queryCompositionDefinitions(String name, String version,
Integer page, Integer size, UUID requestId) {
- var pageable = page != null && size != null ? PageRequest.of(page, size) : Pageable.unpaged();
+ var pageable = getPageable(page, size);
return ResponseEntity.ok().body(provider.getAutomationCompositionDefinitions(name, version, pageable));
}
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, Integer page, Integer size, UUID requestId) {
- var pageable = page != null && size != null ? PageRequest.of(page, size) : Pageable.unpaged();
+ var pageable = getPageable(page, size);
return ResponseEntity.ok().body(provider.getAutomationCompositions(compositionId, name, version, pageable));
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 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.
private final AcmParticipantProvider acmParticipantProvider;
@Override
- public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID requestId) {
- var participantInformation = acmParticipantProvider.getParticipantById(participantId);
+ public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, Integer page, Integer size,
+ UUID requestId) {
+ var pageable = getPageable(page, size);
+ var participantInformation = acmParticipantProvider.getParticipantById(participantId, pageable);
return ResponseEntity.ok().body(participantInformation);
}
@Override
public ResponseEntity<List<ParticipantInformation>> queryParticipants(String name, String version,
- UUID requestId) {
- var participantInformationList = acmParticipantProvider.getAllParticipants();
+ Integer page, Integer size, UUID requestId) {
+ var pageable = getPageable(page, size);
+ var participantInformationList = acmParticipantProvider.getAllParticipants(pageable);
return ResponseEntity.ok().body(participantInformationList);
}
}
/*-
* ============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.
private String pathToParticipantList;
@Override
- public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID xonaprequestid) {
+ public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, Integer page, Integer size,
+ UUID xonaprequestid) {
return stubUtils.getResponse(pathToSingleParticipant, ParticipantInformation.class);
}
@Override
public ResponseEntity<List<ParticipantInformation>> queryParticipants(String name, String version,
- UUID xonaprequestid) {
+ Integer page, Integer size, UUID xonaprequestid) {
List<ParticipantInformation> participantInformationList = new ArrayList<>();
return (ResponseEntity<List<ParticipantInformation>>) stubUtils
.getResponse(pathToParticipantList, participantInformationList.getClass());
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022,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 java.net.URI;
import java.net.URISyntaxException;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
/**
throw new AutomationCompositionRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
+
+ protected Pageable getPageable(Integer page, Integer size) {
+ return page != null && size != null ? PageRequest.of(page, size) : Pageable.unpaged();
+ }
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 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.
package org.onap.policy.clamp.acm.runtime.participants;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.function.Function;
+import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.apache.commons.collections4.MapUtils;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantStatusReqPublisher;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
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;
/**
* Get all participants.
*
+ * @param pageable the Pageable
* @return A list of available participants
*/
- public List<ParticipantInformation> getAllParticipants() {
+ public List<ParticipantInformation> getAllParticipants(final Pageable pageable) {
var participants = this.participantProvider.getParticipants();
+ return participants.stream().map(participant -> createParticipantInformation(participant, pageable)).toList();
+ }
- List<ParticipantInformation> participantInformationList = new ArrayList<>();
- participants.forEach(participant -> {
- ParticipantInformation participantInformation = new ParticipantInformation();
- participantInformation.setParticipant(participant);
- participantInformation.setAcElementInstanceMap(getAutomationCompositionElementsForParticipant(participant
- .getParticipantId()));
- participantInformation.setAcNodeTemplateStateDefinitionMap(getNodeTemplateStatesForParticipant(participant
- .getParticipantId()));
- participantInformationList.add(participantInformation);
- });
- return participantInformationList;
+ private ParticipantInformation createParticipantInformation(Participant participant, Pageable pageable) {
+ var participantInformation = new ParticipantInformation();
+ participantInformation.setParticipant(participant);
+ participantInformation.setAcElementInstanceMap(
+ getAcElementsForParticipant(participant.getParticipantId(), pageable));
+ participantInformation.setAcNodeTemplateStateDefinitionMap(
+ getNodeTemplateStatesForParticipant(participant.getParticipantId(), pageable));
+ return participantInformation;
}
/**
* Get a participant.
*
* @param participantId The UUID of the participant to get
+ * @param pageable the Pageable
* @return The participant
*/
- public ParticipantInformation getParticipantById(UUID participantId) {
+ public ParticipantInformation getParticipantById(final UUID participantId, final Pageable pageable) {
var participant = this.participantProvider.getParticipantById(participantId);
- var participantInformation = new ParticipantInformation();
- participantInformation.setParticipant(participant);
-
- participantInformation.setAcElementInstanceMap(getAutomationCompositionElementsForParticipant(participantId));
- participantInformation.setAcNodeTemplateStateDefinitionMap(getNodeTemplateStatesForParticipant(participantId));
-
- return participantInformation;
+ return createParticipantInformation(participant, pageable);
}
/**
this.participantStatusReqPublisher.send((UUID) null);
}
- private Map<UUID, AutomationCompositionElement> getAutomationCompositionElementsForParticipant(UUID participantId) {
- var automationCompositionElements = participantProvider
- .getAutomationCompositionElements(participantId);
- Map<UUID, AutomationCompositionElement> map = new HashMap<>();
- MapUtils.populateMap(map, automationCompositionElements, AutomationCompositionElement::getId);
-
- return map;
+ private Map<UUID, AutomationCompositionElement> getAcElementsForParticipant(UUID participantId, Pageable pageable) {
+ var automationCompositionElements =
+ participantProvider.getAutomationCompositionElements(participantId, pageable);
+ return automationCompositionElements
+ .stream().collect(Collectors.toMap(AutomationCompositionElement::getId, Function.identity()));
}
- private Map<UUID, NodeTemplateState> getNodeTemplateStatesForParticipant(UUID participantId) {
- var acNodeTemplateStates = participantProvider.getAcNodeTemplateStates(participantId);
- Map<UUID, NodeTemplateState> map = new HashMap<>();
- MapUtils.populateMap(map, acNodeTemplateStates, NodeTemplateState::getNodeTemplateStateId);
-
- return map;
+ private Map<UUID, NodeTemplateState> getNodeTemplateStatesForParticipant(UUID participantId, Pageable pageable) {
+ var acNodeTemplateStates = participantProvider.getAcNodeTemplateStates(participantId, pageable);
+ return acNodeTemplateStates
+ .stream().collect(Collectors.toMap(NodeTemplateState::getNodeTemplateStateId, Function.identity()));
}
}
parameter is not specified, all automation composition definitions 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
schema:
type: string
format: uuid
+ - 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
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2024 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.
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.GenericType;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.onap.policy.clamp.acm.runtime.instantiation.AutomationCompositionInstantiationProvider;
+import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.main.rest.ParticipantController;
+import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantInformation;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
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.resources.ResourceUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
@ActiveProfiles({ "test", "default" })
class ParticipantControllerTest extends CommonRestController {
private static final String PARTICIPANTS_ENDPOINT = "participants";
+ private static final int NUMBER_RECORDS = 10;
+
+ @Autowired
+ private AcDefinitionProvider acDefinitionProvider;
+
+ @Autowired
+ private AutomationCompositionInstantiationProvider instantiationProvider;
@LocalServerPort
private int randomServerPort;
private static final Coder CODER = new StandardCoder();
private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
private static final String PARTICIPANT_JSON2 = "src/test/resources/providers/TestParticipant2.json";
-
+ private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
+ private static final String NODE_TYPE = "org.onap.policy.clamp.acm.AutomationComposition";
+ private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+ private static AutomationComposition automationComposition = new AutomationComposition();
private static final List<Participant> inputParticipants = new ArrayList<>();
private static final String ORIGINAL_JSON = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
private static final String ORIGINAL_JSON2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
public static void setUpBeforeClass() throws CoderException {
inputParticipants.add(CODER.decode(ORIGINAL_JSON, Participant.class));
inputParticipants.add(CODER.decode(ORIGINAL_JSON2, Participant.class));
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Query");
}
@BeforeEach
@Test
void testQueryParticipant() {
- participantProvider.saveParticipant(inputParticipants.get(0));
- var participantId = participantProvider.getParticipants().get(0).getParticipantId();
- var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participantId);
+ var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
+ var replica = CommonTestData.createParticipantReplica(CommonTestData.getParticipantId());
+ participant.getReplicas().put(replica.getReplicaId(), replica);
+ participantProvider.saveParticipant(participant);
+ for (var i = 0; i < NUMBER_RECORDS; i++) {
+ createAcDefinitionInDB("QueryParticipant" + i);
+ }
+ // valid pagination
+ validateParticipantPageable("?page=1&size=4", 4);
+
+ // not valid pagination
+ validateParticipantNotPageable("?page=0", NUMBER_RECORDS);
+ validateParticipantNotPageable("?size=5", NUMBER_RECORDS);
+ validateParticipantNotPageable("", NUMBER_RECORDS);
+ }
+
+ private void validateParticipantPageable(String url, int size) {
+ var participantInfo = getParticipantInformation(url);
+ assertThat(participantInfo.getAcNodeTemplateStateDefinitionMap()).hasSize(size);
+ assertThat(participantInfo.getAcElementInstanceMap()).hasSize(size);
+ }
+
+ private void validateParticipantNotPageable(String url, int size) {
+ var participantInfo = getParticipantInformation(url);
+ assertThat(participantInfo.getAcNodeTemplateStateDefinitionMap()).hasSizeGreaterThanOrEqualTo(size);
+ assertThat(participantInfo.getAcElementInstanceMap()).hasSizeGreaterThanOrEqualTo(size);
+ }
+
+ private ParticipantInformation getParticipantInformation(String url) {
+ var invocationBuilder = super.sendRequest(
+ PARTICIPANTS_ENDPOINT + "/" + CommonTestData.getParticipantId() + url);
try (var response = invocationBuilder.buildGet().invoke()) {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- var entityList = response.readEntity(ParticipantInformation.class);
- assertNotNull(entityList);
+ var participantInfo = response.readEntity(ParticipantInformation.class);
+ assertNotNull(participantInfo);
+ return participantInfo;
}
}
@Test
void getAllParticipants() {
- inputParticipants.forEach(p -> participantProvider.saveParticipant(p));
+ inputParticipants.forEach(participantProvider::saveParticipant);
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
try (var response = invocationBuilder.buildGet().invoke()) {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
+ List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {
+ });
assertThat(entityList).isNotEmpty();
var participantIds =
entityList.stream().map(ParticipantInformation::getParticipant).map(Participant::getParticipantId)
.collect(Collectors.toSet());
inputParticipants.forEach(p -> assertThat(participantIds).contains(p.getParticipantId()));
}
+ var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
+ var replica = CommonTestData.createParticipantReplica(CommonTestData.getParticipantId());
+ participant.getReplicas().put(replica.getReplicaId(), replica);
+ participantProvider.saveParticipant(participant);
+ for (var i = 0; i < NUMBER_RECORDS; i++) {
+ createAcDefinitionInDB("AllParticipants" + i);
+ }
+ // valid pagination
+ validateAllParticipantsPageable("?page=1&size=4", 4);
+
+ // not valid pagination
+ validateAllParticipantsNotPageable("?page=0", NUMBER_RECORDS);
+ validateAllParticipantsNotPageable("?size=5", NUMBER_RECORDS);
+ validateAllParticipantsNotPageable("", NUMBER_RECORDS);
+ }
+
+ private void validateAllParticipantsNotPageable(String url, int size) {
+ var participantInfo = getFirstParticipantInformation(url);
+ assertThat(participantInfo.getAcNodeTemplateStateDefinitionMap()).hasSizeGreaterThanOrEqualTo(size);
+ assertThat(participantInfo.getAcElementInstanceMap()).hasSizeGreaterThanOrEqualTo(size);
+ }
+
+ private void validateAllParticipantsPageable(String url, int size) {
+ var participantInfo = getFirstParticipantInformation(url);
+ assertThat(participantInfo.getAcNodeTemplateStateDefinitionMap()).hasSize(size);
+ assertThat(participantInfo.getAcElementInstanceMap()).hasSize(size);
+ }
+
+ private ParticipantInformation getFirstParticipantInformation(String url) {
+ var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + url);
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
+ var participantInfoOpt = entityList.stream()
+ .filter(p -> CommonTestData.getParticipantId().equals(p.getParticipant().getParticipantId()))
+ .findFirst();
+ assertThat(participantInfoOpt).isPresent();
+ return participantInfoOpt.get();
+ }
+ }
+
+ private void createAcDefinitionInDB(String name) {
+ var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate);
+ serviceTemplateCreate.setName(name);
+ var acmDefinition = CommonTestData.createAcDefinition(serviceTemplateCreate, AcTypeState.PRIMED);
+ acDefinitionProvider.updateAcDefinition(acmDefinition, NODE_TYPE);
+ var automationCompositionCreate = new AutomationComposition(automationComposition);
+ automationCompositionCreate.setCompositionId(acmDefinition.getCompositionId());
+ automationCompositionCreate.setName(acmDefinition.getServiceTemplate().getName());
+ var elements = new ArrayList<>(automationCompositionCreate.getElements().values());
+ automationCompositionCreate.getElements().clear();
+ for (var element : elements) {
+ element.setId(UUID.randomUUID());
+ automationCompositionCreate.getElements().put(element.getId(), element);
+ }
+ instantiationProvider
+ .createAutomationComposition(acmDefinition.getCompositionId(), automationCompositionCreate);
}
@Test
+ "/"
+ participantId);
try (var response = invocationBuilder.header("Content-Length", 0)
- .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
}
}
+ "/"
+ UUID.randomUUID());
try (var response = invocationBuilder.header("Content-Length", 0)
- .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
}
}
@Test
void testOrderAllParticipantReport() {
- inputParticipants.forEach(p -> {
- participantProvider.saveParticipant(p);
- });
+ inputParticipants.forEach(participantProvider::saveParticipant);
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
try (var response = invocationBuilder.header("Content-Length", 0)
- .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
}
}