DefaultModelConfiguration extends AbstractLogEnabled implements ModelConfiguration { public String getDefaultReferenceValue(EntityType type) { String name; try { ConfigurationSource configuration = this.componentManager.lookup(ConfigurationSource.class, "xwikiproperties"); name = configuration.getProperty(PREFIX + "reference.default." + type.toString().toLowerCase(), DEFAULT_VALUES.get(type)); } catch (ComponentLookupException e) { getLogger().debug("Failed to load [" + ConfigurationSource.class.getName() + "]. Using default Model values", e); name = DEFAULT_VALUES.get(type); } return name; }  String getDefaultReferenceValue(EntityType type);  }
@Test public void testGetDefaultReferenceNameWhenDefinedInConfiguration() { this.mockery.checking(new Expectations() {{ oneOf(mockSource).getProperty(with(equal("model.reference.default.wiki")), with(any(String.class))); will(returnValue("defaultWiki")); oneOf(mockSource).getProperty(with(equal("model.reference.default.document")), with(any(String.class))); will(returnValue("defaultDocument")); oneOf(mockSource).getProperty(with(equal("model.reference.default.space")), with(any(String.class))); will(returnValue("defaultSpace")); oneOf(mockSource).getProperty(with(equal("model.reference.default.attachment")), with(any(String.class))); will(returnValue("defaultFilename")); oneOf(mockSource).getProperty(with(equal("model.reference.default.object")), with(any(String.class))); will(returnValue("defaultObject")); oneOf(mockSource).getProperty(with(equal("model.reference.default.object_property")), with(any(String.class))); will(returnValue("defaultProperty")); }}); Assert.assertEquals("defaultWiki", this.configuration.getDefaultReferenceValue(EntityType.WIKI)); Assert.assertEquals("defaultDocument", this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)); Assert.assertEquals("defaultSpace", this.configuration.getDefaultReferenceValue(EntityType.SPACE)); Assert.assertEquals("defaultFilename", this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)); Assert.assertEquals("defaultObject", this.configuration.getDefaultReferenceValue(EntityType.OBJECT)); Assert.assertEquals("defaultProperty", this.configuration.getDefaultReferenceValue(EntityType.OBJECT_PROPERTY)); }
@Test public void testGetDefaultReferenceNameWhenNotDefinedInConfiguration() { this.mockery.checking(new Expectations() {{ oneOf(mockSource).getProperty("model.reference.default.wiki", "xwiki"); will(returnValue("xwiki")); oneOf(mockSource).getProperty("model.reference.default.document", "WebHome"); will(returnValue("WebHome")); oneOf(mockSource).getProperty("model.reference.default.space", "Main"); will(returnValue("Main")); oneOf(mockSource).getProperty("model.reference.default.attachment", "filename"); will(returnValue("filename")); oneOf(mockSource).getProperty("model.reference.default.object", "object"); will(returnValue("Main.WebHome")); oneOf(mockSource).getProperty("model.reference.default.object_property", "property"); will(returnValue("property")); }}); Assert.assertEquals("xwiki", this.configuration.getDefaultReferenceValue(EntityType.WIKI)); Assert.assertEquals("WebHome", this.configuration.getDefaultReferenceValue(EntityType.DOCUMENT)); Assert.assertEquals("Main", this.configuration.getDefaultReferenceValue(EntityType.SPACE)); Assert.assertEquals("filename", this.configuration.getDefaultReferenceValue(EntityType.ATTACHMENT)); Assert.assertEquals("Main.WebHome", configuration.getDefaultReferenceValue(EntityType.OBJECT)); Assert.assertEquals("property", configuration.getDefaultReferenceValue(EntityType.OBJECT_PROPERTY)); }