Search in sources :

Example 16 with Settings

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

the class TrackingSystemProducerTest method testGetDepartmentTrackingSystem.

@Test
public void testGetDepartmentTrackingSystem() throws NoSuchFieldException {
    Settings settings = createMock(Settings.class);
    Instance instance = createMock(Instance.class);
    trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).addMockedMethod("findImplementationByName", Instance.class, String.class).createMock();
    setField(trackingSystemProducer, "departmentTrackingSystems", instance);
    setField(trackingSystemProducer, "settings", settings);
    DepartmentTrackingSystem expectedImpl = createMock(DepartmentTrackingSystem.class);
    expect(trackingSystemProducer.findImplementationByName(instance, "ExpectedImpl")).andReturn(expectedImpl);
    expect(settings.getDepartmentTrackingSystemName()).andReturn("ExpectedImpl");
    replayAll(instance, settings, expectedImpl, trackingSystemProducer);
    DepartmentTrackingSystem actual = trackingSystemProducer.getDepartmentTrackingSystem();
    PowerMock.verifyAll();
    assertEquals(expectedImpl, actual);
}
Also used : Instance(javax.enterprise.inject.Instance) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with Settings

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

the class KeycloakClientTest method testLoadUserGroups.

@Test
public void testLoadUserGroups() throws NoSuchFieldException {
    keycloakClient = createMockBuilder(KeycloakClient.class).addMockedMethod("listGroups", UserRepresentation.class, RealmResource.class).createMock();
    setField(keycloakClient, "settings", settings);
    String departmentAttribute = "department";
    settings.setKeycloakUserDepartmentAttribute(departmentAttribute);
    String username1 = "user1";
    String username2 = "user2";
    String username3 = "user3";
    String group1 = "grp1";
    String group2 = "grp2";
    String group3 = "grp3";
    Map<String, List<String>> user1attributes = new HashMap<>();
    Map<String, List<String>> user2attributes = new HashMap<>();
    Map<String, List<String>> user3attributes = new HashMap<>();
    List<String> user1groups = Arrays.asList(group1, group2);
    List<String> user2groups = Arrays.asList(group1, group3);
    List<String> user3groups = Arrays.asList(group3);
    user1attributes.put(departmentAttribute, user1groups);
    user2attributes.put(departmentAttribute, user2groups);
    user3attributes.put(departmentAttribute, user3groups);
    UserRepresentation user1 = new UserRepresentation();
    UserRepresentation user2 = new UserRepresentation();
    UserRepresentation user3 = new UserRepresentation();
    user1.setUsername(username1);
    user2.setUsername(username2);
    user3.setUsername(username3);
    user1.setAttributes(user1attributes);
    user2.setAttributes(user2attributes);
    user3.setAttributes(user3attributes);
    RealmResource mockRealm = mock(RealmResource.class);
    expect(keycloakClient.listGroups(user1, mockRealm)).andReturn(new HashSet<>(user1groups));
    expect(keycloakClient.listGroups(user2, mockRealm)).andReturn(new HashSet<>(user2groups));
    expect(keycloakClient.listGroups(user3, mockRealm)).andReturn(new HashSet<>(user3groups));
    replay(keycloakClient);
    Map<String, List<UserInfo>> actual = keycloakClient.loadUserGroups(Arrays.asList(user1, user2, user3), mockRealm);
    verify(keycloakClient);
    assertTrue(actual.containsKey(group1));
    assertTrue(actual.containsKey(group2));
    assertTrue(actual.containsKey(group3));
    List<UserInfo> userInfosGroup1 = actual.get(group1);
    List<UserInfo> userInfosGroup2 = actual.get(group2);
    List<UserInfo> userInfosGroup3 = actual.get(group3);
    assertTrue(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username1)));
    assertTrue(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username2)));
    assertFalse(userInfosGroup1.stream().anyMatch(u -> u.getUsername().equals(username3)));
    assertTrue(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username1)));
    assertFalse(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username2)));
    assertFalse(userInfosGroup2.stream().anyMatch(u -> u.getUsername().equals(username3)));
    assertFalse(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username1)));
    assertTrue(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username2)));
    assertTrue(userInfosGroup3.stream().anyMatch(u -> u.getUsername().equals(username3)));
}
Also used : TimerService(javax.ejb.TimerService) java.util(java.util) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) RealmResource(org.keycloak.admin.client.resource.RealmResource) Settings(com.artezio.arttime.config.Settings) RunWith(org.junit.runner.RunWith) TimerConfig(javax.ejb.TimerConfig) UsersResource(org.keycloak.admin.client.resource.UsersResource) PrivateAccessor.setField(junitx.util.PrivateAccessor.setField) TestSubject(org.easymock.TestSubject) Test(org.junit.Test) GroupRepresentation(org.keycloak.representations.idm.GroupRepresentation) EasyMock(org.easymock.EasyMock) Setting(com.artezio.arttime.config.Setting) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) EnvironmentVariables(org.junit.contrib.java.lang.system.EnvironmentVariables) Timer(javax.ejb.Timer) Rule(org.junit.Rule) Duration(java.time.Duration) EasyMockRunner(org.easymock.EasyMockRunner) UserResource(org.keycloak.admin.client.resource.UserResource) Assert(org.junit.Assert) Before(org.junit.Before) RealmResource(org.keycloak.admin.client.resource.RealmResource) UserInfo(com.artezio.arttime.services.integration.spi.UserInfo) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) Test(org.junit.Test)

Example 18 with Settings

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

the class SettingsBeanTest method testGetSettings_ifNotNull.

@Test
public void testGetSettings_ifNotNull() throws Exception {
    settings = new Settings(new EnumMap<>(Setting.Name.class));
    setField(settingsBean, "settings", settings);
    Settings actual = settingsBean.getSettings();
    assertSame(settings, actual);
}
Also used : Setting(com.artezio.arttime.config.Setting) EnumMap(java.util.EnumMap) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test)

Example 19 with Settings

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

the class AdminRealm method doGetAuthorizationInfo.

@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
    String username = getAvailablePrincipal(principals).toString();
    Settings settings = getSettings();
    return getAccount(username, settings);
}
Also used : Settings(com.artezio.arttime.config.Settings)

Example 20 with Settings

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

the class Scheduler method actualizeSettings.

protected void actualizeSettings() {
    Settings currentSettings = settings;
    Settings actualSettings = settingsService.getSettings();
    settings = actualSettings;
    if (actualSettings != null && !currentSettings.hasSameTimerSettings(actualSettings)) {
        createIntervalTimer();
    }
}
Also used : ApplicationSettings(com.artezio.arttime.config.ApplicationSettings) Settings(com.artezio.arttime.config.Settings)

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