<commit_before>/**
 * $Id$
 * $URL$
 **************************************************************************
 * Copyright (c) 2012 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sakaiproject.entitybroker.providers;


import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entitybroker.DeveloperHelperService;
import org.sakaiproject.entitybroker.EntityReference;
import org.sakaiproject.entitybroker.EntityView;
import org.sakaiproject.entitybroker.entityprovider.capabilities.CollectionResolvable;
import org.sakaiproject.entitybroker.entityprovider.extension.ActionReturn;
import org.sakaiproject.entitybroker.entityprovider.extension.EntityData;
import org.sakaiproject.entitybroker.entityprovider.search.Restriction;
import org.sakaiproject.entitybroker.entityprovider.search.Search;
import org.sakaiproject.entitybroker.providers.model.EntityMember;
import org.sakaiproject.entitybroker.providers.model.EntityUser;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.mock.domain.*;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.util.BaseResourceProperties;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class MembershipEntityProviderTest {

    @Mock
    private SiteService siteService;
    @Mock
    private DeveloperHelperService developerHelperService;
    @Mock
    private UserEntityProvider userEntityProvider;
    private MembershipEntityProvider provider;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        provider = new MembershipEntityProvider();
        provider.setSiteService(siteService);
        provider.setDeveloperHelperService(developerHelperService);
        provider.setUserEntityProvider(userEntityProvider);
    }

    @Test
    public void handleSiteMembershipPreservesDotsInSiteIdPathParams_GET() throws IdUnusedException {
        EntityView entityView = new EntityView("/membership/site/site.with.dots.json");
        entityView.setMethod(EntityView.Method.GET);

        Site site = new Site();
        site.setId("site.with.dots");
        EntityUser user = new EntityUser();
        user.setId("user-foo");
        user.setEid("user-foo");
        Member member = new Member();
        member.setUserId("user-foo");
        member.setUserEid("user-foo");
        Map<String,org.sakaiproject.authz.api.Member> members = new HashMap<String,org.sakaiproject.authz.api.Member>();
        members.put("user-foo", member);
        site.setMembers(members);
        when(siteService.getSite("site.with.dots")).thenReturn(site);
        when(developerHelperService.getCurrentUserReference()).thenReturn("/user/me");
        when(siteService.allowViewRoster("site.with.dots")).thenReturn(true);<commit_msg>SAK-25926 Add option to allow users to see group membership in site info fixing test error<commit_after>/**
 * $Id$
 * $URL$
 **************************************************************************
 * Copyright (c) 2012 The Sakai Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.osedu.org/licenses/ECL-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sakaiproject.entitybroker.providers;


import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.entitybroker.DeveloperHelperService;
import org.sakaiproject.entitybroker.EntityReference;
import org.sakaiproject.entitybroker.EntityView;
import org.sakaiproject.entitybroker.entityprovider.capabilities.CollectionResolvable;
import org.sakaiproject.entitybroker.entityprovider.extension.ActionReturn;
import org.sakaiproject.entitybroker.entityprovider.extension.EntityData;
import org.sakaiproject.entitybroker.entityprovider.search.Restriction;
import org.sakaiproject.entitybroker.entityprovider.search.Search;
import org.sakaiproject.entitybroker.providers.model.EntityMember;
import org.sakaiproject.entitybroker.providers.model.EntityUser;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.mock.domain.*;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.util.BaseResourceProperties;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.api.privacy.PrivacyManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class MembershipEntityProviderTest {

    @Mock
    private SiteService siteService;
    @Mock
    private DeveloperHelperService developerHelperService;
    @Mock
    private UserEntityProvider userEntityProvider;
    private MembershipEntityProvider provider;
    @Mock
    private SecurityService securityService;
    @Mock
    private PrivacyManager privacyManager;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        provider = new MembershipEntityProvider();
        provider.setSiteService(siteService);
        provider.setDeveloperHelperService(developerHelperService);
        provider.setUserEntityProvider(userEntityProvider);
    	provider.setSecurityService(securityService);
	provider.setPrivacyManager(privacyManager);
    }

    @Test
    public void handleSiteMembershipPreservesDotsInSiteIdPathParams_GET() throws IdUnusedException {
        EntityView entityView = new EntityView("/membership/site/site.with.dots.json");
        entityView.setMethod(EntityView.Method.GET);

        Site site = new Site();
        site.setId("site.with.dots");
        EntityUser user = new EntityUser();
        user.setId("user-foo");
        user.setEid("user-foo");
        Member member = new Member();
        member.setUserId("user-foo");
        member.setUserEid("user-foo");
        Map<String,org.sakaiproject.authz.api.Member> members = new HashMap<String,org.sakaiproject.authz.api.Member>();
        members.put("user-foo", member);
        site.setMembers(members);
        when(siteService.getSite("site.with.dots")).thenReturn(site);
        when(developerHelperService.getCurrentUserReference()).thenReturn("/user/me");
        when(siteService.allowViewRoster("site.with.dots")).thenReturn(true);
{'fraction_non_alphanumeric': 0.11265592515592515, 'fraction_numerical': 0.002728690228690229, 'mean_word_length': 4.714179658500371, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3026974', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2103, 'n_words': 456}