Search in sources :

Example 31 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class PipelineRunDaoTest method testLoadActiveServicesByOwner.

@Test
public void testLoadActiveServicesByOwner() {
    PipelineRun run = createTestPipelineRun();
    PagingRunFilterVO filterVO = new PagingRunFilterVO();
    filterVO.setPage(1);
    filterVO.setPageSize(TEST_PAGE_SIZE);
    PipelineUser user = new PipelineUser();
    user.setUserName(USER);
    List<PipelineRun> runs = pipelineRunDao.loadActiveServices(filterVO, user);
    assertEquals(1, runs.size());
    assertEquals(run.getId(), runs.get(0).getId());
    assertEquals(1, runs.size());
}
Also used : PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) PagingRunFilterVO(com.epam.pipeline.controller.vo.PagingRunFilterVO) EnvVarsBuilderTest(com.epam.pipeline.manager.execution.EnvVarsBuilderTest) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test)

Example 32 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class MonitoringNotificationDaoTest method testCreateMonitoringNotifications.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCreateMonitoringNotifications() {
    NotificationTemplate notificationTemplate = notificationTemplateDao.createNotificationTemplate(template);
    PipelineUser pipelineUser = userDao.loadUserByName(TEST_USER1);
    List<NotificationMessage> messages = IntStream.range(0, 5).mapToObj(i -> {
        NotificationMessage notificationMessage = new NotificationMessage();
        notificationMessage.setTemplate(notificationTemplate);
        notificationMessage.setToUserId(pipelineUser.getId());
        notificationMessage.setCopyUserIds(Collections.singletonList(pipelineUser.getId()));
        notificationMessage.setTemplateParameters(Collections.singletonMap("test", i));
        return notificationMessage;
    }).collect(Collectors.toList());
    monitoringNotificationDao.createMonitoringNotifications(messages);
    List<NotificationMessage> loaded = monitoringNotificationDao.loadAllNotifications();
    assertTrue(messages.size() <= loaded.size());
    assertTrue(loaded.stream().allMatch(l -> messages.stream().anyMatch(m -> m.getTemplateParameters().equals(l.getTemplateParameters()))));
}
Also used : IntStream(java.util.stream.IntStream) PipelineRunMapper(com.epam.pipeline.mapper.PipelineRunMapper) Arrays(java.util.Arrays) PipelineRunDao(com.epam.pipeline.dao.pipeline.PipelineRunDao) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) PipelineDao(com.epam.pipeline.dao.pipeline.PipelineDao) Propagation(org.springframework.transaction.annotation.Propagation) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Before(org.junit.Before) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Collectors(java.util.stream.Collectors) com.epam.pipeline.entity.pipeline(com.epam.pipeline.entity.pipeline) Objects(java.util.Objects) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Assert.assertFalse(org.junit.Assert.assertFalse) UserDao(com.epam.pipeline.dao.user.UserDao) Collections(java.util.Collections) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 33 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class MonitoringNotificationDaoTest method testLoadMonitoringNotification.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testLoadMonitoringNotification() {
    PipelineRun run1 = createTestPipelineRun();
    List<PipelineRun> pipelineRuns = pipelineRunDao.loadPipelineRuns(Collections.singletonList(run1.getId()));
    NotificationTemplate notificationTemplate = notificationTemplateDao.createNotificationTemplate(template);
    notificationMessage = new NotificationMessage();
    notificationMessage.setTemplate(notificationTemplate);
    PipelineUser pipelineUser = userDao.loadUserByName(TEST_USER1);
    notificationMessage.setToUserId(pipelineUser.getId());
    notificationMessage.setCopyUserIds(Collections.singletonList(pipelineUser.getId()));
    notificationMessage.setTemplateParameters(PipelineRunMapper.map(pipelineRuns.get(0), TEST_THRESHOLD));
    monitoringNotificationDao.createMonitoringNotification(notificationMessage);
    NotificationMessage actualMessage = monitoringNotificationDao.loadMonitoringNotification(notificationMessage.getId());
    assertEquals(notificationMessage.getId(), actualMessage.getId());
    assertEquals(notificationMessage.getTemplate().getId(), actualMessage.getTemplate().getId());
    assertEquals(user.getId(), notificationMessage.getToUserId());
    assertFalse(notificationMessage.getCopyUserIds().isEmpty());
    notificationMessage.getTemplateParameters().values().removeIf(Objects::isNull);
    notificationMessage.getTemplateParameters().forEach((k, v) -> {
        assertTrue(actualMessage.getTemplateParameters().containsKey(k));
        assertEquals(v.toString(), actualMessage.getTemplateParameters().get(k).toString());
    });
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) Objects(java.util.Objects) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class MonitoringNotificationDaoTest method setUp.

@Before
public void setUp() {
    user = new PipelineUser();
    user.setUserName(TEST_USER1);
    userDao.createUser(user, Arrays.asList(DefaultRoles.ROLE_ADMIN.getId(), DefaultRoles.ROLE_USER.getId()));
    testPipeline = new Pipeline();
    testPipeline.setName("Test");
    testPipeline.setRepository("///");
    testPipeline.setOwner(TEST_USER1);
    pipelineDao.createPipeline(testPipeline);
    template = new NotificationTemplate();
    template.setId(1L);
    template.setSubject(SUBJECT_STRING);
    template.setBody(BODY_STRING);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationTemplate(com.epam.pipeline.entity.notification.NotificationTemplate) Before(org.junit.Before)

Example 35 with PipelineUser

use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.

the class MonitoringNotificationDaoTest method testCreateAndLoadCustomMonitoringNotifications.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testCreateAndLoadCustomMonitoringNotifications() {
    PipelineUser pipelineUser = userDao.loadUserByName(TEST_USER1);
    NotificationMessage message = new NotificationMessage();
    message.setBody(BODY_STRING);
    message.setSubject(SUBJECT_STRING);
    message.setToUserId(pipelineUser.getId());
    message.setCopyUserIds(Collections.emptyList());
    message.setTemplateParameters(Collections.singletonMap(TEMPLATE_PARAMETER, TEMPLATE_PARAMETER_VALUE));
    monitoringNotificationDao.createMonitoringNotification(message);
    NotificationMessage singleLoadedMessage = monitoringNotificationDao.loadMonitoringNotification(message.getId());
    assertEquals(singleLoadedMessage.getBody(), BODY_STRING);
    assertEquals(singleLoadedMessage.getSubject(), SUBJECT_STRING);
    assertEquals(singleLoadedMessage.getToUserId(), pipelineUser.getId());
    assertEquals(singleLoadedMessage.getCopyUserIds(), Collections.emptyList());
    assertNull(singleLoadedMessage.getTemplate());
    NotificationMessage batchLoadedMessage = monitoringNotificationDao.loadAllNotifications().stream().filter(m -> m.getId().equals(message.getId())).findFirst().get();
    assertEquals(singleLoadedMessage, batchLoadedMessage);
}
Also used : PipelineUser(com.epam.pipeline.entity.user.PipelineUser) NotificationMessage(com.epam.pipeline.entity.notification.NotificationMessage) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

PipelineUser (com.epam.pipeline.entity.user.PipelineUser)44 Transactional (org.springframework.transaction.annotation.Transactional)23 Test (org.junit.Test)19 NotificationMessage (com.epam.pipeline.entity.notification.NotificationMessage)13 NotificationTemplate (com.epam.pipeline.entity.notification.NotificationTemplate)13 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)12 ArrayList (java.util.ArrayList)8 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)7 Collections (java.util.Collections)7 List (java.util.List)7 Map (java.util.Map)7 Autowired (org.springframework.beans.factory.annotation.Autowired)7 Role (com.epam.pipeline.entity.user.Role)6 AbstractSpringTest (com.epam.pipeline.notifier.AbstractSpringTest)6 Arrays (java.util.Arrays)6 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)5 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)5 Collection (java.util.Collection)5 CollectionUtils (org.apache.commons.collections4.CollectionUtils)5 DataStorageDao (com.epam.pipeline.dao.datastorage.DataStorageDao)4