
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.junit.Before;
import org.junit.Test;

import eu.dnetlib.api.functionality.CommunityServiceException;
import eu.dnetlib.clients.functionality.community.ws.CommunityWebService;
import eu.dnetlib.clients.functionality.community.ws.CommunityWebServiceClient;
import eu.dnetlib.domain.functionality.Community;


public class CommunityService {

	private static CommunityWebServiceClient communityService = null;
	
	@Before
	public void setup() throws Throwable {
		try {
			communityService = new CommunityWebServiceClient();
			JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
			factory.setServiceClass(CommunityWebService.class);
			factory.setAddress("http://vatopedi.di.uoa.gr:8280/uoa-community-latest/services/communityWebService");

			CommunityWebService webService = (CommunityWebService) factory.create();
			communityService.setWebService(webService);
		} catch (Throwable t) {
			t.printStackTrace();

			throw t;
		}
	}
	
	@Test
	public void testSaveCommunity() throws CommunityServiceException{
		Community community = new Community();
		community.setName("Hello!");
		community.setOwner("26-1fd69d42-a0e7-4c2a-8029-14c24fc05dec_VXNlckRTUmVzb3VyY2VzL1VzZXJEU1Jlc291cmNlVHlwZQ==");
		
		communityService.saveCommunity(community);
	}

}
