@Override public Form getEditionForm(ProjectEntity entity, AutoPromotionProperty value) { PromotionLevel promotionLevel = (PromotionLevel) entity; return Form.create() .with( MultiSelection.of("validationStamps") .label("Validation stamps") .items( structureService .getValidationStampListForBranch(promotionLevel.getBranch().getId()) .stream() .map( vs -> new ValidationStampSelection( vs, value != null && value.containsDirectValidationStamp(vs))) .collect(Collectors.toList())) .help( "When all the selected validation stamps have passed for a build, the promotion will automatically be granted.")) .with( Text.of("include") .label("Include") .optional() .value(value != null ? value.getInclude() : "") .help("Regular expression to select validation stamps by name")) .with( Text.of("exclude") .label("Exclude") .optional() .value(value != null ? value.getExclude() : "") .help("Regular expression to exclude validation stamps by name")); }
@Before public void before() { SecurityService securityService = mock(SecurityService.class); ValidationRunStatusService validationRunStatusService = mock(ValidationRunStatusService.class); structureRepository = mock(StructureRepository.class); EventPostService eventService = mock(EventPostService.class); EventFactory eventFactory = mock(EventFactory.class); ExtensionManager extensionManager = mock(ExtensionManager.class); PropertyService propertyService = mock(PropertyService.class); PredefinedPromotionLevelService predefinedPromotionLevelService = mock(PredefinedPromotionLevelService.class); PredefinedValidationStampService predefinedValidationStampService = mock(PredefinedValidationStampService.class); DecorationService decorationService = mock(DecorationService.class); ProjectFavouriteService projectFavouriteService = mock(ProjectFavouriteService.class); service = new StructureServiceImpl( securityService, eventService, eventFactory, validationRunStatusService, structureRepository, extensionManager, propertyService, predefinedPromotionLevelService, predefinedValidationStampService, decorationService, projectFavouriteService); // Model Project project = Project.of(nd("P", "Project")).withId(ID.of(1)); Branch branch = Branch.of(project, nd("B", "Branch")).withId(ID.of(1)); copper = PromotionLevel.of(branch, nd("COPPER", "")).withId(ID.of(1)); build = Build.of(branch, nd("1", "Build 1"), Signature.of("test")).withId(ID.of(1)); }
@Override public AutoPromotionProperty copy( ProjectEntity sourceEntity, AutoPromotionProperty value, ProjectEntity targetEntity, Function<String, String> replacementFn) { PromotionLevel targetPromotionLevel = (PromotionLevel) targetEntity; return new AutoPromotionProperty( value .getValidationStamps() .stream() .map( vs -> structureService.findValidationStampByName( targetPromotionLevel.getBranch().getProject().getName(), targetPromotionLevel.getBranch().getName(), vs.getName())) .filter(Optional::isPresent) .map(Optional::get) .collect(Collectors.toList()), value.getInclude(), value.getExclude()); }