package org.onap.policy.clamp.models.acm.persistence.concepts;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
import javax.persistence.CascadeType;
import javax.persistence.Column;
-import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
+import javax.persistence.ForeignKey;
+import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
-import javax.persistence.ManyToMany;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
-import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.validation.annotations.VerifyKey;
+import org.onap.policy.models.base.Validated;
/**
* Class to represent a automation composition in the database.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationComposition extends PfConcept implements PfAuthorative<AutomationComposition> {
- private static final long serialVersionUID = -4725410933242154805L;
+public class JpaAutomationComposition extends Validated
+ implements PfAuthorative<AutomationComposition>, Comparable<JpaAutomationComposition> {
- @Column
+ @Id
@NotNull
private String instanceId;
- @EmbeddedId
- @VerifyKey
@NotNull
- private PfConceptKey key;
+ @Column
+ private String name;
+
+ @NotNull
+ @Column
+ private String version;
@Column
@NotNull
@Column
private Boolean primed;
- @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@NotNull
- private Map<@NotNull UUID, @NotNull @Valid JpaAutomationCompositionElement> elements;
- // @formatter:on
+ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
+ @JoinColumn(name = "instanceId", foreignKey = @ForeignKey(name = "ac_element_fk"))
+ private List<@NotNull @Valid JpaAutomationCompositionElement> elements;
/**
* The Default Constructor creates a {@link JpaAutomationComposition} object with a null key.
*/
public JpaAutomationComposition() {
this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(),
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
+ AutomationCompositionState.UNINITIALISED, new ArrayList<>());
}
/**
*/
public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key,
@NonNull final String compositionId, @NonNull final AutomationCompositionState state,
- @NonNull final Map<UUID, JpaAutomationCompositionElement> elements) {
+ @NonNull final List<JpaAutomationCompositionElement> elements) {
this.instanceId = instanceId;
- this.key = key;
+ this.name = key.getName();
+ this.version = key.getVersion();
this.compositionId = compositionId;
this.state = state;
this.elements = elements;
* @param copyConcept the concept to copy from
*/
public JpaAutomationComposition(@NonNull final JpaAutomationComposition copyConcept) {
- super(copyConcept);
this.instanceId = copyConcept.instanceId;
- this.key = new PfConceptKey(copyConcept.key);
+ this.name = copyConcept.name;
+ this.version = copyConcept.version;
this.compositionId = copyConcept.compositionId;
this.state = copyConcept.state;
this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
- this.elements =
- PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0));
+ this.elements = PfUtils.mapList(copyConcept.elements, JpaAutomationCompositionElement::new);
this.primed = copyConcept.primed;
}
var automationComposition = new AutomationComposition();
automationComposition.setInstanceId(UUID.fromString(instanceId));
- automationComposition.setName(getKey().getName());
- automationComposition.setVersion(getKey().getVersion());
+ automationComposition.setName(name);
+ automationComposition.setVersion(version);
automationComposition.setCompositionId(UUID.fromString(compositionId));
automationComposition.setState(state);
automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
automationComposition.setDescription(description);
- automationComposition.setElements(
- PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0)));
automationComposition.setPrimed(primed);
+ automationComposition.setElements(new LinkedHashMap<>(this.elements.size()));
+ for (var element : this.elements) {
+ automationComposition.getElements().put(UUID.fromString(element.getElementId()), element.toAuthorative());
+ }
return automationComposition;
}
@Override
public void fromAuthorative(@NonNull final AutomationComposition automationComposition) {
this.instanceId = automationComposition.getInstanceId().toString();
- if (this.key == null || this.getKey().isNullKey()) {
- this.setKey(new PfConceptKey(automationComposition.getName(), automationComposition.getVersion()));
- }
-
+ this.name = automationComposition.getName();
+ this.version = automationComposition.getVersion();
this.compositionId = automationComposition.getCompositionId().toString();
this.state = automationComposition.getState();
this.orderedState = automationComposition.getOrderedState();
this.description = automationComposition.getDescription();
this.primed = automationComposition.getPrimed();
- this.elements = new LinkedHashMap<>(automationComposition.getElements().size());
+ this.elements = new ArrayList<>(automationComposition.getElements().size());
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var jpaAutomationCompositionElement = new JpaAutomationCompositionElement();
- jpaAutomationCompositionElement
- .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString()));
+ var jpaAutomationCompositionElement =
+ new JpaAutomationCompositionElement(elementEntry.getKey().toString(), this.instanceId);
jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue());
- this.elements.put(elementEntry.getKey(), jpaAutomationCompositionElement);
- }
- }
-
- @Override
- public List<PfKey> getKeys() {
- var keyList = getKey().getKeys();
-
- for (var element : elements.values()) {
- keyList.addAll(element.getKeys());
- }
-
- return keyList;
- }
-
- @Override
- public void clean() {
- key.clean();
- description = (description == null ? null : description.trim());
-
- for (var element : elements.values()) {
- element.clean();
+ this.elements.add(jpaAutomationCompositionElement);
}
}
@Override
- public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
+ public int compareTo(final JpaAutomationComposition other) {
+ if (other == null) {
return -1;
}
- if (this == otherConcept) {
+ if (this == other) {
return 0;
}
- if (getClass() != otherConcept.getClass()) {
- return this.getClass().getName().compareTo(otherConcept.getClass().getName());
- }
- final var other = (JpaAutomationComposition) otherConcept;
var result = ObjectUtils.compare(instanceId, other.instanceId);
if (result != 0) {
return result;
}
- result = key.compareTo(other.key);
+ result = ObjectUtils.compare(name, other.name);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(version, other.version);
if (result != 0) {
return result;
}
package org.onap.policy.clamp.models.acm.persistence.concepts;
import java.util.LinkedHashMap;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.UnaryOperator;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Convert;
-import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Lob;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
-import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.Validated;
import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaAutomationCompositionElement extends PfConcept implements PfAuthorative<AutomationCompositionElement> {
- private static final long serialVersionUID = -1791732273187890213L;
+public class JpaAutomationCompositionElement extends Validated
+ implements PfAuthorative<AutomationCompositionElement>, Comparable<JpaAutomationCompositionElement> {
- @EmbeddedId
- @VerifyKey
+ @Id
@NotNull
- private PfReferenceKey key;
+ private String elementId;
+
+ @Column
+ @NotNull
+ private String instanceId;
// @formatter:off
@VerifyKey
* The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
*/
public JpaAutomationCompositionElement() {
- this(new PfReferenceKey());
+ this(UUID.randomUUID().toString(), UUID.randomUUID().toString());
}
/**
* The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key.
*
- * @param key the key
+ * @param elementId The id of the automation composition instance Element
+ * @param instanceId The id of the automation composition instance
*/
- public JpaAutomationCompositionElement(@NonNull final PfReferenceKey key) {
- this(key, new PfConceptKey(), new PfConceptKey(), AutomationCompositionState.UNINITIALISED);
+ public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
+ this(elementId, instanceId, new PfConceptKey(), new PfConceptKey(), AutomationCompositionState.UNINITIALISED);
}
/**
* The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields.
*
- * @param key the key
+ * @param elementId The id of the automation composition instance Element
+ * @param instanceId The id of the automation composition instance
* @param definition the TOSCA definition of the automation composition element
* @param participantType the TOSCA definition of the participant running the automation composition element
* @param state the state of the automation composition
*/
- public JpaAutomationCompositionElement(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey definition,
- @NonNull final PfConceptKey participantType, @NonNull final AutomationCompositionState state) {
- this.key = key;
+ public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
+ @NonNull final PfConceptKey definition, @NonNull final PfConceptKey participantType,
+ @NonNull final AutomationCompositionState state) {
+ this.elementId = elementId;
+ this.instanceId = instanceId;
this.definition = definition;
this.participantType = participantType;
this.state = state;
* @param copyConcept the concept to copy from
*/
public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) {
- super(copyConcept);
- this.key = new PfReferenceKey(copyConcept.key);
+ this.elementId = copyConcept.elementId;
+ this.instanceId = copyConcept.instanceId;
this.definition = new PfConceptKey(copyConcept.definition);
this.participantType = new PfConceptKey(copyConcept.participantType);
this.participantId = new PfConceptKey(copyConcept.participantId);
public AutomationCompositionElement toAuthorative() {
var element = new AutomationCompositionElement();
- element.setId(UUID.fromString(getKey().getLocalName()));
+ element.setId(UUID.fromString(elementId));
element.setDefinition(new ToscaConceptIdentifier(definition));
element.setParticipantType(new ToscaConceptIdentifier(participantType));
element.setParticipantId(new ToscaConceptIdentifier(participantId));
@Override
public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
- if (this.key == null || this.getKey().isNullKey()) {
- this.setKey(new PfReferenceKey());
- getKey().setLocalName(element.getId().toString());
- }
-
this.definition = element.getDefinition().asConceptKey();
this.participantType = element.getParticipantType().asConceptKey();
this.participantId = element.getParticipantId().asConceptKey();
}
@Override
- public List<PfKey> getKeys() {
- List<PfKey> keyList = getKey().getKeys();
-
- keyList.add(definition);
- keyList.add(participantType);
- keyList.add(participantId);
-
- return keyList;
- }
-
- @Override
- public void clean() {
- key.clean();
- definition.clean();
- participantType.clean();
- participantId.clean();
-
- if (description != null) {
- description = description.trim();
- }
- }
-
- @Override
- public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
+ public int compareTo(final JpaAutomationCompositionElement other) {
+ if (other == null) {
return -1;
}
- if (this == otherConcept) {
+ if (this == other) {
return 0;
}
- if (getClass() != otherConcept.getClass()) {
- return this.getClass().getName().compareTo(otherConcept.getClass().getName());
+
+ var result = ObjectUtils.compare(elementId, other.elementId);
+ if (result != 0) {
+ return result;
}
- final JpaAutomationCompositionElement other = (JpaAutomationCompositionElement) otherConcept;
- int result = key.compareTo(other.key);
+ result = ObjectUtils.compare(instanceId, other.instanceId);
if (result != 0) {
return result;
}
import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import javax.persistence.EntityNotFoundException;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import lombok.AllArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
-import org.onap.policy.models.base.PfConceptKey;
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.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
*/
@Transactional(readOnly = true)
public AutomationComposition getAutomationComposition(final UUID instanceId) {
- var result = automationCompositionRepository.findByInstanceId(instanceId.toString());
+ var result = automationCompositionRepository.findById(instanceId.toString());
if (result.isEmpty()) {
throw new PfModelRuntimeException(Status.NOT_FOUND, "AutomationComposition not found");
}
return result.get().toAuthorative();
}
- /**
- * Get automation composition.
- *
- * @param automationCompositionId the ID of the automation composition to get
- * @return the automation composition found
- */
- @Transactional(readOnly = true)
- public AutomationComposition getAutomationComposition(final ToscaConceptIdentifier automationCompositionId) {
- try {
- return automationCompositionRepository.getById(automationCompositionId.asConceptKey()).toAuthorative();
- } catch (EntityNotFoundException e) {
- throw new PfModelRuntimeException(Status.NOT_FOUND, "AutomationComposition not found", e);
- }
- }
-
/**
* Find automation composition.
*
*/
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(final UUID instanceId) {
- var result = automationCompositionRepository.findByInstanceId(instanceId.toString());
+ var result = automationCompositionRepository.findById(instanceId.toString());
return result.stream().map(JpaAutomationComposition::toAuthorative).findFirst();
}
@Transactional(readOnly = true)
public Optional<AutomationComposition> findAutomationComposition(
final ToscaConceptIdentifier automationCompositionId) {
- return findAutomationComposition(automationCompositionId.asConceptKey());
- }
-
- private Optional<AutomationComposition> findAutomationComposition(@NonNull final PfConceptKey key) {
- return automationCompositionRepository.findById(key).map(JpaAutomationComposition::toAuthorative);
+ return automationCompositionRepository
+ .findOne(createExample(null, automationCompositionId.getName(), automationCompositionId.getVersion()))
+ .map(JpaAutomationComposition::toAuthorative);
}
/**
* @return the automation compositions found
*/
@Transactional(readOnly = true)
- public List<AutomationComposition> getAutomationCompositions(final String name, final String version) {
+ public List<AutomationComposition> getAutomationCompositions(final UUID compositionId, final String name,
+ final String version) {
+
+ return ProviderUtils
+ .asEntityList(automationCompositionRepository.findAll(createExample(compositionId, name, version)));
+ }
- return ProviderUtils.asEntityList(
- automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version));
+ private Example<JpaAutomationComposition> createExample(final UUID compositionId, final String name,
+ final String version) {
+ var example = new JpaAutomationComposition();
+ example.setCompositionId(compositionId != null ? compositionId.toString() : null);
+ example.setName(name);
+ example.setVersion(version);
+ example.setInstanceId(null);
+ example.setElements(null);
+ example.setState(null);
+
+ return Example.of(example);
}
/**
* @return the automation composition deleted
*/
public AutomationComposition deleteAutomationComposition(@NonNull final UUID instanceId) {
- var jpaDeleteAutomationComposition = automationCompositionRepository.findByInstanceId(instanceId.toString());
+ var jpaDeleteAutomationComposition = automationCompositionRepository.findById(instanceId.toString());
if (jpaDeleteAutomationComposition.isEmpty()) {
var errorMessage = "delete of automation composition \"" + instanceId
+ "\" failed, automation composition does not exist";
throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage);
}
- automationCompositionRepository.deleteById(jpaDeleteAutomationComposition.get().getKey());
+ automationCompositionRepository.deleteById(instanceId.toString());
return jpaDeleteAutomationComposition.get().toAuthorative();
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import lombok.NoArgsConstructor;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfAuthorative;
-import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.Validated;
* @param conceptDescription the description used for validation result
* @return the list of Jpa objects
*/
- public static <A, J extends PfConcept & PfAuthorative<A>> List<J> getJpaAndValidateList(
+ public static <A, J extends Validated & PfAuthorative<A>> List<J> getJpaAndValidateList(
List<A> authorativeConceptList, Supplier<J> jpaSupplier, String conceptDescription) {
var validationResult = new BeanValidationResult(conceptDescription + " List", authorativeConceptList);
package org.onap.policy.clamp.models.acm.persistence.repository;
import java.util.List;
-import java.util.Optional;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
-import org.onap.policy.models.base.PfConceptKey;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionRepository
- extends JpaRepository<JpaAutomationComposition, PfConceptKey>, FilterRepository {
-
- Optional<JpaAutomationComposition> findByInstanceId(String instanceId);
+ extends JpaRepository<JpaAutomationComposition, String>, QueryByExampleExecutor<JpaAutomationComposition> {
List<JpaAutomationComposition> findByCompositionId(String compositionId);
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* 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.models.base.PfConcept;
-import org.onap.policy.models.dao.PfFilterParametersIntfc;
public interface FilterRepository {
- /**
- * Get an object from the database, referred to by concept key.
- *
- * @param <T> the type of the object to get, a subclass of {@link PfConcept}
- * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts
- * of type T are returned, if name is not null and version is null, all versions of that concept matching the
- * name are returned.
- * @param filterParams filter parameters
- * @return the objects that was retrieved from the database
- */
- <T extends PfConcept> List<T> getFiltered(Class<T> someClass, PfFilterParametersIntfc filterParams);
-
/**
* Get an object from the database, referred to by concept key.
*
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import javax.persistence.PersistenceContext;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.dao.PfFilterParametersIntfc;
import org.onap.policy.models.dao.impl.ProxyDao;
import org.springframework.stereotype.Repository;
return new ProxyDao(entityManager);
}
- @Override
- public <T extends PfConcept> List<T> getFiltered(Class<T> someClass, PfFilterParametersIntfc filterParams) {
- return getPfDao().getFiltered(someClass, filterParams);
- }
-
@Override
public <T extends PfConcept> List<T> getFiltered(Class<T> someClass, String name, String version) {
return getPfDao().getFiltered(someClass, name, version);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* 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.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
- * Test the {@link JpaAutomationCompositionElement} class.
+ * Test the{@link JpaAutomationCompositionElement} class.
*/
class JpaAutomationCompositionElementTest {
- private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+ private static final String NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";
+ private static final String NULL_ELEMENT_ID_ERROR = "elementId is marked .*ull but is null";
+ private static final String NULL_ERROR = " is marked .*ull but is null";
+ private static final String ELEMENT_ID = "a95757ba-b34a-4049-a2a8-46773abcbe5e";
+ private static final String INSTANCE_ID = "a78757co-b34a-8949-a2a8-46773abcbe2a";
@Test
void testJpaAutomationCompositionElementConstructor() {
}).hasMessageMatching("copyConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement((PfReferenceKey) null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", null);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, "key");
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, null);
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement(null, null, null, null, null);
+ }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", null, null, null, AutomationCompositionState.UNINITIALISED);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", "key", null, new PfConceptKey("participant", "0.0.1"), null);
+ }).hasMessageMatching("definition" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), null,
+ AutomationCompositionState.UNINITIALISED);
+ }).hasMessageMatching("participantType" + NULL_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"),
- null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, null);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"),
- null);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"),
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("definition is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, null);
- }).hasMessageMatching("participantType is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED);
- }).hasMessageMatching("participantType is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(),
- new PfConceptKey("participant", "0.0.1"), null);
- }).hasMessageMatching("state is marked .*ull but is null");
+ new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), new PfConceptKey(), null);
+ }).hasMessageMatching("state" + NULL_ERROR);
assertNotNull(new JpaAutomationCompositionElement());
- assertNotNull(new JpaAutomationCompositionElement((new PfReferenceKey())));
- assertNotNull(new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(),
- new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED));
+ assertNotNull(new JpaAutomationCompositionElement("key", "key"));
+ assertNotNull(new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
+ new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED));
}
@Test
void testJpaAutomationCompositionElement() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAcElement = createJpaAutomationCompositionElementInstance();
var ace = createAutomationCompositionElementInstance();
- assertEquals(ace, testJpaAutomationCompositionElement.toAuthorative());
+ assertEquals(ace, testJpaAcElement.toAuthorative());
assertThatThrownBy(() -> {
- testJpaAutomationCompositionElement.fromAuthorative(null);
+ testJpaAcElement.fromAuthorative(null);
}).hasMessageMatching("element is marked .*ull but is null");
assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null))
- .isInstanceOf(NullPointerException.class);
-
- var testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement();
- testJpaAutomationCompositionElementFa.setKey(null);
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
- testJpaAutomationCompositionElementFa.setKey(PfReferenceKey.getNullKey());
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
- testJpaAutomationCompositionElementFa.setKey(
- new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
- testJpaAutomationCompositionElementFa.fromAuthorative(ace);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa);
-
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- testJpaAutomationCompositionElement.getKey().getLocalName());
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()).getKey().getLocalName());
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- ((PfReferenceKey) new JpaAutomationCompositionElement(createAutomationCompositionElementInstance())
- .getKeys().get(0)).getLocalName());
-
- testJpaAutomationCompositionElement.clean();
- assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e",
- testJpaAutomationCompositionElement.getKey().getLocalName());
-
- testJpaAutomationCompositionElement.setDescription(" A Message ");
- testJpaAutomationCompositionElement.clean();
- assertEquals("A Message", testJpaAutomationCompositionElement.getDescription());
-
- var testJpaAutomationCompositionElement2 =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
- assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElement2);
+ .isInstanceOf(NullPointerException.class);
+
+ var testJpaAcElementFa =
+ new JpaAutomationCompositionElement(ace.getId().toString(), testJpaAcElement.getInstanceId());
+ testJpaAcElementFa.fromAuthorative(ace);
+ assertEquals(testJpaAcElement, testJpaAcElementFa);
+
+ assertEquals(ELEMENT_ID, testJpaAcElement.getElementId());
+
+ var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
}
@Test
void testJpaAutomationCompositionElementOrderedState() throws CoderException {
var testAutomationCompositionElement = createAutomationCompositionElementInstance();
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
testJpaAutomationCompositionElement.setOrderedState(null);
assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative());
testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
var noOrderedStateAce = new StandardCoder().decode(
- new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
- AutomationCompositionElement.class);
+ new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
+ AutomationCompositionElement.class);
var noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
assertNull(noOrderedStateJpaAce.getOrderedState());
noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
+ noOrderedStateJpaAce.setInstanceId(testJpaAutomationCompositionElement.getInstanceId());
+ noOrderedStateJpaAce.setElementId(testJpaAutomationCompositionElement.getElementId());
assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce);
}
@Test
void testJpaAutomationCompositionElementValidation() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
assertThatThrownBy(() -> testJpaAutomationCompositionElement.validate(null))
- .hasMessageMatching("fieldName is marked .*ull but is null");
+ .hasMessageMatching("fieldName is marked .*ull but is null");
assertTrue(testJpaAutomationCompositionElement.validate("").isValid());
}
@Test
void testJpaAutomationCompositionElementCompareTo() {
- var testJpaAutomationCompositionElement =
- createJpaAutomationCompositionElementInstance();
+ var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
var otherJpaAutomationCompositionElement =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
+ new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement));
assertNotEquals(0,
- testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
+ testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
- testJpaAutomationCompositionElement
- .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ testJpaAutomationCompositionElement.setElementId("BadValue");
assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setKey(
- new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ testJpaAutomationCompositionElement.setElementId(ELEMENT_ID);
+ assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
+
+ testJpaAutomationCompositionElement.setInstanceId("BadValue");
+ assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
+ testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
assertEquals(testJpaAutomationCompositionElement,
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
+ new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
}
@Test
assertEquals(ace0, ace0);
assertNotEquals(null, ace0);
- var ace1 = new JpaAutomationCompositionElement();
+ var ace1 = new JpaAutomationCompositionElement(ace0.getElementId(), ace0.getInstanceId());
ace1.setDefinition(new PfConceptKey("defName", "0.0.1"));
ace1.setDescription("Description");
assertNotEquals(ace1, ace0);
- var ace2 = new JpaAutomationCompositionElement();
+ var ace2 = new JpaAutomationCompositionElement(ace0.getElementId(), ace0.getInstanceId());
assertEquals(ace2, ace0);
}
private JpaAutomationCompositionElement createJpaAutomationCompositionElementInstance() {
var testAce = createAutomationCompositionElementInstance();
- var testJpaAutomationCompositionElement = new JpaAutomationCompositionElement();
- testJpaAutomationCompositionElement.setKey(null);
- testJpaAutomationCompositionElement.fromAuthorative(testAce);
- testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey());
- testJpaAutomationCompositionElement.fromAuthorative(testAce);
- testJpaAutomationCompositionElement.setProperties(Map.of("key", "{}"));
-
- return testJpaAutomationCompositionElement;
+ var testJpaAcElement =
+ new JpaAutomationCompositionElement(testAce.getId().toString(), INSTANCE_ID);
+ testJpaAcElement.fromAuthorative(testAce);
+ testJpaAcElement.setProperties(Map.of("key", "{}"));
+
+ return testJpaAcElement;
}
private AutomationCompositionElement createAutomationCompositionElementInstance() {
var automationCompositionElement = new AutomationCompositionElement();
- automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
+ automationCompositionElement.setId(UUID.fromString(ELEMENT_ID));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
automationCompositionElement.setProperties(Map.of("key", "{}"));
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* 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.persistence.concepts;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.models.base.PfConceptKey;
/**
- * Test the {@link JpaAutomationCompositionTest} class.
+ * Test the{@link JpaAutomationCompositionTest} class.
*/
class JpaAutomationCompositionTest {
- private static final String NULL_KEY_ERROR = "instanceId is marked .*ull but is null";
- private static final UUID INSTANCE_ID = UUID.fromString("709c62b3-8918-41b9-a747-d21eb79c6c20");
+ private static final String NULL_INSTANCE_ID_ERROR = "instanceId is marked .*ull but is null";
+ private static final String NULL_TEXT_ERROR = " is marked .*ull but is null";
+ private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c20";
private static final String COMPOSITION_ID = "709c62b3-8918-41b9-a747-e21eb79c6c41";
@Test
assertThatThrownBy(() -> {
new JpaAutomationComposition(null, null, null, null, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
+ }).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, null, new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
+ new JpaAutomationComposition(INSTANCE_ID, null, null, null, new ArrayList<>());
+ }).hasMessageMatching("key" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", null, new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, "key", AutomationCompositionState.UNINITIALISED,
- new LinkedHashMap<>());
- }).hasMessageMatching(NULL_KEY_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, null);
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null, null, new LinkedHashMap<>());
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null,
AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching("compositionId is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>());
- }).hasMessageMatching("compositionId is marked .*ull but is null");
+ }).hasMessageMatching("compositionId" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null, null);
- }).hasMessageMatching("state is marked .*ull but is null");
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null, null);
+ }).hasMessageMatching("state" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key", null,
- new LinkedHashMap<>());
- }).hasMessageMatching("state is marked .*ull but is null");
-
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
+ new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
AutomationCompositionState.UNINITIALISED, null);
- }).hasMessageMatching("elements is marked .*ull but is null");
+ }).hasMessageMatching("elements" + NULL_TEXT_ERROR);
assertNotNull(new JpaAutomationComposition());
- assertNotNull(new JpaAutomationComposition(INSTANCE_ID.toString(), new PfConceptKey(), "key",
- AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()));
+ assertNotNull(new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
+ AutomationCompositionState.UNINITIALISED, new ArrayList<>()));
}
@Test
.isInstanceOf(NullPointerException.class);
var testJpaAutomationCompositionFa = new JpaAutomationComposition();
- testJpaAutomationCompositionFa.setKey(null);
- testJpaAutomationCompositionFa.fromAuthorative(participant);
- assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- testJpaAutomationCompositionFa.setKey(PfConceptKey.getNullKey());
- testJpaAutomationCompositionFa.fromAuthorative(participant);
- assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- testJpaAutomationCompositionFa.setKey(new PfConceptKey("automation-composition", "0.0.1"));
+ testJpaAutomationCompositionFa.setInstanceId(null);
testJpaAutomationCompositionFa.fromAuthorative(participant);
assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa);
- assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
- assertEquals("automation-composition",
- new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName());
+ assertEquals("automation-composition", testJpaAutomationComposition.getName());
assertEquals("automation-composition",
- ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0))
- .getName());
-
- testJpaAutomationComposition.clean();
- assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName());
-
- testJpaAutomationComposition.setDescription(" A Message ");
- testJpaAutomationComposition.clean();
- assertEquals("A Message", testJpaAutomationComposition.getDescription());
+ new JpaAutomationComposition(createAutomationCompositionInstance()).getName());
var testJpaAutomationComposition2 = new JpaAutomationComposition(testJpaAutomationComposition);
assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2);
new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"),
AutomationComposition.class);
- noOrderedStateAc.setInstanceId(INSTANCE_ID);
+ noOrderedStateAc.setInstanceId(UUID.fromString(INSTANCE_ID));
var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
assertNull(noOrderedStateJpaAc.getOrderedState());
noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
AutomationCompositions.class).getAutomationCompositionList().get(0);
- acWithElements.setInstanceId(INSTANCE_ID);
+ acWithElements.setInstanceId(UUID.fromString(INSTANCE_ID));
var jpaAutomationCompositionWithElements = new JpaAutomationComposition(acWithElements);
assertEquals(4, jpaAutomationCompositionWithElements.getElements().size());
- assertEquals(17, jpaAutomationCompositionWithElements.getKeys().size());
- assertThatCode(jpaAutomationCompositionWithElements::clean).doesNotThrowAnyException();
-
assertEquals(acWithElements, jpaAutomationCompositionWithElements.toAuthorative());
}
assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition));
assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild()));
- testJpaAutomationComposition.setKey(new PfConceptKey("BadValue", "0.0.1"));
+ testJpaAutomationComposition.setInstanceId("BadValue");
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setKey(new PfConceptKey("automation-composition", "0.0.1"));
+ testJpaAutomationComposition.setInstanceId(INSTANCE_ID);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setCompositionId(UUID.randomUUID().toString());
testJpaAutomationComposition.setCompositionId(COMPOSITION_ID);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setName("BadValue");
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setName("automation-composition");
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
+ testJpaAutomationComposition.setVersion("0.0.0");
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setVersion("0.0.1");
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE);
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED);
ac1.setCompositionId(UUID.randomUUID().toString());
ac1.setDescription("Description");
- ac1.setElements(new LinkedHashMap<>());
- ac1.setKey(new PfConceptKey("participant", "0.0.1"));
+ ac1.setElements(new ArrayList<>());
+ ac1.setInstanceId(INSTANCE_ID);
ac1.setState(AutomationCompositionState.UNINITIALISED);
assertThat(ac1.toString()).contains("AutomationComposition(");
private JpaAutomationComposition createJpaAutomationCompositionInstance() {
var testAutomationComposition = createAutomationCompositionInstance();
var testJpaAutomationComposition = new JpaAutomationComposition();
- testJpaAutomationComposition.setKey(null);
- testJpaAutomationComposition.fromAuthorative(testAutomationComposition);
- testJpaAutomationComposition.setKey(PfConceptKey.getNullKey());
testJpaAutomationComposition.fromAuthorative(testAutomationComposition);
return testJpaAutomationComposition;
private AutomationComposition createAutomationCompositionInstance() {
var testAutomationComposition = new AutomationComposition();
testAutomationComposition.setName("automation-composition");
- testAutomationComposition.setInstanceId(INSTANCE_ID);
+ testAutomationComposition.setInstanceId(UUID.fromString(INSTANCE_ID));
testAutomationComposition.setVersion("0.0.1");
testAutomationComposition.setCompositionId(UUID.fromString(COMPOSITION_ID));
testAutomationComposition.setElements(new LinkedHashMap<>());
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import javax.persistence.EntityNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.springframework.data.domain.Example;
class AutomationCompositionProviderTest {
private static final String OBJECT_IS_NULL = "automationComposition is marked non-null but is null";
- private static final String ID_NAME = "PMSHInstance1";
- private static final String ID_VERSION = "1.0.1";
- private static final String ID_NAME_NOT_EXTST = "not_exist";
-
private static final Coder CODER = new StandardCoder();
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
@Test
void testGetAutomationCompositions() throws Exception {
- var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1);
- var name = automationComposition0.getName();
- var version = automationComposition0.getVersion();
- var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1);
-
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any()))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0),
- new JpaAutomationComposition(automationComposition1)));
- when(automationCompositionRepository.findById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0)));
- when(automationCompositionRepository.getById(automationComposition0.getKey().asIdentifier().asConceptKey()))
- .thenReturn(new JpaAutomationComposition(automationComposition0));
- when(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version))
- .thenReturn(List.of(new JpaAutomationComposition(automationComposition0)));
- when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey()))
- .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1)));
-
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size());
- var ac = automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION))
- .orElse(new AutomationComposition());
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
+ automationComposition.getName(), automationComposition.getVersion());
+ assertThat(acList).isEmpty();
- ac = automationCompositionProvider.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION));
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac);
+ when(automationCompositionRepository.findAll(Mockito.<Example<JpaAutomationComposition>>any()))
+ .thenReturn(inputAutomationCompositionsJpa);
+ acList = automationCompositionProvider.getAutomationCompositions(automationComposition.getCompositionId(), null,
+ null);
+ assertThat(acList).hasSize(2);
+ }
- when(automationCompositionRepository.getById(any())).thenThrow(EntityNotFoundException.class);
+ @Test
+ void testGetAutomationComposition() {
+ var automationCompositionRepository = mock(AutomationCompositionRepository.class);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
- assertThatThrownBy(() -> automationCompositionProvider
- .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)))
+ var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
+ assertThatThrownBy(
+ () -> automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId()))
.hasMessageMatching("AutomationComposition not found");
- assertThat(automationCompositionProvider
- .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty();
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ var ac = automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId());
+ assertEquals(automationComposition, ac);
}
@Test
- void testGetAutomationComposition() {
+ void testFindAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
- when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
+ var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
+ assertThat(acOpt).isEmpty();
+
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
+ assertThat(acOpt).isEmpty();
+
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
.thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
- var ac = automationCompositionProvider.getAutomationComposition(automationComposition.getInstanceId());
- assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), ac);
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
+ assertEquals(automationComposition, acOpt.get());
+
+ when(automationCompositionRepository.findOne(Mockito.<Example<JpaAutomationComposition>>any()))
+ .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
+ acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getKey().asIdentifier());
+ assertEquals(automationComposition, acOpt.get());
}
@Test
.hasMessageMatching(".*.failed, automation composition does not exist");
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
- when(automationCompositionRepository.findByInstanceId(automationComposition.getInstanceId().toString()))
+ when(automationCompositionRepository.findById(automationComposition.getInstanceId().toString()))
.thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0)));
var deletedAc =
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* 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 java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.Participant;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.dao.PfDao;
-import org.onap.policy.models.dao.PfFilterParameters;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.provider.impl.ModelsProvider;
class FilterRepositoryImplTest {
- private static final String AUTOMATION_COMPOSITION_JSON =
- "src/test/resources/providers/TestAutomationCompositions.json";
+ private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json";
+ private final List<Participant> inputParticipants = new ArrayList<>();
+ private List<JpaParticipant> jpaParticipantList;
+ private final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
private static final Coder CODER = new StandardCoder();
+
private static final AtomicInteger dbNameCounter = new AtomicInteger();
- private static final String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
- private static List<JpaAutomationComposition> jpaAutomationCompositions;
private PfDao pfDao;
@BeforeEach
parameters.setPersistenceUnit("ToscaConceptTest");
pfDao = ModelsProvider.init(parameters);
- var inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class);
- jpaAutomationCompositions =
- ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
- JpaAutomationComposition::new, "AutomationCompositions");
-
- pfDao.createCollection(jpaAutomationCompositions);
+ inputParticipants.add(CODER.decode(originalJson, Participant.class));
+ jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant");
+ pfDao.createCollection(jpaParticipantList);
}
@Test
return pfDao;
}
};
- var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, null, null);
- assertThat(result).hasSize(2);
-
- result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class,
- jpaAutomationCompositions.get(0).getName(), null);
+ var result = filterRepositoryImpl.getFiltered(JpaParticipant.class, null, null);
assertThat(result).hasSize(1);
- }
-
- @Test
- void testGetFiltered() {
- var filterRepositoryImpl = new FilterRepositoryImpl() {
- @Override
- protected PfDao getPfDao() {
- return pfDao;
- }
- };
-
- // @formatter:off
- PfFilterParameters filterParams = PfFilterParameters
- .builder()
- .name(jpaAutomationCompositions.get(0).getName())
- .build();
- // @formatter:on
- var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, filterParams);
+ result = filterRepositoryImpl.getFiltered(JpaParticipant.class, jpaParticipantList.get(0).getName(), null);
assertThat(result).hasSize(1);
}
}
"orderedState": "UNINITIALISED",
"elements": {
"709c62b3-8918-41b9-a747-e21eb79c6c20": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c20",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c20",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
"version": "1.2.3"
"description": "DCAE automation composition element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c21": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c21",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement",
"version": "1.2.3"
"description": "Monitoring Policy element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c22": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c22",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
"version": "1.2.3"
"description": "Operational Policy element for the PMSH instance 0 automation composition"
},
"709c62b3-8918-41b9-a747-e21eb79c6c23": {
- "id": "709c62b3-8918-41b9-a747-d21eb79c6c23",
+ "id": "709c62b3-8918-41b9-a747-e21eb79c6c23",
"definition": {
"name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement",
"version": "1.2.3"
* @return the automation compositions
*/
@Transactional(readOnly = true)
- public AutomationCompositions getAutomationCompositions(String name, String version) {
+ public AutomationCompositions getAutomationCompositions(UUID compositionId, String name, String version) {
var automationCompositions = new AutomationCompositions();
- automationCompositions
- .setAutomationCompositionList(automationCompositionProvider.getAutomationCompositions(name, version));
+ automationCompositions.setAutomationCompositionList(
+ automationCompositionProvider.getAutomationCompositions(compositionId, name, version));
return automationCompositions;
}
public ResponseEntity<AutomationCompositions> queryCompositionInstances(UUID compositionId, String name,
String version, UUID requestId) {
- return ResponseEntity.ok().body(provider.getAutomationCompositions(name, version));
+ return ResponseEntity.ok().body(provider.getAutomationCompositions(compositionId, name, version));
}
/**
verify(acProvider).createAutomationComposition(automationCompositionCreate);
- when(acProvider.getAutomationCompositions(automationCompositionCreate.getName(),
+ when(acProvider.getAutomationCompositions(compositionId, automationCompositionCreate.getName(),
automationCompositionCreate.getVersion())).thenReturn(List.of(automationCompositionCreate));
- var automationCompositionsGet = instantiationProvider.getAutomationCompositions(
+ var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId,
automationCompositionCreate.getName(), automationCompositionCreate.getVersion());
assertThat(automationCompositionCreate)
.isEqualTo(automationCompositionsGet.getAutomationCompositionList().get(0));
var instResponse = resp.readEntity(InstantiationResponse.class);
InstantiationUtils.assertInstantiationResponse(instResponse, automationComposition);
- var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
+ var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(compositionId,
automationComposition.getKey().getName(), automationComposition.getKey().getVersion());
assertNotNull(automationCompositionsFromDb);
instResponse = resp.readEntity(InstantiationResponse.class);
InstantiationUtils.assertInstantiationResponse(instResponse, automationCompositionFromRsc);
- var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(
+ var automationCompositionsFromDb = instantiationProvider.getAutomationCompositions(compositionId,
automationCompositionFromRsc.getKey().getName(), automationCompositionFromRsc.getKey().getVersion());
assertThat(automationCompositionsFromDb.getAutomationCompositionList()).isEmpty();
}
// check passive state on DB
var toscaConceptIdentifier = instResponse.getAffectedAutomationComposition();
- var automationCompositionsGet = instantiationProvider
- .getAutomationCompositions(toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
+ var automationCompositionsGet = instantiationProvider.getAutomationCompositions(compositionId,
+ toscaConceptIdentifier.getName(), toscaConceptIdentifier.getVersion());
assertThat(automationCompositionsGet.getAutomationCompositionList()).hasSize(1);
assertEquals(command.getOrderedState(),
automationCompositionsGet.getAutomationCompositionList().get(0).getOrderedState());