@Test void cantSetApplicationsIfDuplicates() { final ApplicationEntity one = Mockito.mock(ApplicationEntity.class); Mockito.when(one.getUniqueId()).thenReturn(UUID.randomUUID().toString()); final ApplicationEntity two = Mockito.mock(ApplicationEntity.class); Mockito.when(two.getUniqueId()).thenReturn(UUID.randomUUID().toString()); Assertions .assertThatExceptionOfType(PreconditionFailedException.class) .isThrownBy(() -> this.c.setApplications(Lists.newArrayList(one, two, one))); }
public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } }
CommandEntity extends BaseEntity { public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } } }
CommandEntity extends BaseEntity { public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } } CommandEntity(); }
CommandEntity extends BaseEntity { public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } } CommandEntity(); void setExecutable(@NotEmpty final List<@NotBlank @Size(max = 1024) String> executable); void setConfigs(@Nullable final Set<FileEntity> configs); void setDependencies(@Nullable final Set<FileEntity> dependencies); void setTags(@Nullable final Set<TagEntity> tags); Optional<Integer> getMemory(); Optional<JsonNode> getLauncherExt(); void setLauncherExt(@Nullable final JsonNode launcherExt); void setApplications(
        @Nullable final List<ApplicationEntity> applications
    ); void addApplication(@NotNull final ApplicationEntity application); void removeApplication(@NotNull final ApplicationEntity application); void setClusterCriteria(@Nullable final List<CriterionEntity> clusterCriteria); void addClusterCriterion(final CriterionEntity criterion); void addClusterCriterion(final CriterionEntity criterion, final int priority); CriterionEntity removeClusterCriterion(final int priority); @Override boolean equals(final Object o); @Override int hashCode(); }
CommandEntity extends BaseEntity { public void setApplications( @Nullable final List<ApplicationEntity> applications ) throws PreconditionFailedException { if (applications != null && applications.stream().map(ApplicationEntity::getUniqueId).distinct().count() != applications.size()) { throw new PreconditionFailedException("List of applications to set cannot contain duplicates"); } for (final ApplicationEntity application : this.applications) { application.getCommands().remove(this); } this.applications.clear(); if (applications != null) { this.applications.addAll(applications); for (final ApplicationEntity application : this.applications) { application.getCommands().add(this); } } } CommandEntity(); void setExecutable(@NotEmpty final List<@NotBlank @Size(max = 1024) String> executable); void setConfigs(@Nullable final Set<FileEntity> configs); void setDependencies(@Nullable final Set<FileEntity> dependencies); void setTags(@Nullable final Set<TagEntity> tags); Optional<Integer> getMemory(); Optional<JsonNode> getLauncherExt(); void setLauncherExt(@Nullable final JsonNode launcherExt); void setApplications(
        @Nullable final List<ApplicationEntity> applications
    ); void addApplication(@NotNull final ApplicationEntity application); void removeApplication(@NotNull final ApplicationEntity application); void setClusterCriteria(@Nullable final List<CriterionEntity> clusterCriteria); void addClusterCriterion(final CriterionEntity criterion); void addClusterCriterion(final CriterionEntity criterion, final int priority); CriterionEntity removeClusterCriterion(final int priority); @Override boolean equals(final Object o); @Override int hashCode(); static final String APPLICATIONS_ENTITY_GRAPH; static final String APPLICATIONS_DTO_ENTITY_GRAPH; static final String CLUSTER_CRITERIA_ENTITY_GRAPH; static final String DTO_ENTITY_GRAPH; }