BackwardCompatibleUtil { @Deprecated public ConfigGroup compat(final ConfigGroup configGroup) { if (configGroup != null) { final ConfigItem<List<String>> roles = configGroup.getConfigItem("security:roles"); if (roles != null) { configGroup.addConfigItem(configurationFactory.newConfigItem("security:groups", new ArrayList<String>(roles.getValue()))); configGroup.removeConfigItem("security:roles"); } final ConfigItem<List<String>> groups = configGroup.getConfigItem("security:groups"); if (groups == null) { configGroup.addConfigItem(configurationFactory.newConfigItem("security:groups", new ArrayList<String>())); } } return configGroup; } BackwardCompatibleUtil(); @Inject  BackwardCompatibleUtil(ConfigurationFactory configurationFactory); @Deprecated ConfigGroup compat(final ConfigGroup configGroup);  }
@Test public void backwardCompatibilityNullTest() { final ConfigurationFactory factory = new ConfigurationFactoryImpl(); final BackwardCompatibleUtil backwardUtil = new BackwardCompatibleUtil(factory); assertNull(backwardUtil.compat(null)); }
@Test public void backwardCompatibilityNullSecurityRolesTest() { final ConfigurationFactory factory = new ConfigurationFactoryImpl(); final BackwardCompatibleUtil backwardUtil = new BackwardCompatibleUtil(factory); final ConfigGroup group = factory.newConfigGroup(ConfigType.PROJECT, "cool", "test"); assertNotNull(backwardUtil.compat(group)); assertNotNull(backwardUtil.compat(group).getConfigItem("security:groups")); }
@Test public void backwardCompatibilityExistingSecurityRolesTest() { final ConfigurationFactory factory = new ConfigurationFactoryImpl(); final BackwardCompatibleUtil backwardUtil = new BackwardCompatibleUtil(factory); final ConfigGroup group = factory.newConfigGroup(ConfigType.PROJECT, "cool2", "test2"); group.addConfigItem(factory.newConfigItem("security:roles", new ArrayList() {{ add("group1"); }})); assertNotNull(backwardUtil.compat(group).getConfigItem("security:groups")); assertEquals(1, ((List<String>) (backwardUtil.compat(group).getConfigItem("security:groups")).getValue()).size()); assertNull(backwardUtil.compat(group).getConfigItem("security:roles")); }
@Test public void backwardCompatibilityEmptySecurityRolesTest() { final ConfigurationFactory factory = new ConfigurationFactoryImpl(); final BackwardCompatibleUtil backwardUtil = new BackwardCompatibleUtil(factory); final ConfigGroup group = factory.newConfigGroup(ConfigType.PROJECT, "cool3", "test3"); group.addConfigItem(factory.newConfigItem("security:roles", new ArrayList())); assertNotNull(backwardUtil.compat(group).getConfigItem("security:groups")); assertEquals(0, ((List<String>) (backwardUtil.compat(group).getConfigItem("security:groups")).getValue()).size()); assertNull(backwardUtil.compat(group).getConfigItem("security:roles")); }