Search in sources :

Example 16 with Issue

use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.

the class NotificationManagerTest method testNotifyIssueComment.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIssueComment() {
    Pipeline pipeline = createPipeline(testOwner);
    Issue issue = createIssue(testUser2, pipeline);
    issueDao.createIssue(issue);
    IssueComment comment = new IssueComment();
    comment.setIssueId(issue.getId());
    comment.setText("Notify @TestUser1");
    comment.setAuthor(testUser2.getUserName());
    notificationManager.notifyIssueComment(comment, issue, comment.getText());
    List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertEquals(1, messages.size());
    NotificationMessage message = messages.get(0);
    Assert.assertEquals(testUser2.getId(), message.getToUserId());
    Assert.assertEquals(issueCommentTemplate.getId(), message.getTemplate().getId());
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser1.getId())));
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testOwner.getId())));
    updateKeepInformedOwner(issueCommentSettings, false);
    notificationManager.notifyIssueComment(comment, issue, comment.getText());
    messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertEquals(2, messages.size());
    Assert.assertNull(messages.get(1).getToUserId());
}
Also used : Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) PodMonitor(com.epam.pipeline.manager.cluster.PodMonitor) Autowired(org.springframework.beans.factory.annotation.Autowired) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) MockitoAnnotations(org.mockito.MockitoAnnotations) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ExtendedRole(com.epam.pipeline.entity.user.ExtendedRole) Map(java.util.Map) IssueComment(com.epam.pipeline.entity.issue.IssueComment) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) MockBean(org.springframework.boot.test.mock.mockito.MockBean) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) DateUtils(com.epam.pipeline.entity.utils.DateUtils) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) NotificationTemplateDao(com.epam.pipeline.dao.notification.NotificationTemplateDao) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) List(java.util.List) MonitoringNotificationDao(com.epam.pipeline.dao.notification.MonitoringNotificationDao) NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) UserDao(com.epam.pipeline.dao.user.UserDao) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Mockito.mock(org.mockito.Mockito.mock) MixedOperation(io.fabric8.kubernetes.client.dsl.MixedOperation) NotificationSettingsDao(com.epam.pipeline.dao.notification.NotificationSettingsDao) Mock(org.mockito.Mock) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) Duration(org.joda.time.Duration) TestApplication(com.epam.pipeline.app.TestApplication) PipelineDao(com.epam.pipeline.dao.pipeline.PipelineDao) ArgumentCaptor(org.mockito.ArgumentCaptor) Propagation(org.springframework.transaction.annotation.Propagation) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) KubernetesManager(com.epam.pipeline.manager.cluster.KubernetesManager) KubernetesTestUtils(com.epam.pipeline.util.KubernetesTestUtils) NotificationType(com.epam.pipeline.entity.notification.NotificationSettings.NotificationType) Before(org.junit.Before) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) PodStatus(io.fabric8.kubernetes.api.model.PodStatus) CustomAssertions.assertThrows(com.epam.pipeline.util.CustomAssertions.assertThrows) DateTime(org.joda.time.DateTime) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) Matchers(org.hamcrest.Matchers) Pod(io.fabric8.kubernetes.api.model.Pod) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) NotificationMessageVO(com.epam.pipeline.controller.vo.notification.NotificationMessageVO) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) Mockito.verify(org.mockito.Mockito.verify) PodList(io.fabric8.kubernetes.api.model.PodList) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IssueDao(com.epam.pipeline.dao.issue.IssueDao) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert(org.junit.Assert) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Issue(com.epam.pipeline.entity.issue.Issue) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with Issue

use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.

the class IssueLoaderTest method shouldLoadIssueTest.

@Test
void shouldLoadIssueTest() throws EntityNotFoundException {
    Attachment attachment = new Attachment();
    attachment.setPath(TEST_PATH);
    attachment.setOwner(USER_NAME);
    IssueComment comment = IssueComment.builder().author(USER_NAME).text(TEST_DESCRIPTION).build();
    EntityVO entity = new EntityVO(1L, AclClass.TOOL);
    Issue expectedIssue = Issue.builder().id(1L).name(TEST_NAME).text(TEST_DESCRIPTION).status(IssueStatus.OPEN).labels(Collections.singletonList(TEST_LABEL)).attachments(Collections.singletonList(attachment)).comments(Collections.singletonList(comment)).entity(entity).author(TEST_NAME).build();
    IssueLoader issueLoader = new IssueLoader(apiClient);
    when(apiClient.loadIssue(anyLong())).thenReturn(expectedIssue);
    Optional<EntityContainer<Issue>> container = issueLoader.loadEntity(1L);
    EntityContainer<Issue> issueEntityContainer = container.orElseThrow(AssertionError::new);
    Issue actualIssue = issueEntityContainer.getEntity();
    assertNotNull(actualIssue);
    verifyIssue(expectedIssue, actualIssue);
    verifyPipelineUser(issueEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, issueEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(issueEntityContainer.getMetadata().values()));
}
Also used : EntityVO(com.epam.pipeline.vo.EntityVO) LoaderVerificationUtils.verifyIssue(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyIssue) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Attachment(com.epam.pipeline.entity.issue.Attachment) Test(org.junit.jupiter.api.Test)

Example 18 with Issue

use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.

the class IssueManager method loadIssue.

/**
 * Loads an {@link Issue} specified by ID. If issue doesn't exist exception will be thrown.
 * @param id issue's ID
 * @return issue with comments that belong to it
 */
public Issue loadIssue(Long id) {
    Issue issue = issueDao.loadIssue(id).orElseThrow(getIssueNotFoundException(id));
    issue.setComments(commentDao.loadCommentsForIssue(id));
    issue.setAttachments(attachmentDao.loadAttachmentsByIssueId(id));
    Map<Long, List<Attachment>> attachmentMap = attachmentDao.loadAttachmentsByCommentIds(issue.getComments().stream().map(IssueComment::getId).collect(Collectors.toList()));
    issue.getComments().forEach(c -> c.setAttachments(attachmentMap.get(c.getId())));
    return issue;
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) List(java.util.List)

Example 19 with Issue

use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.

the class NotificationManager method notifyIssue.

/**
 * Notify users that a new issue was created for a given entity. Will notify mentioned users as well.
 *
 * @param issue an issue to notify about
 * @param entity an entity for wich issue was created
 */
@Transactional(propagation = Propagation.REQUIRED)
public void notifyIssue(Issue issue, AbstractSecuredEntity entity, String htmlText) {
    NotificationSettings newIssueSettings = notificationSettingsManager.load(NotificationType.NEW_ISSUE);
    if (newIssueSettings == null || !newIssueSettings.isEnabled()) {
        LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_NOTIFICATION_TEMPLATE_NOT_CONFIGURED, "new issue"));
        return;
    }
    NotificationMessage message = new NotificationMessage();
    message.setTemplate(new NotificationTemplate(newIssueSettings.getTemplateId()));
    message.setCopyUserIds(getMentionedUsers(issue.getText()));
    Issue copyWithHtml = issue.toBuilder().text(htmlText).build();
    message.setTemplateParameters(jsonMapper.convertValue(copyWithHtml, new TypeReference<Map<String, Object>>() {
    }));
    if (newIssueSettings.isKeepInformedOwner()) {
        PipelineUser owner = userManager.loadUserByName(entity.getOwner());
        message.setToUserId(owner.getId());
    }
    monitoringNotificationDao.createMonitoringNotification(message);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Issue(com.epam.pipeline.entity.issue.Issue) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) NotificationSettings(com.epam.pipeline.entity.notification.NotificationSettings) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with Issue

use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.

the class IssueDaoTest method testCRUD.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCRUD() {
    EntityVO entity = new EntityVO(ENTITY_ID, ENTITY_CLASS);
    Issue issue = getIssue(NAME, entity);
    // create
    issueDao.createIssue(issue);
    Long id = issue.getId();
    // load
    Optional<Issue> loaded = issueDao.loadIssue(id);
    assertTrue(loaded.isPresent());
    verifyIssue(issue, loaded.get());
    Issue issue2 = getIssue(NAME2, entity);
    issueDao.createIssue(issue2);
    List<Issue> issues = issueDao.loadIssuesForEntity(entity);
    assertEquals(2, issues.size());
    // update
    issue.setName(NAME3);
    issue.setText(TEXT2);
    issue.setStatus(STATUS);
    issueDao.updateIssue(issue);
    Optional<Issue> updated = issueDao.loadIssue(id);
    assertTrue(updated.isPresent());
    assertEquals(NAME3, updated.get().getName());
    assertEquals(STATUS, updated.get().getStatus());
    // delete
    issueDao.deleteIssue(issue.getId());
    Optional<Issue> deleted = issueDao.loadIssue(id);
    assertFalse(deleted.isPresent());
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Issue(com.epam.pipeline.entity.issue.Issue) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Issue (com.epam.pipeline.entity.issue.Issue)44 Transactional (org.springframework.transaction.annotation.Transactional)30 Test (org.junit.Test)25 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)21 IssueComment (com.epam.pipeline.entity.issue.IssueComment)17 EntityVO (com.epam.pipeline.controller.vo.EntityVO)16 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)13 IssueVO (com.epam.pipeline.controller.vo.IssueVO)11 List (java.util.List)9 Attachment (com.epam.pipeline.entity.issue.Attachment)7 Map (java.util.Map)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Propagation (org.springframework.transaction.annotation.Propagation)7 AclClass (com.epam.pipeline.entity.security.acl.AclClass)6 Collections (java.util.Collections)6 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)5 Collectors (java.util.stream.Collectors)5 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)4 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)4 Folder (com.epam.pipeline.entity.pipeline.Folder)4