package org.arachb.owlbuilder.lib;

import static org.junit.Assert.assertNotNull;

import java.util.HashSet;
import java.util.Set;

import org.apache.log4j.Logger;
import org.arachb.arachadmin.AbstractConnection;
import org.arachb.arachadmin.ClaimBean;
import org.arachb.arachadmin.DBConnection;
import org.arachb.arachadmin.ParticipantBean;
import org.arachb.owlbuilder.Owlbuilder;
import org.junit.Before;
import org.junit.Test;
import org.semanticweb.owlapi.model.OWLObject;

public class TestParticipant {

    private static Logger log = Logger.getLogger(TestParticipant.class);

    private AbstractConnection testConnection;

    private final int TESTCLAIMID1 = 1;
    private final int TESTCLAIMID26 = 26;
    private ClaimBean testClaim1;
    private ClaimBean testClaim26;
    private Set<ParticipantBean> beanSet1;
    private Set<ParticipantBean> beanSet26;
    private final Set<ParticipantBean> allParticipants = new HashSet<ParticipantBean>();
	private Owlbuilder builder;
	
	@Before
	public void setUp() throws Exception {
		if (DBConnection.testConnection()){
			log.info("Testing with live connection");
			testConnection = DBConnection.getTestConnection();
		}
		else{
			log.info("Testing with mock connection");
			testConnection = DBConnection.getMockConnection();
		}
    	builder = new Owlbuilder();
    	builder.setUpForTesting();
    	testClaim1 = testConnection.getClaim(TESTCLAIMID1);
    	testClaim26 = testConnection.getClaim(TESTCLAIMID26);
		beanSet1 = testConnection.getParticipantTable(TESTCLAIMID1);
		beanSet26 = testConnection.getParticipantTable(TESTCLAIMID26);
		allParticipants.clear();
		allParticipants.addAll(beanSet1);
		allParticipants.addAll(beanSet26);
    	
	}

	@Test
	public void testParticipant() throws Exception{
		for (ParticipantBean pb : allParticipants){
			Participant p = new Participant(pb);
			assertNotNull(p);
		}
	}

//	@Test
//	public void testGenerateElementOWL() throws Exception{
//		for (ParticipantBean pb : beanSet1){
//			OWLObject o = setUpGenerateElement(pb);
//			assertNotNull(o);
//			assertTrue(o instanceof OWLClassExpression);
//		}
//			//TODO add tests for individuals and 'bad child' beans
//		for (ParticipantBean pb : beanSet26){
//			OWLObject o = setUpGenerateElement(pb);
//			assertNotNull(o);
//			assertTrue(o instanceof OWLIndividual);			
//		}
//	}
	
	
//	private OWLObject setUpGenerateElement(ParticipantBean pb) throws Exception{
//		Participant p = new Participant(pb);
//		PElementBean headBean = pb.getElementBean(pb.getHeadElement());
//		Map<String, OWLObject> elements = new HashMap<String, OWLObject>(); 
//		return p.generateElementOWL(headBean, builder, elements);		
//	}
	
	

//	@Test
//	public void testGenerateTermOWL(){
//		fail("Not implemented");
//	}
//	
//
//	@Test
//	public void testGenerateIndividualOWL(){
//		fail("Not implemented");
//	}

	
	
	@Test
	public void testGenerateOWL() throws Exception {
		for (ParticipantBean pb : allParticipants){
			Participant p = new Participant(pb);
			OWLObject o = p.generateOWL(builder);
			assertNotNull(o);
			log.info("OWL result is: " + o);
		}
	}

}

@@ -74,16 +74,59 @@
 NotNull;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Aimport
@@ -1637,16 +1637,281 @@
 MID26);%0A
+%09%09for (ParticipantBean pb : beanSet1)%7B%0A%09%09%09testConnection.getPElementTable(pb);%0A%09%09%09testConnection.getProperty(pb.getProperty());%0A%09%09%7D%0A%09%09for (ParticipantBean pb : beanSet26)%7B%0A%09%09%09testConnection.getPElementTable(pb);%0A%09%09%09testConnection.getProperty(pb.getProperty());%0A%09%09%7D%0A
 %09%09allPar
@@ -2002,16 +2002,56 @@
 Set26);%0A
+%09%09testConnection.getPublicationTable();%0A
     %09%0A%09%7D
@@ -3261,16 +3261,16 @@
 ption %7B%0A
-
 %09%09for (P
@@ -3299,32 +3299,67 @@
 lParticipants)%7B%0A
+%09%09%09assertTrue(pb.getProperty()%3E0);%0A
 %09%09%09Participant p

add some initialization and a valid property precheck in the generateOWL test