Search in sources :

Example 41 with Issue

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

the class NotificationManagerTest method createIssue.

private Issue createIssue(PipelineUser author, AbstractSecuredEntity entity) {
    Issue issue = new Issue();
    issue.setName("testIssue");
    issue.setText("Notifying @TestUser1, @TestUser2, also add @admin here");
    issue.setAuthor(author.getUserName());
    issue.setEntity(new EntityVO(entity.getId(), entity.getAclClass()));
    return issue;
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Issue(com.epam.pipeline.entity.issue.Issue)

Example 42 with Issue

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

the class NotificationManagerTest method testNotifyIssue.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIssue() {
    Pipeline pipeline = createPipeline(testOwner);
    Issue issue = createIssue(testUser2, pipeline);
    notificationManager.notifyIssue(issue, pipeline, issue.getText());
    List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
    Assert.assertEquals(1, messages.size());
    NotificationMessage message = messages.get(0);
    Assert.assertEquals(testOwner.getId(), message.getToUserId());
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser1.getId())));
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser2.getId())));
    Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(admin.getId())));
    updateKeepInformedOwner(issueSettings, false);
    notificationManager.notifyIssue(issue, pipeline, issue.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) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 43 with Issue

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

the class IssueMapper method map.

@Override
public XContentBuilder map(final EntityContainer<Issue> container) {
    Issue issue = container.getEntity();
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        jsonBuilder.startObject();
        jsonBuilder.field(DOC_TYPE_FIELD, SearchDocumentType.ISSUE.name()).field("id", issue.getId()).field("name", issue.getName()).field("text", issue.getText()).field("status", issue.getStatus()).field("createdDate", parseDataToString(issue.getCreatedDate())).field("updatedDate", parseDataToString(issue.getUpdatedDate()));
        buildLabels(issue.getLabels(), jsonBuilder);
        buildAttachments(issue.getAttachments(), jsonBuilder);
        buildEntityVO(issue.getEntity(), jsonBuilder);
        buildComments(issue.getComments(), jsonBuilder);
        buildPermissions(container.getPermissions(), jsonBuilder);
        buildUserContent(container.getOwner(), jsonBuilder);
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for issue: ", e);
    }
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 44 with Issue

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

the class IssueMapperTest method shouldMapIssue.

@Test
void shouldMapIssue() throws IOException {
    IssueMapper mapper = new IssueMapper();
    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 issue = 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).build();
    EntityContainer<Issue> container = EntityContainer.<Issue>builder().entity(issue).owner(USER).permissions(PERMISSIONS_CONTAINER).build();
    XContentBuilder contentBuilder = mapper.map(container);
    verifyIssue(issue, contentBuilder);
    verifyAttachments(Collections.singletonList(attachment.getPath()), contentBuilder);
    verifyComments(Collections.singletonList(comment.getAuthor() + " : " + comment.getText()), contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
}
Also used : EntityVO(com.epam.pipeline.vo.EntityVO) MapperVerificationUtils.verifyIssue(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyIssue) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Attachment(com.epam.pipeline.entity.issue.Attachment) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

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