### Question:
ConfigurationService { public void saveConfig(final Map<String, Object> configs) throws NotFoundEntityException, GmsGeneralException { if (configs.get("user") != null) { try { long id = Long.parseLong(configs.remove("user").toString()); saveConfig(configs, id); } catch (NumberFormatException e) { throw GmsGeneralException.builder() .messageI18N(CONFIG_USER_PARAM_NUMBER) .cause(e) .finishedOK(false) .httpStatus(HttpStatus.UNPROCESSABLE_ENTITY) .build(); } } String uppercaseKey; for (Map.Entry<String, Object> entry : configs.entrySet()) { uppercaseKey = entry.getKey().toUpperCase(Locale.ENGLISH); if (isValidKey(uppercaseKey) && uppercaseKey.endsWith(IN_SERVER)) { switch (ConfigKey.valueOf(uppercaseKey)) { case IS_MULTI_ENTITY_APP_IN_SERVER: setIsMultiEntity(Boolean.parseBoolean(entry.getValue().toString())); break; case IS_USER_REGISTRATION_ALLOWED_IN_SERVER: setUserRegistrationAllowed(Boolean.parseBoolean(entry.getValue().toString())); break; default: throw new NotFoundEntityException(CONFIG_NOT_FOUND); } } } } @Autowired  ConfigurationService(final BConfigurationRepository configurationRepository,
                                final EUserRepository userRepository, final EOwnedEntityRepository entityRepository,
                                final BRoleRepository roleRepository, final BAuthorizationRepository authRepository,
                                final DefaultConst defaultConst); boolean isApplicationConfigured(); boolean isDefaultConfigurationCreated(); boolean isDefaultUserAssignedToEntityWithRole(); Map<String, String> getConfig(); Object getConfig(final String key); String getConfig(final String key, final long userId); Map<String, Object> getConfigByUser(final long userId); void saveConfig(final Map<String, Object> configs); void saveConfig(final Map<String, Object> configs, final long userId); void setUserRegistrationAllowed(final boolean userRegistrationAllowed); void setIsMultiEntity(final boolean isMultiEntity); Long getLastAccessedEntityIdByUser(final long userId); void setLastAccessedEntityIdByUser(final long userId, final long entityId); static final String IN_SERVER; static final String CONFIG_NOT_FOUND; }### Answer:
@Test public void saveConfig() { List<Iterable<BConfiguration>> list = deleteAllServerConfig(); Map<String, Object> configs = new HashMap<>(); configs.put(keyUserRegistrationAllowed, false); configs.put(keyMultiEntityApp, true); try { configurationService.saveConfig(configs); BConfiguration cR = configurationRepository.findFirstByKey(keyUserRegistrationAllowed); assertNotNull(cR); assertEquals(Boolean.toString(false), cR.getValue()); cR = configurationRepository.findFirstByKey(keyMultiEntityApp); assertNotNull(cR); assertEquals(Boolean.toString(true), cR.getValue()); } catch (NotFoundEntityException e) { LOGGER.error(e.getLocalizedMessage()); fail("At least one of the keys was not found."); } catch (GmsGeneralException e) { LOGGER.error(e.getLocalizedMessage()); fail("The provided user key was not valid"); } assertTrue(hasRestoredAllServerConfig(list)); }
@Test public void saveConfigForUser() { EUser u = userRepository.save(EntityUtil.getSampleUser(random.nextString())); EOwnedEntity e = entityRepository.save(EntityUtil.getSampleEntity(random.nextString())); assertNotNull(u); Map<String, Object> configs = new HashMap<>(); configs.put(keyLang, "fr"); configs.put(keyLastAccessedEntity, e.getId()); try { configurationService.saveConfig(configs, u.getId()); } catch (NotFoundEntityException e1) { LOGGER.error(e1.getLocalizedMessage()); fail("At least one of the keys was not found."); } }
@Test public void saveConfigKeyNotFound() { Map<String, Object> configs = new HashMap<>(); configs.put(random.nextString(), random.nextString()); boolean success = false; try { configurationService.saveConfig(configs); } catch (GmsGeneralException e) { LOGGER.error(e.getLocalizedMessage()); fail("There was not provided user and the test still failed because of it"); } catch (Exception e) { success = true; } assertTrue(success); }