Search in sources :

Example 1 with DecorationExtension

use of net.nemerosa.ontrack.extension.api.DecorationExtension 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 2 with DecorationExtension

use of net.nemerosa.ontrack.extension.api.DecorationExtension 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

DecorationExtension (net.nemerosa.ontrack.extension.api.DecorationExtension)2 ExtensionManager (net.nemerosa.ontrack.extension.api.ExtensionManager)2 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)2 Decoration (net.nemerosa.ontrack.model.structure.Decoration)2 ProjectEntity (net.nemerosa.ontrack.model.structure.ProjectEntity)2 Test (org.junit.Test)2