ConfigurationFactoryImpl implements ConfigurationFactory { @Override public ConfigGroup newConfigGroup(final ConfigType type, final String name, final String description) { if (type.hasNamespace()) { throw new RuntimeException("The ConfigType " + type.toString() + " requires a namespace."); } final ConfigGroup configGroup = new ConfigGroup(); configGroup.setDescription(description); configGroup.setName(name); configGroup.setType(type); configGroup.setEnabled(true); return configGroup; } ConfigurationFactoryImpl(); @Inject  ConfigurationFactoryImpl(final PasswordService secureService); @Override ConfigGroup newConfigGroup(final ConfigType type,
                                      final String name,
                                      final String description); @Override ConfigGroup newConfigGroup(final ConfigType type,
                                      final String namespace,
                                      final String name,
                                      final String description); @Override ConfigItem<String> newConfigItem(final String name,
                                            final String valueType); @Override ConfigItem<Boolean> newConfigItem(final String name,
                                             final boolean valueType); @Override SecureConfigItem newSecuredConfigItem(final String name,
                                                 final String valueType); @Override ConfigItem<List> newConfigItem(String name,
                                          List valueType); @Override ConfigItem<Object> newConfigItem(String name,
                                            Object valueType);  }
@Test public void newConfigGroupWithoutNamespaceTest() { final ConfigGroup configGroup = configurationFactory.newConfigGroup(ConfigType.GLOBAL, "my-config", "my-description"); assertEquals(ConfigType.GLOBAL, configGroup.getType()); assertEquals("my-config", configGroup.getName()); assertEquals("my-description", configGroup.getDescription()); assertTrue(configGroup.isEnabled()); }
@Test(expected = RuntimeException.class) public void newConfigGroupWithoutNamespaceButTypeRequiresNamespaceTest() { configurationFactory.newConfigGroup(ConfigType.REPOSITORY, "my-config", "my-description"); }
@Test public void newConfigGroupWithNamespaceTest() { final ConfigGroup configGroup = configurationFactory.newConfigGroup(ConfigType.REPOSITORY, "my-namespace", "my-config", "my-description"); assertEquals(ConfigType.REPOSITORY, configGroup.getType()); assertEquals("my-namespace", configGroup.getNamespace()); assertEquals("my-config", configGroup.getName()); assertEquals("my-description", configGroup.getDescription()); assertTrue(configGroup.isEnabled()); }
@Test(expected = RuntimeException.class) public void newConfigGroupWithNamespaceButTypeDoesNotSupportNamespacesTest() { configurationFactory.newConfigGroup(ConfigType.GLOBAL, "my-namespace", "my-config", "my-description"); }