PUMAConfig extends Config { public Map<String, Collection<String>> getGroupMapping(XWikiContext context) { return getOneToManyParam("groupsMapping", '|', null, false, context); } PUMAConfig(); String getUserUidField(XWikiContext context); Map<String, String> getUserMapping(XWikiContext context); Map<String, Collection<String>> getGroupMapping(XWikiContext context); XWikiAuthService getFallbackAuthenticator(XWikiContext context);  }
@Test public void testGetGroupMappingsWithoutProperty() throws Exception { this.mockery.checking(new Expectations() {{ allowing(xwikiMock).getXWikiPreference("puma_groupsMapping", getContext()); will(returnValue(null)); allowing(xwikiMock).Param("xwiki.authentication.puma.groupsMapping"); will(returnValue(null)); }}); Map<String, Collection<String>> groupMapping = this.config.getGroupMapping(getContext()); Assert.assertNull(groupMapping); }
@Test public void testGetGroupMappingsWithEmptyProperty() throws Exception { this.mockery.checking(new Expectations() {{ allowing(xwikiMock).getXWikiPreference("puma_groupsMapping", getContext()); will(returnValue("")); allowing(xwikiMock).Param("xwiki.authentication.puma.groupsMapping"); will(returnValue("")); }}); Map<String, Collection<String>> groupMapping = this.config.getGroupMapping(getContext()); Assert.assertTrue(groupMapping.isEmpty()); }
@Test public void testGetGroupMappingsWithOneCouple() throws Exception { this.mockery.checking(new Expectations() {{ allowing(xwikiMock).getXWikiPreference("puma_groupsMapping", getContext()); will(returnValue("xwikigroup=pumagroup")); }}); Map<String, Collection<String>> groupMapping = this.config.getGroupMapping(getContext()); Assert.assertEquals(new HashSet<String>(Arrays.asList("xwikigroup")), groupMapping.get("pumagroup")); }
@Test public void testGetGroupMappingsWithTwoCouples() throws Exception { this.mockery.checking(new Expectations() {{ allowing(xwikiMock).getXWikiPreference("puma_groupsMapping", getContext()); will(returnValue("xwikigroup=pumagroup|xwikigroup2=pumagroup2")); }}); Map<String, Collection<String>> groupMapping = this.config.getGroupMapping(getContext()); Assert.assertEquals(new HashSet<String>(Arrays.asList("xwikigroup")), groupMapping.get("pumagroup")); Assert.assertEquals(new HashSet<String>(Arrays.asList("xwikigroup2")), groupMapping.get("pumagroup2")); }
@Test public void testGetGroupMappingsWithTwoCouplesMixed() throws Exception { this.mockery.checking(new Expectations() {{ allowing(xwikiMock).getXWikiPreference("puma_groupsMapping", getContext()); will(returnValue("xwikigroup=pumagroup|xwikigroup2=pumagroup|xwikigroup=pumagroup2|xwikigroup2=pumagroup2")); }}); Map<String, Collection<String>> groupMapping = this.config.getGroupMapping(getContext()); Assert.assertEquals(new HashSet<String>(Arrays.asList("xwikigroup", "xwikigroup2")), groupMapping .get("pumagroup")); Assert.assertEquals(new HashSet<String>(Arrays.asList("xwikigroup", "xwikigroup2")), groupMapping .get("pumagroup2")); }