Search in sources :

Example 1 with ExtensionManager

use of net.nemerosa.ontrack.extension.api.ExtensionManager in project ontrack by nemerosa.

the class StructureServiceImplTest method before.

@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));
}
Also used : PredefinedPromotionLevelService(net.nemerosa.ontrack.model.settings.PredefinedPromotionLevelService) EventPostService(net.nemerosa.ontrack.model.events.EventPostService) EventFactory(net.nemerosa.ontrack.model.events.EventFactory) PredefinedValidationStampService(net.nemerosa.ontrack.model.settings.PredefinedValidationStampService) StructureRepository(net.nemerosa.ontrack.repository.StructureRepository) ExtensionManager(net.nemerosa.ontrack.extension.api.ExtensionManager) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) Before(org.junit.Before)

Example 2 with ExtensionManager

use of net.nemerosa.ontrack.extension.api.ExtensionManager in project ontrack by nemerosa.

the class DecorationServiceImplTest method base_exception_decoration_generates_default_error_decoration.

@Test
public void base_exception_decoration_generates_default_error_decoration() {
    ProjectEntity projectEntity = mock(ProjectEntity.class);
    DecorationExtension decorator = mock(DecorationExtension.class);
    when(decorator.getDecorations(any(ProjectEntity.class))).thenThrow(new TestBaseException());
    ExtensionManager extensionManager = mock(ExtensionManager.class);
    when(extensionManager.getExtensions(DecorationExtension.class)).thenReturn(Collections.singletonList(decorator));
    SecurityService securityService = mock(SecurityService.class);
    DecorationServiceImpl service = new DecorationServiceImpl(extensionManager, securityService);
    @SuppressWarnings("unchecked") List<? extends Decoration> decorations = service.getDecorations(projectEntity, decorator);
    assertNotNull(decorations);
    assertEquals(1, decorations.size());
    Decoration decoration = decorations.get(0);
    assertEquals("Known exception", decoration.getError());
    assertNull(decoration.getData());
}
Also used : ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) ExtensionManager(net.nemerosa.ontrack.extension.api.ExtensionManager) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) DecorationExtension(net.nemerosa.ontrack.extension.api.DecorationExtension) Decoration(net.nemerosa.ontrack.model.structure.Decoration) Test(org.junit.Test)

Example 3 with ExtensionManager

use of net.nemerosa.ontrack.extension.api.ExtensionManager in project ontrack by nemerosa.

the class DecorationServiceImplTest method error_decoration_generates_default_error_decoration.

@Test
public void error_decoration_generates_default_error_decoration() {
    ProjectEntity projectEntity = mock(ProjectEntity.class);
    DecorationExtension decorator = mock(DecorationExtension.class);
    when(decorator.getDecorations(any(ProjectEntity.class))).thenThrow(new RuntimeException("Error while generating the decoration"));
    ExtensionManager extensionManager = mock(ExtensionManager.class);
    when(extensionManager.getExtensions(DecorationExtension.class)).thenReturn(Collections.singletonList(decorator));
    SecurityService securityService = mock(SecurityService.class);
    DecorationServiceImpl service = new DecorationServiceImpl(extensionManager, securityService);
    @SuppressWarnings("unchecked") List<? extends Decoration> decorations = service.getDecorations(projectEntity, decorator);
    assertNotNull(decorations);
    assertEquals(1, decorations.size());
    Decoration decoration = decorations.get(0);
    assertNull(decoration.getData());
    assertEquals("Problem while getting decoration", decoration.getError());
}
Also used : ProjectEntity(net.nemerosa.ontrack.model.structure.ProjectEntity) ExtensionManager(net.nemerosa.ontrack.extension.api.ExtensionManager) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) DecorationExtension(net.nemerosa.ontrack.extension.api.DecorationExtension) Decoration(net.nemerosa.ontrack.model.structure.Decoration) Test(org.junit.Test)

Aggregations

ExtensionManager (net.nemerosa.ontrack.extension.api.ExtensionManager)3 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)3 DecorationExtension (net.nemerosa.ontrack.extension.api.DecorationExtension)2 Decoration (net.nemerosa.ontrack.model.structure.Decoration)2 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)2 Test (org.junit.Test)2 EventFactory (net.nemerosa.ontrack.model.events.EventFactory)1 EventPostService (net.nemerosa.ontrack.model.events.EventPostService)1 PredefinedPromotionLevelService (net.nemerosa.ontrack.model.settings.PredefinedPromotionLevelService)1 PredefinedValidationStampService (net.nemerosa.ontrack.model.settings.PredefinedValidationStampService)1 StructureRepository (net.nemerosa.ontrack.repository.StructureRepository)1 Before (org.junit.Before)1