package org.arachb.owlbuilder.lib;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.arachb.arachadmin.AbstractConnection;
import org.arachb.arachadmin.DBConnection;
import org.arachb.arachadmin.PropertyBean;
import org.arachb.owlbuilder.Owlbuilder;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.semanticweb.owlapi.model.OWLObject;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;

public class TestPropertyTerm {

	private Owlbuilder builder;
	private static Logger log = Logger.getLogger(TestPropertyTerm.class);
	private static AbstractConnection testConnection;

	private static String hasPartIRI = Vocabulary.hasPartProperty.toString();
	private static PropertyBean hasPartBean;
	private static PropertyTerm hasPartPropertyTerm;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception{
		if (DBConnection.probeTestConnection()){
			log.info("Testing with live connection");
			testConnection = DBConnection.getTestConnection();
		}
		else{
			log.info("Testing with mock connection");
			testConnection = DBConnection.getMockConnection();
		}
		hasPartBean = testConnection.getPropertyFromSourceId(hasPartIRI);
		hasPartPropertyTerm = new PropertyTerm(hasPartBean);
	}

	@Before
	public void setUp() throws Exception {
		builder = new Owlbuilder(testConnection);
		builder.setUpForTesting();
	}


	@Test
	public void testGenerateOwl1arg() throws Exception {
		OWLObject owlObj = hasPartPropertyTerm.generateOWL(builder);
		assertNotNull(owlObj);
		assert(owlObj instanceof OWLObjectPropertyExpression);
	}


	@Test
	public void testGenerateOwl2arg() throws Exception{
		Map<String,OWLObject> elements = new HashMap<>();
		OWLObject owlObj = hasPartPropertyTerm.generateOWL(builder, elements);
		assertEquals(1,elements.size());
		assertNotNull(elements.get(hasPartIRI));
		assertEquals(owlObj,elements.get(hasPartIRI));
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception{
		testConnection.close();
	}

}

@@ -749,23 +749,22 @@
  String 
-hasP
+p
 art
+Of
 IRI = Vo
@@ -772,23 +772,22 @@
 abulary.
-hasP
+p
 art
+Of
 Property
@@ -828,23 +828,22 @@
 rtyBean 
-hasP
+p
 art
+Of
 Bean;%0A%09p
@@ -869,23 +869,22 @@
 rtyTerm 
-hasP
+p
 art
+Of
 Property
@@ -1220,23 +1220,22 @@
 ;%0A%09%09%7D%0A%09%09
-hasP
+p
 art
+Of
 Bean = t
@@ -1276,23 +1276,22 @@
 eId(
-hasP
+p
 art
+Of
 IRI);%0A%09%09
 hasP
@@ -1286,23 +1286,22 @@
 IRI);%0A%09%09
-hasP
+p
 art
+Of
 Property
@@ -1324,23 +1324,22 @@
 rtyTerm(
-hasP
+p
 art
+Of
 Bean);%0A%09
@@ -1542,39 +1542,38 @@
 Object owlObj = 
-hasP
+p
 art
+Of
 PropertyTerm.gen
@@ -1811,23 +1811,22 @@
 wlObj = 
-hasP
+p
 art
+Of
 Property
@@ -1918,39 +1918,38 @@
 ll(elements.get(
-hasP
+p
 art
+Of
 IRI));%0A%09%09assertE
@@ -1978,15 +1978,14 @@
 get(
-hasP
+p
 art
+Of
 IRI)

change tests that use hasPart to use partOf since former is currently suppressed