Search in sources :

Example 21 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class HoursRepositoryTest method testGetActualHours_ifEmployeesIsEmpty.

@Test
public void testGetActualHours_ifEmployeesIsEmpty() throws NoSuchFieldException {
    Date start = new Date();
    Date finish = getOffsetDate(2);
    Period period = new Period(start, finish);
    Employee employee = new Employee("employee");
    Project project = new Project();
    HourType actualType = new HourType("actual type");
    actualType.setActualTime(true);
    BigDecimal quantity = new BigDecimal(8);
    Hours hours1 = createHours(project, employee, getOffsetDate(1), actualType, quantity);
    entityManager.persist(employee);
    entityManager.persist(project);
    entityManager.persist(actualType);
    entityManager.persist(hours1);
    List<Hours> actuals = hoursRepository.getActualHours(Collections.emptyList(), period, false);
    assertTrue(actuals.isEmpty());
}
Also used : Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Hours(com.artezio.arttime.datamodel.Hours) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) CalendarUtils.getOffsetDate(com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 22 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class NotificationManagerTest method testNotifyPmAboutTimeProblems.

@Test
public void testNotifyPmAboutTimeProblems() throws NoSuchFieldException {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("getProjects", List.class).addMockedMethod("getProjectManagers", Collection.class).createMock();
    setMockServices(notificationManager);
    Employee sender = new Employee("sender", "sender", "sender", "sender");
    Employee employee = new Employee("iivanov");
    Employee pm = new Employee("ppetrov");
    pm.setEmail("ppetrov@mail.com");
    Project project = createProject(1L, employee);
    List<Employee> employees = Arrays.asList(employee);
    List<Project> projects = Arrays.asList(project);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<>();
    timeProblems.put(employee, new HashMap<>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    EasyMock.expect(notificationManager.getProjects(employees)).andReturn(projects);
    EasyMock.expect(notificationManager.getProjectManagers(projects)).andReturn(Lists.newArrayList(pm));
    EasyMock.expect(hourTypeService.findActualTime()).andReturn(new HourType());
    EasyMock.expect(workTimeService.getWorkTimeDeviations(period, employees)).andReturn(timeProblems);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName()), anyObject(Map.class))).andReturn(body);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    EasyMock.expect(settings.getSmtpUsername()).andReturn("testSmtpUsername");
    EasyMock.expect(settings.getSmtpSender()).andReturn("sender");
    EasyMock.expect(settings.getApplicationBaseUrl()).andReturn("appHost");
    mailingEngine.send(new Mail(subject, body, sender.getEmail(), pm.getEmail()));
    EasyMock.replay(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine, settings);
    notificationManager.notifyProjectManagers(employees, period, comment);
    EasyMock.verify(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 23 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class NotificationManagerTest method testNotifyAboutWorkTimeProblem.

@Test
public void testNotifyAboutWorkTimeProblem() {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("notifyEmployees", List.class, Period.class, String.class).addMockedMethod("notifyProjectManagers", List.class, Period.class, String.class).createMock();
    List<Employee> employees = new ArrayList<>();
    Period period = new Period();
    String comment = "";
    notificationManager.notifyEmployees(employees, period, comment);
    notificationManager.notifyProjectManagers(employees, period, comment);
    replay(notificationManager);
    notificationManager.notifyAboutWorkTimeProblems(employees, period, comment);
    verify(notificationManager);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) ArrayList(java.util.ArrayList) Period(com.artezio.arttime.datamodel.Period) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 24 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class NotificationManagerTest method testNotifyAboutUnapprovedHours_oneEmployee.

@Test
public void testNotifyAboutUnapprovedHours_oneEmployee() throws Exception {
    setMockServices(notificationManager);
    Employee employee = new Employee("user_name");
    String employeeEmail = "user_name@mail.com";
    employee.setEmail(employeeEmail);
    Period period = mock(Period.class);
    String senderEmail = "sender@mail.com";
    String body = "mail_body";
    String subject = "mail_subject";
    Mail mail = new Mail(subject, body, senderEmail, employeeEmail);
    String applicationBaseUrl = "url";
    Map<String, Object> mailParameters = new HashMap<>();
    mailParameters.put("period", period);
    mailParameters.put("appHost", applicationBaseUrl);
    expect(settings.getSmtpSender()).andReturn(senderEmail);
    expect(settings.getApplicationBaseUrl()).andReturn(applicationBaseUrl);
    expect(mailTemplateManager.getTemplateText(MailTemplate.UNAPPROVED_HOURS_BODY.getFileName(), mailParameters)).andReturn(body);
    expect(mailTemplateManager.getTemplateText(MailTemplate.UNAPPROVED_HOURS_SUBJECT.getFileName(), mailParameters)).andReturn(subject);
    mailingEngine.send(mail);
    replay(settings, mailTemplateManager, mailingEngine);
    notificationManager.notifyAboutUnapprovedHours(employee, period);
    verify(settings, mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Example 25 with Period

use of com.artezio.arttime.datamodel.Period in project ART-TIME by Artezio.

the class NotificationManagerTest method testNotifyAboutIncorrectTimesheet_oneEmployee.

@Test
public void testNotifyAboutIncorrectTimesheet_oneEmployee() throws Exception {
    setMockServices(notificationManager);
    Employee employee = new Employee("user_name");
    String employeeEmail = "user_name@mail.com";
    employee.setEmail(employeeEmail);
    Period period = mock(Period.class);
    HourType actualTime = new HourType("actual");
    String senderEmail = "sender@mail.com";
    String body = "mail_body";
    String subject = "mail_subject";
    Mail mail = new Mail(subject, body, senderEmail, employeeEmail);
    String applicationBaseUrl = "url";
    Map<String, Object> mailParameters = new HashMap<>();
    mailParameters.put("hourType", actualTime);
    mailParameters.put("period", period);
    mailParameters.put("appHost", applicationBaseUrl);
    expect(hourTypeService.findActualTime()).andReturn(actualTime);
    expect(settings.getSmtpSender()).andReturn(senderEmail);
    expect(settings.getApplicationBaseUrl()).andReturn(applicationBaseUrl);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_BODY.getFileName(), mailParameters)).andReturn(body);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_SUBJECT.getFileName(), mailParameters)).andReturn(subject);
    mailingEngine.send(mail);
    replay(hourTypeService, settings, mailTemplateManager, mailingEngine);
    notificationManager.notifyAboutIncorrectTimesheet(employee, period);
    verify(hourTypeService, settings, mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Aggregations

Period (com.artezio.arttime.datamodel.Period)93 Test (org.junit.Test)87 Employee (com.artezio.arttime.datamodel.Employee)59 Date (java.util.Date)56 CalendarUtils.getOffsetDate (com.artezio.arttime.test.utils.CalendarUtils.getOffsetDate)44 HourType (com.artezio.arttime.datamodel.HourType)43 Project (com.artezio.arttime.datamodel.Project)42 Hours (com.artezio.arttime.datamodel.Hours)40 BigDecimal (java.math.BigDecimal)34 CalendarUtils.createPeriod (com.artezio.arttime.test.utils.CalendarUtils.createPeriod)22 Day (com.artezio.arttime.datamodel.Day)17 HashMap (java.util.HashMap)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 WorkdaysCalendar (com.artezio.arttime.datamodel.WorkdaysCalendar)13 List (java.util.List)13 Map (java.util.Map)11 ArrayList (java.util.ArrayList)8 GregorianCalendar (java.util.GregorianCalendar)8 HoursRepository (com.artezio.arttime.repositories.HoursRepository)7 Mail (com.artezio.arttime.services.mailing.Mail)7