/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see .
* #L%
*/
package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.tenant.TenantUtil;
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
import org.alfresco.rest.api.tests.RepoService.TestNetwork;
import org.alfresco.rest.api.tests.RepoService.TestPerson;
import org.alfresco.rest.api.tests.RepoService.TestSite;
import org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse;
import org.alfresco.rest.api.tests.client.PublicApiClient.Paging;
import org.alfresco.rest.api.tests.client.PublicApiClient.Sites;
import org.alfresco.rest.api.tests.client.PublicApiException;
import org.alfresco.rest.api.tests.client.RequestContext;
import org.alfresco.rest.api.tests.client.data.SiteContainer;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
import org.apache.commons.httpclient.HttpStatus;
import org.junit.Before;
import org.junit.Test;
public class TestSiteContainers extends EnterpriseTestApi
{
private TestNetwork network1;
private TestNetwork network2;
private List people1 = new ArrayList(2);
private List people2 = new ArrayList(2);
private TestPerson person11; // site creator
private TestPerson person12; // same network, not invited to site
private TestPerson person13; // same network, invited to site
private TestPerson person21; // different network, not invited to site
private TestSite site1;
@Before
public void setup() throws Exception
{
Iterator networksIt = getTestFixture().getNetworksIt();
assertTrue(networksIt.hasNext());
this.network1 = networksIt.next();
assertTrue(networksIt.hasNext());
this.network2 = networksIt.next();
// Create some users in different networks
TenantUtil.runAsSystemTenant(new TenantRunAsWork()
{
@Override
public Void doWork() throws Exception
{
// add as external user
TestPerson person1 = network1.createUser();
people1.add(person1);
TestPerson person2 = network1.createUser();
people1.add(person2);
TestPerson person3 = network1.createUser();
people1.add(person3);
return null;
}
}, network1.getId());
TenantUtil.runAsSystemTenant(new TenantRunAsWork()
{
@Override
public Void doWork() throws Exception
{
TestPerson person1 = network2.createUser();
people2.add(person1);
return null;
}
}, network2.getId());
this.person11 = people1.get(0); // site creator
this.person12 = people1.get(1); // same network, not invited to site
this.person21 = people2.get(0); // different network, not invited to site
this.person13 = people1.get(2); // same network, invited to site
// TenantUtil.runAsSystemTenant(new TenantRunAsWork()
// {
// @Override
// public Void doWork() throws Exception
// {
// // add as external user
// TestPerson person1 = network2.createUser();
// network2People.add(person1);
//
// return null;
// }
// }, network2.getId());
//
// final TestPerson person3 = network2People.get(0);
// Create a public site
this.site1 = TenantUtil.runAsUserTenant(new TenantRunAsWork()
{
@Override
public TestSite doWork() throws Exception
{
TestSite testSite = network1.createSite(SiteVisibility.PUBLIC);
return testSite;
}
}, person11.getId(), network1.getId());
TenantUtil.runAsUserTenant(new TenantRunAsWork