Program: 174733
Project: 174733
Buggy source:
@Test public void testSiteMembers() throws Exception {
  Iterator<TestNetwork> networksIt=getTestFixture().getNetworksIt();
  final TestNetwork testNetwork=networksIt.next();
  final List<String> networkPeople=testNetwork.getPersonIds();
  String personId=networkPeople.get(0);
  Sites sitesProxy=publicApiClient.sites();
{
    final List<SiteMember> expectedSiteMembers=new ArrayList<SiteMember>();
    TestSite testSite=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite testSite=testNetwork.createSite(SiteVisibility.PRIVATE);
        for (int i=1; i <= 5; i++) {
          String inviteeId=networkPeople.get(i);
          testSite.inviteToSite(inviteeId,SiteRole.SiteConsumer);
          SiteMember sm=new SiteMember(inviteeId,repoService.getPerson(inviteeId),testSite.getSiteId(),SiteRole.SiteConsumer.toString());
          expectedSiteMembers.add(sm);
        }
        return testSite;
      }
    }
,personId,testNetwork.getId());
{
      SiteMember sm=new SiteMember(personId,repoService.getPerson(personId),testSite.getSiteId(),SiteRole.SiteManager.toString());
      expectedSiteMembers.add(sm);
      Collections.sort(expectedSiteMembers);
    }
{
      int skipCount=0;
      int maxItems=2;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(testSite.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
    }
{
      int skipCount=2;
      int maxItems=10;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(testSite.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      HttpResponse response=sitesProxy.getAll("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,createParams(paging,Collections.singletonMap("String_Node_Str","String_Node_Str")),"String_Node_Str");
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),SiteMember.parseSiteMembers(testSite.getSiteId(),response.getJsonResponse()));
      JSONObject source=sitesProxy.parseListSource(response.getJsonResponse());
      Site sourceSite=SiteImpl.parseSite(source);
      assertNotNull(sourceSite);
      testSite.expected(sourceSite);
    }
    try {
      int skipCount=2;
      int maxItems=10;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.getSiteMembers(GUID.generate(),createParams(paging,null));
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.update("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,siteMember.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.create("String_Node_Str",testSite.getSiteId(),"String_Node_Str",siteMember1.getMemberId(),siteMember1.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.update("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,siteMember1.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.remove("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
{
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      SiteMember ret=sitesProxy.updateSiteMember(testSite.getSiteId(),siteMember1);
      assertEquals(siteMember1.getRole(),ret.getRole());
      Person expectedSiteMember=repoService.getPerson(siteMember1.getMemberId());
      expectedSiteMember.expected(ret.getMember());
    }
{
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      SiteMember ret=sitesProxy.getSingleSiteMember(testSite.getSiteId(),siteMember1.getMemberId());
      siteMember1.expected(ret);
    }
  }
{
    Iterator<TestNetwork> accountsIt=getTestFixture().getNetworksIt();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network1=accountsIt.next();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network2=accountsIt.next();
    final List<TestPerson> people=new ArrayList<TestPerson>();
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        return null;
      }
    }
,network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network2.createUser();
        people.add(person);
        return null;
      }
    }
,network2.getId());
    final TestPerson person1=people.get(0);
    final TestPerson person2=people.get(1);
    final TestPerson person3=people.get(2);
    final TestPerson person4=people.get(3);
    final TestSite site=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite site=network1.createSite(SiteVisibility.PUBLIC);
        return site;
      }
    }
,person2.getId(),network1.getId());
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),"String_Node_Str"));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person3.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_FORBIDDEN,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember("String_Node_Str",SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember("String_Node_Str",new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_FORBIDDEN,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person4.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_UNAUTHORIZED,e.getHttpResponse().getStatusCode());
    }
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember sm=new SiteMember(person1.getId(),SiteRole.SiteConsumer.toString());
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),sm);
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteConsumer.toString(),siteMember.getRole());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_CONFLICT,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person4.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person4.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    List<SiteMember> expectedSiteMembers=site.getMembers();
{
      int skipCount=0;
      int maxItems=Integer.MAX_VALUE;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
    }
  }
{
    Iterator<TestNetwork> accountsIt=getTestFixture().getNetworksIt();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network1=accountsIt.next();
    assertTrue(accountsIt.hasNext());
    final List<TestPerson> people=new ArrayList<TestPerson>();
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        return null;
      }
    }
,network1.getId());
    TestPerson person1=people.get(0);
    TestPerson person2=people.get(1);
    TestSite site=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite site=network1.createSite(SiteVisibility.PRIVATE);
        return site;
      }
    }
,person2.getId(),network1.getId());
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteContributor.toString(),siteMember.getRole());
      SiteMember toRemove=new SiteMember("String_Node_Str");
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.removeSiteMember(site.getSiteId(),toRemove);
    }
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteContributor.toString(),siteMember.getRole());
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(GUID.generate(),siteMember);
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(site.getSiteId(),new SiteMember(GUID.generate()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
{
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(site.getSiteId(),siteMember);
      }
      List<SiteMember> expectedSiteMembers=site.getMembers();
      assertFalse(expectedSiteMembers.contains(siteMember));
{
        int skipCount=0;
        int maxItems=Integer.MAX_VALUE;
        Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
        checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(GUID.generate(),siteMember);
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(GUID.generate()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(person1.getId(),"String_Node_Str"));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
      }
{
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        SiteMember sm=new SiteMember(person1.getId(),SiteRole.SiteContributor.toString());
        SiteMember ret=sitesProxy.createSiteMember(site.getSiteId(),sm);
        assertEquals(SiteRole.SiteContributor.toString(),ret.getRole());
        person1.expected(ret.getMember());
        sm=new SiteMember(person1.getId(),SiteRole.SiteCollaborator.toString());
        ret=sitesProxy.updateSiteMember(site.getSiteId(),sm);
        assertEquals(SiteRole.SiteCollaborator.toString(),ret.getRole());
        person1.expected(ret.getMember());
        expectedSiteMembers=site.getMembers();
        SiteMember toCheck=null;
        for (        SiteMember sm1 : expectedSiteMembers) {
          if (sm1.getMemberId().equals(person1.getId())) {
            toCheck=sm1;
          }
        }
        assertNotNull(toCheck);
        assertEquals(sm.getRole(),toCheck.getRole());
        int skipCount=0;
        int maxItems=Integer.MAX_VALUE;
        Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
        checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      }
    }
  }
}

Fixed version (ground truth):
@Test public void testSiteMembers() throws Exception {
  Iterator<TestNetwork> networksIt=getTestFixture().getNetworksIt();
  final TestNetwork testNetwork=networksIt.next();
  final List<String> networkPeople=testNetwork.getPersonIds();
  String personId=networkPeople.get(0);
  Sites sitesProxy=publicApiClient.sites();
{
    final List<SiteMember> expectedSiteMembers=new ArrayList<SiteMember>();
    TestSite testSite=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite testSite=testNetwork.createSite(SiteVisibility.PRIVATE);
        for (int i=1; i <= 5; i++) {
          String inviteeId=networkPeople.get(i);
          testSite.inviteToSite(inviteeId,SiteRole.SiteConsumer);
          SiteMember sm=new SiteMember(inviteeId,repoService.getPerson(inviteeId),testSite.getSiteId(),SiteRole.SiteConsumer.toString());
          expectedSiteMembers.add(sm);
        }
        return testSite;
      }
    }
,personId,testNetwork.getId());
{
      SiteMember sm=new SiteMember(personId,repoService.getPerson(personId),testSite.getSiteId(),SiteRole.SiteManager.toString());
      expectedSiteMembers.add(sm);
      Collections.sort(expectedSiteMembers);
    }
{
      int skipCount=0;
      int maxItems=2;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(testSite.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
    }
{
      int skipCount=2;
      int maxItems=10;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(testSite.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      HttpResponse response=sitesProxy.getAll("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,createParams(paging,Collections.singletonMap("String_Node_Str","String_Node_Str")),"String_Node_Str");
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),SiteMember.parseSiteMembers(testSite.getSiteId(),response.getJsonResponse()));
      JSONObject source=sitesProxy.parseListSource(response.getJsonResponse());
      Site sourceSite=SiteImpl.parseSite(source);
      assertNotNull(sourceSite);
      testSite.expected(sourceSite);
    }
    try {
      int skipCount=2;
      int maxItems=10;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.getSiteMembers(GUID.generate(),createParams(paging,null));
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.update("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,siteMember.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.create("String_Node_Str",testSite.getSiteId(),"String_Node_Str",siteMember1.getMemberId(),siteMember1.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.update("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,siteMember1.toJSON().toString(),"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      sitesProxy.remove("String_Node_Str",testSite.getSiteId(),"String_Node_Str",null,"String_Node_Str");
      fail();
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED,e.getHttpResponse().getStatusCode());
    }
{
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      SiteMember ret=sitesProxy.updateSiteMember(testSite.getSiteId(),siteMember1);
      assertEquals(siteMember1.getRole(),ret.getRole());
      Person expectedSiteMember=repoService.getPerson(siteMember1.getMemberId());
      expectedSiteMember.expected(ret.getMember());
    }
{
      SiteMember siteMember1=expectedSiteMembers.get(0);
      publicApiClient.setRequestContext(new RequestContext(testNetwork.getId(),personId));
      SiteMember ret=sitesProxy.getSingleSiteMember(testSite.getSiteId(),siteMember1.getMemberId());
      siteMember1.expected(ret);
    }
  }
{
    Iterator<TestNetwork> accountsIt=getTestFixture().getNetworksIt();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network1=accountsIt.next();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network2=accountsIt.next();
    final List<TestPerson> people=new ArrayList<TestPerson>();
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        return null;
      }
    }
,network1.getId());
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network2.createUser();
        people.add(person);
        return null;
      }
    }
,network2.getId());
    final TestPerson person1=people.get(0);
    final TestPerson person2=people.get(1);
    final TestPerson person3=people.get(2);
    final TestPerson person4=people.get(3);
    final TestSite site=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite site=network1.createSite(SiteVisibility.PUBLIC);
        return site;
      }
    }
,person2.getId(),network1.getId());
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),"String_Node_Str"));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person3.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_FORBIDDEN,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember("String_Node_Str",SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember("String_Node_Str",new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_FORBIDDEN,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person4.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_UNAUTHORIZED,e.getHttpResponse().getStatusCode());
    }
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember sm=new SiteMember(person1.getId(),SiteRole.SiteConsumer.toString());
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),sm);
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteConsumer.toString(),siteMember.getRole());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_CONFLICT,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person4.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person4.getId(),SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(e.getMessage(),HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(null,SiteRole.SiteContributor.toString()));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
    }
    try {
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),null));
      fail("String_Node_Str");
    }
 catch (    PublicApiException e) {
      assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
    }
    List<SiteMember> expectedSiteMembers=site.getMembers();
{
      int skipCount=0;
      int maxItems=Integer.MAX_VALUE;
      Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
      ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
      checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
    }
  }
{
    Iterator<TestNetwork> accountsIt=getTestFixture().getNetworksIt();
    assertTrue(accountsIt.hasNext());
    final TestNetwork network1=accountsIt.next();
    assertTrue(accountsIt.hasNext());
    final List<TestPerson> people=new ArrayList<TestPerson>();
    TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>(){
      @Override public Void doWork() throws Exception {
        TestPerson person=network1.createUser();
        people.add(person);
        person=network1.createUser();
        people.add(person);
        return null;
      }
    }
,network1.getId());
    TestPerson person1=people.get(0);
    TestPerson person2=people.get(1);
    TestSite site=TenantUtil.runAsUserTenant(new TenantRunAsWork<TestSite>(){
      @Override public TestSite doWork() throws Exception {
        TestSite site=network1.createSite(SiteVisibility.PRIVATE);
        return site;
      }
    }
,person2.getId(),network1.getId());
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteContributor.toString(),siteMember.getRole());
      SiteMember toRemove=new SiteMember("String_Node_Str");
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person1.getId()));
      sitesProxy.removeSiteMember(site.getSiteId(),toRemove);
    }
{
      publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
      SiteMember siteMember=sitesProxy.createSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
      assertEquals(person1.getId(),siteMember.getMemberId());
      assertEquals(SiteRole.SiteContributor.toString(),siteMember.getRole());
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(GUID.generate(),siteMember);
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(site.getSiteId(),new SiteMember(GUID.generate()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
{
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.removeSiteMember(site.getSiteId(),siteMember);
      }
      List<SiteMember> expectedSiteMembers=site.getMembers();
      assertFalse(expectedSiteMembers.contains(siteMember));
{
        int skipCount=0;
        int maxItems=Integer.MAX_VALUE;
        Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
        checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(GUID.generate(),siteMember);
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(GUID.generate()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_NOT_FOUND,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(person1.getId(),"String_Node_Str"));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
      }
      try {
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        sitesProxy.updateSiteMember(site.getSiteId(),new SiteMember(person1.getId(),SiteRole.SiteContributor.toString()));
        fail();
      }
 catch (      PublicApiException e) {
        assertEquals(HttpStatus.SC_BAD_REQUEST,e.getHttpResponse().getStatusCode());
      }
{
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        SiteMember sm=new SiteMember(person1.getId(),SiteRole.SiteContributor.toString());
        SiteMember ret=sitesProxy.createSiteMember(site.getSiteId(),sm);
        assertEquals(SiteRole.SiteContributor.toString(),ret.getRole());
        person1.expected(ret.getMember());
        sm=new SiteMember(person1.getId(),SiteRole.SiteCollaborator.toString());
        ret=sitesProxy.updateSiteMember(site.getSiteId(),sm);
        assertEquals(SiteRole.SiteCollaborator.toString(),ret.getRole());
        person1.expected(ret.getMember());
        expectedSiteMembers=site.getMembers();
        SiteMember toCheck=null;
        for (        SiteMember sm1 : expectedSiteMembers) {
          if (sm1.getMemberId().equals(person1.getId())) {
            toCheck=sm1;
          }
        }
        assertNotNull(toCheck);
        assertEquals(sm.getRole(),toCheck.getRole());
        int skipCount=0;
        int maxItems=Integer.MAX_VALUE;
        Paging paging=getPaging(skipCount,maxItems,expectedSiteMembers.size(),null);
        publicApiClient.setRequestContext(new RequestContext(network1.getId(),person2.getId()));
        ListResponse<SiteMember> siteMembers=sitesProxy.getSiteMembers(site.getSiteId(),createParams(paging,null));
        checkList(expectedSiteMembers.subList(skipCount,skipCount + paging.getExpectedPaging().getCount()),paging.getExpectedPaging(),siteMembers);
      }
    }
  }
}