Search in sources :

Example 26 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class IniWebEnvironmentTest method testAddLdapProperties.

@Test
public void testAddLdapProperties() throws NoSuchFieldException {
    Ini ini = new Ini();
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setLdapPrincipalUsername("username");
    settings.setLdapBindCredentials("password");
    settings.setLdapServerHost("localhost");
    settings.setLdapServerPort("356");
    settings.setLdapPrincipalSuffix("@company.com");
    settings.setExecRoleMemberOf("EXEC_GROUP");
    settings.setLdapUserContextDN("DC=MyCompany,DC=local");
    settings.setLdapCommonNameAttribute("CN");
    setField(iniWebEnvironment, "ini", ini);
    setField(iniWebEnvironment, "settingsService", settingsService);
    expect(settingsService.getSettings()).andReturn(settings);
    replay(settingsService);
    iniWebEnvironment.addLdapProperties(ini);
    verify(settingsService);
    assertEquals("com.artezio.arttime.security.auth.ActiveDirectoryRealm", ini.getSectionProperty("main", "ldapRealm"));
    assertEquals("ldap://localhost:356", ini.getSectionProperty("main", "ldapRealm.url"));
    assertEquals("username", ini.getSectionProperty("main", "ldapRealm.systemUsername"));
    assertEquals("password", ini.getSectionProperty("main", "ldapRealm.systemPassword"));
    assertEquals("DC=MyCompany,DC=local", ini.getSectionProperty("main", "ldapRealm.searchBase"));
    assertEquals("@company.com", ini.getSectionProperty("main", "ldapRealm.principalSuffix"));
    assertEquals("\"CN=EXEC_GROUP,DC=MyCompany,DC=local\":\"exec\"", ini.getSectionProperty("main", "ldapRealm.groupRolesMap"));
}
Also used : Ini(org.apache.shiro.config.Ini) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class MailingEngineTest method testSendMail_byRecipientId.

@Test
public void testSendMail_byRecipientId() throws Exception {
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setSmtpUsername("smtpUser");
    setField(mailingEngine, "settings", settings);
    Employee employee = new Employee("smtpUser");
    employee.setEmail("smtpUser@mail.com");
    PowerMock.mockStatic(Transport.class);
    expect(employeeService.findEmployee("smtpUser")).andReturn(employee);
    Transport.send(anyObject(MimeMessage.class));
    PowerMock.replayAll(Transport.class, employeeService);
    mailingEngine.send("recipient@mail.com", new Mail());
    PowerMock.verifyAll();
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) MimeMessage(javax.mail.internet.MimeMessage) Settings(com.artezio.arttime.config.Settings) URLName(javax.mail.URLName) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class MailingEngineTest method testInitSession.

@Test
public void testInitSession() throws NoSuchFieldException, NoSuchMethodException {
    Session session = PowerMock.createMock(Session.class);
    Settings settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setSmtpHostName("smtp.host");
    settings.setSmtpPortNumber("25");
    settings.setSmtpUsername("TestUser");
    settings.setSmtpPassword("123");
    setField(mailingEngine, "session", session);
    setField(mailingEngine, "settings", settings);
    Properties properties = new Properties();
    expect(session.getProperties()).andReturn(properties).anyTimes();
    PowerMock.stub(Session.class.getMethod("setPasswordAuthentication", URLName.class, PasswordAuthentication.class));
    session.setPasswordAuthentication(anyObject(), anyObject());
    PowerMock.replay(session);
    mailingEngine.initSession();
    verify(session);
    assertEquals(settings.getSmtpHostName(), properties.getProperty("mail.smtp.host"));
    assertEquals(settings.getSmtpPortNumber(), properties.getProperty("mail.smtp.port"));
    assertEquals(settings.getSmtpUsername(), properties.getProperty("mail.smtp.user"));
    assertTrue(Boolean.parseBoolean(properties.getProperty("mail.smtp.auth")));
}
Also used : URLName(javax.mail.URLName) Properties(java.util.Properties) Settings(com.artezio.arttime.config.Settings) Session(javax.mail.Session) URLName(javax.mail.URLName) PasswordAuthentication(javax.mail.PasswordAuthentication) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class SchedulerTest method testActualizeSettings_timeoutHasNotChanged.

@Test
public void testActualizeSettings_timeoutHasNotChanged() throws NoSuchFieldException {
    settings = new Settings(new EnumMap<>(Setting.Name.class));
    settings.setTimerHoursInterval(200);
    settings.setTimerMinutesInterval(500);
    setField(scheduler, "settings", settings);
    expect(settingsService.getSettings()).andReturn(settings);
    replay(settingsService);
    scheduler.actualizeSettings();
    verify(settingsService);
}
Also used : Setting(com.artezio.arttime.config.Setting) EnumMap(java.util.EnumMap) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test)

Example 30 with Settings

use of com.artezio.arttime.config.Settings in project ART-TIME by Artezio.

the class SchedulerTest method testTimeout.

@Test
public void testTimeout() throws NoSuchFieldException {
    synchronizer = createMockBuilder(Synchronizer.class).addMockedMethod("synchronize").createMock();
    setField(scheduler, "synchronizer", synchronizer);
    setField(scheduler, "settingsService", settingsService);
    Settings actual = new Settings(new EnumMap<>(Setting.Name.class));
    expect(settingsService.getSettings()).andReturn(actual);
    synchronizer.synchronize();
    expectLastCall().once();
    replay(synchronizer, settingsService);
    scheduler.timeout();
    verify(synchronizer, settingsService);
}
Also used : Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test)

Aggregations

Settings (com.artezio.arttime.config.Settings)40 Test (org.junit.Test)31 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Setting (com.artezio.arttime.config.Setting)9 EnumMap (java.util.EnumMap)5 Before (org.junit.Before)5 SimpleAccount (org.apache.shiro.authc.SimpleAccount)4 Instance (javax.enterprise.inject.Instance)3 Properties (java.util.Properties)2 URLName (javax.mail.URLName)2 ApplicationSettings (com.artezio.arttime.config.ApplicationSettings)1 Employee (com.artezio.arttime.datamodel.Employee)1 ProjectService (com.artezio.arttime.services.ProjectService)1 SettingsService (com.artezio.arttime.services.SettingsService)1 UserInfo (com.artezio.arttime.services.integration.spi.UserInfo)1 Duration (java.time.Duration)1 java.util (java.util)1 HashMap (java.util.HashMap)1 Timer (javax.ejb.Timer)1 TimerConfig (javax.ejb.TimerConfig)1