add method to get a single action by externalRef (#942)
* add method to get a single action by externalRef * adding junit test for ControllerManagement::getActionByExternalRef * fixing sonarQube findings * improve assert statement Signed-off-by: Ravindranath Sandeep <Sandeep.Ravindranath@bosch-si.com>
This commit is contained in:
committed by
GitHub
parent
46ce3b632a
commit
cf7add7aaa
@@ -481,6 +481,16 @@ public interface ControllerManagement {
|
|||||||
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||||
List<Action> getActiveActionsByExternalRef(@NotNull List<String> externalRefs);
|
List<Action> getActiveActionsByExternalRef(@NotNull List<String> externalRefs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an {@link Action} using {@link Action#getExternalRef()}
|
||||||
|
*
|
||||||
|
* @param externalRef
|
||||||
|
* of the action. See {@link Action#getExternalRef()}
|
||||||
|
* @return {@link Action} or {@code null} if it does not exist
|
||||||
|
*/
|
||||||
|
@PreAuthorize(SpringEvalExpressions.IS_CONTROLLER)
|
||||||
|
Optional<Action> getActionByExternalRef(@NotEmpty String externalRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a single target.
|
* Delete a single target.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -264,6 +264,16 @@ public interface ActionRepository extends BaseEntityRepository<JpaAction, Long>,
|
|||||||
List<Action> findByExternalRefInAndActive(@Param("externalRefs") List<String> externalRefs,
|
List<Action> findByExternalRefInAndActive(@Param("externalRefs") List<String> externalRefs,
|
||||||
@Param("active") boolean active);
|
@Param("active") boolean active);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an {@link Action} that matches the queried externalRef.
|
||||||
|
*
|
||||||
|
* @param externalRef
|
||||||
|
* of the action. See {@link Action#getExternalRef()}
|
||||||
|
* @return the found {@link Action}
|
||||||
|
*/
|
||||||
|
Optional<Action> findByExternalRef(@Param("externalRef") String externalRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Switches the status of actions from one specific status into another for
|
* Switches the status of actions from one specific status into another for
|
||||||
* given actions IDs, active flag and current status
|
* given actions IDs, active flag and current status
|
||||||
|
|||||||
@@ -1050,6 +1050,11 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
|||||||
actionRepository.updateExternalRef(actionId, externalRef);
|
actionRepository.updateExternalRef(actionId, externalRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Action> getActionByExternalRef(@NotEmpty final String externalRef) {
|
||||||
|
return actionRepository.findByExternalRef(externalRef);
|
||||||
|
}
|
||||||
|
|
||||||
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
private void cancelAssignDistributionSetEvent(final JpaTarget target, final Long actionId) {
|
||||||
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
afterCommit.afterCommit(() -> eventPublisherHolder.getEventPublisher().publishEvent(
|
||||||
new CancelTargetAssignmentEvent(target, actionId, eventPublisherHolder.getApplicationId())));
|
new CancelTargetAssignmentEvent(target, actionId, eventPublisherHolder.getApplicationId())));
|
||||||
|
|||||||
@@ -1365,6 +1365,29 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Description("Verify that getting a single action using externalRef works")
|
||||||
|
public void getActionUsingSingleExternalRef() {
|
||||||
|
|
||||||
|
final String knownControllerId = "controllerId";
|
||||||
|
final String knownExternalRef = "externalRefId";
|
||||||
|
final DistributionSet knownDistributionSet = testdataFactory.createDistributionSet();
|
||||||
|
|
||||||
|
// GIVEN
|
||||||
|
testdataFactory.createTarget(knownControllerId);
|
||||||
|
final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(knownDistributionSet.getId(),
|
||||||
|
knownControllerId);
|
||||||
|
final Long actionId = getFirstAssignedActionId(assignmentResult);
|
||||||
|
controllerManagement.updateActionExternalRef(actionId, knownExternalRef);
|
||||||
|
|
||||||
|
// WHEN
|
||||||
|
final Optional<Action> foundAction = controllerManagement.getActionByExternalRef(knownExternalRef);
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
assertThat(foundAction).isPresent();
|
||||||
|
assertThat(foundAction.get().getId()).isEqualTo(actionId);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verify that a null externalRef cannot be assigned to an action")
|
@Description("Verify that a null externalRef cannot be assigned to an action")
|
||||||
public void externalRefCannotBeNull() {
|
public void externalRefCannotBeNull() {
|
||||||
|
|||||||
Reference in New Issue
Block a user