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);
}
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)));
}
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);
}
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);
}
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();
}
}
Aggregations