package reciter.junit.testcases;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import reciter.erroranalysis.ReCiterConfigProperty;
import reciter.model.article.ReCiterArticle;
import xmlparser.pubmed.PubmedXmlFetcher;
import xmlparser.pubmed.model.PubmedArticle;
import xmlparser.scopus.ScopusXmlFetcher;
import xmlparser.scopus.model.ScopusArticle;
import xmlparser.translator.ArticleTranslator;
import database.dao.GoldStandardPmidsDao;
import database.dao.impl.GoldStandardPmidsDaoImpl;

public class RcgoldstandardJunitTest {
	static String cwid = "aad2004";
	ReCiterConfigProperty reCiterConfigProperty;
	String lastName;
	String middleName;
	String firstName;
	String affiliation;
	String firstInitial;
	String authorKeywords;
	String coAuthors;
	String department;
	PubmedXmlFetcher pubmedXmlFetcher;
	List<PubmedArticle> pubmedArticleList;
	List<ReCiterArticle> reCiterArticleList;
	List<String> gspPmidList;

	@Before
	public void setUp() throws Exception {
		String path = (new File("").getAbsolutePath()) + File.separator
				+ ReCiterConfigProperty.getDefaultLocation();
		ReCiterConfigProperty reCiterConfigProperty = new ReCiterConfigProperty();
		try {
			reCiterConfigProperty.loadProperty(path + cwid + "/" + cwid
					+ ".properties");
		} catch (Exception e) {
			e.printStackTrace();
		}
		lastName = reCiterConfigProperty.getLastName();
		middleName = reCiterConfigProperty.getMiddleName();
		firstName = reCiterConfigProperty.getFirstName();
		affiliation = reCiterConfigProperty.getAuthorAffiliation();
		firstInitial = firstName.substring(0, 1);
		cwid = reCiterConfigProperty.getCwid();
		authorKeywords = reCiterConfigProperty.getAuthorKeywords();
		coAuthors = reCiterConfigProperty.getCoAuthors();
		department = reCiterConfigProperty.getAuthorDepartment();
		pubmedXmlFetcher = new PubmedXmlFetcher();
		pubmedArticleList = pubmedXmlFetcher.getPubmedArticle(lastName,
				firstInitial, middleName, cwid);
		ScopusXmlFetcher scopusXmlFetcher = new ScopusXmlFetcher();
		reCiterArticleList = new ArrayList<ReCiterArticle>();

		GoldStandardPmidsDao gspDao = new GoldStandardPmidsDaoImpl();
		gspPmidList = gspDao.getPmidsByCwid(cwid);

		for (PubmedArticle pubmedArticle : pubmedArticleList) {
			String pmid = pubmedArticle.getMedlineCitation().getPmid()
					.getPmidString();
			if (gspPmidList.contains(pmid))
				gspPmidList.remove(pmid);
			ScopusArticle scopusArticle = scopusXmlFetcher.getScopusXml(cwid,
					pmid);
			reCiterArticleList.add(ArticleTranslator.translate(pubmedArticle,
					scopusArticle));
		}
	}

	@Test
	public void test() {
		int size = gspPmidList.size();
		assertTrue(size > 1);

	}
}

@@ -198,24 +198,133 @@
 unit.Test;%0D%0A
+import org.slf4j.Logger;%0D%0Aimport org.slf4j.LoggerFactory;%0D%0A%0D%0Aimport reciter.algorithm.cluster.ReCiterExample;
 %0D%0Aimport rec
@@ -775,16 +775,112 @@
 Test %7B%0D%0A
+%09private final static Logger slf4jLogger = LoggerFactory%0D%0A%09%09%09.getLogger(ReCiterExample.class);%0D%0A
 %09static 
@@ -896,17 +896,17 @@
 id = %22aa
-d
+s
 2004%22;%0D%0A
@@ -2313,16 +2313,20 @@
 cwid);%0D%0A
+%09%09%0D%0A
 %09%09Scopus
@@ -2433,24 +2433,100 @@
 rticle%3E();%0D%0A
+%09%09slf4jLogger.info(%22pubmedArticleList Size  = %22 + pubmedArticleList.size());
 %0D%0A%09%09GoldStan
@@ -2626,16 +2626,86 @@
 cwid);%0D%0A
+%09%09%0D%0A%09%09slf4jLogger.info(%22gspPmidList size    = %22 + gspPmidList.size());
 %0D%0A%09%09for 
@@ -2851,10 +2851,13 @@
 %0A%09%09%09
-if
+while
  (gs
@@ -3172,27 +3172,373 @@
 %0D%0A%09%09
-assertTrue(size %3E 1
+if(gspPmidList.size()%3E0)%7B%0D%0A%09%09%09StringBuilder sb = new StringBuilder();%0D%0A%09%09%09for(String pmid: gspPmidList)%7B%0D%0A%09%09%09%09sb.append(pmid).append(%22 %22);%0D%0A%09%09%09%7D%0D%0A%09%09%09slf4jLogger.info(%22Test case is failed , the following PMIDs are not added into cluster one %5B%22+sb.toString().trim()+%22%5D%22 );%0D%0A%09%09%7D%0D%0A%09%09slf4jLogger.info(%22Test Passed%22);%0D%0A%09%09slf4jLogger.info(%22gspPmidList size  =     %22 + size
 );%0D%0A

test case updated for Issue Number # 22