import java.util.List;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import eu.dnetlib.api.functionality.CommunityService;
import eu.dnetlib.api.functionality.CommunityServiceException;
import eu.dnetlib.domain.functionality.Community;
import eu.dnetlib.domain.functionality.CommunitySearchCriteria;
import gr.uoa.di.driver.util.ServiceLocator;


public class TestCommunityWebService {
	private static ServiceLocator<CommunityService> serviceLocator = null;
	private static ApplicationContext applicationContext = null;
	
	@SuppressWarnings("unchecked")
	@BeforeClass
	public static void setup() {
		applicationContext = new ClassPathXmlApplicationContext(new String[] { "file:///home/thanos/dnet11/setup/uoa-trunk/uoa-community/test/junit/cxf-config.xml" });
		serviceLocator = (ServiceLocator<CommunityService>) applicationContext.getBean("communityLocator");
	}
	
	@Test
	public void testService() throws CommunityServiceException {
		Community community = new Community();
		community.setName("foo");
		community.setDescription("bar");
		community.setShortDescription("buz");
		community.setResourceUri("hello.world");
		community.setOwner("4-3a051c0f-ca38-43af-8fc0-3e1635877841_VXNlckRTUmVzb3VyY2VzL1VzZXJEU1Jlc291cmNlVHlwZQ==");
		Assert.assertNotNull("serviceLocator is null", serviceLocator);
		community = serviceLocator.getService().saveCommunity(community);
		Assert.assertNotNull("community is null", community);
		List<Community> communityList = serviceLocator.getService().searchCommunities((new CommunitySearchCriteria()));
		Assert.assertNotNull("communityList is null", communityList);
		Assert.assertTrue(communityList.size() > 0);
		serviceLocator.getService().deleteCommunityById(community.getResourceId());		
	}
}
