Revision 40086
Added by Argiro Kokogiannaki over 8 years ago
TestClass.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
|
7 | 7 |
|
8 |
import eu.dnetlib.data.claimsDemo.eu.dnetlib.data.claims.migration.Claim; |
|
9 |
import eu.dnetlib.data.claimsDemo.eu.dnetlib.data.claims.migration.Result; |
|
8 | 10 |
import org.apache.log4j.BasicConfigurator; |
9 | 11 |
import org.apache.log4j.Logger; |
10 | 12 |
import org.junit.Before; |
... | ... | |
13 | 15 |
import org.springframework.beans.factory.annotation.Autowired; |
14 | 16 |
import org.springframework.test.context.ContextConfiguration; |
15 | 17 |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
18 |
import org.xml.sax.SAXException; |
|
16 | 19 |
|
20 |
import javax.xml.parsers.ParserConfigurationException; |
|
21 |
import javax.xml.xpath.*; |
|
22 |
import java.io.IOException; |
|
23 |
import java.sql.ResultSet; |
|
24 |
|
|
17 | 25 |
import static junit.framework.Assert.assertNotNull; |
18 | 26 |
|
19 | 27 |
/** |
... | ... | |
24 | 32 |
|
25 | 33 |
public class TestClass { |
26 | 34 |
private Logger log = Logger.getLogger(this.getClass()); |
35 |
private ClaimOperations claimOperations= new ClaimOperations(); |
|
27 | 36 |
|
28 | 37 |
@Autowired |
29 | 38 |
private SqlDAO sqlDAO; |
... | ... | |
50 | 59 |
@Test |
51 | 60 |
public void executePreparedQuery() throws Exception { |
52 | 61 |
|
53 |
log.info(sqlDAO.executePreparedQuery("Select * from test limit 1"));
|
|
62 |
log.info(sqlDAO.executePreparedQuery("Select * from claims limit 1"));
|
|
54 | 63 |
|
55 | 64 |
|
56 | 65 |
} |
57 | 66 |
|
67 |
@Test |
|
68 |
public void getFirstClaim() throws Exception { |
|
69 |
//id : 169149 type : rels2actions reltype : resultResult_datasetpublication_isRelatedTo |
|
70 |
// id : 169480 type : rels2actions reltype : resultProject |
|
71 |
// id : 169503 type : rels2actions reltype : resultResult_publicationdataset_isRelatedTo |
|
72 |
ResultSet rs=sqlDAO.executePreparedQuery("Select * from claims limit 15"); |
|
73 |
//ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectClaimById("169480")); |
|
74 |
while(rs.next()){ |
|
75 |
String claimType=rs.getString("type"); |
|
76 |
String xml=rs.getString("xml"); |
|
77 |
if(claimType!=null && claimType.equals("rels2actions")){ |
|
78 |
log.info("*Relation *"); |
|
79 |
log.info(claimOperations.getRelationClaim(rs).toString()); |
|
80 |
}else{ |
|
81 |
if(xml!=null && xml.contains("<oaf:concept")){ |
|
82 |
log.info("* Context *"); |
|
83 |
log.info(claimOperations.getConceptDMFClaim(rs).toString()); |
|
84 |
}else{ |
|
85 |
log.info("* DMF *"); |
|
86 |
log.info(claimOperations.getDMFClaim(rs).toString()); |
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
@Test |
|
92 |
public void getRelationClaims() throws Exception { |
|
93 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectRelationClaims(1)); |
|
94 |
while(rs.next()){ |
|
95 |
Claim claim = claimOperations.getRelationClaim(rs); |
|
96 |
log.info(claim.toString()); |
|
97 |
} |
|
98 |
} |
|
99 |
@Test |
|
100 |
public void getDMFClaims() throws Exception { |
|
101 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectDMFClaims(1)); |
|
102 |
while(rs.next()){ |
|
103 |
Result r=claimOperations.getDMFClaim(rs); |
|
104 |
log.info(r.toString()); |
|
105 |
} |
|
106 |
} |
|
107 |
@Test |
|
108 |
public void getConceptDMFClaims() throws Exception { |
|
109 |
ResultSet rs=sqlDAO.executePreparedQuery(sqlDAO.getQueryGenerator().selectConceptDMFClaims(1)); |
|
110 |
while(rs.next()){ |
|
111 |
log.info(rs.getString("xml")); |
|
112 |
Claim claim=claimOperations.getConceptDMFClaim(rs); |
|
113 |
log.info(claim.toString()); |
|
114 |
} |
|
115 |
} |
|
58 | 116 |
|
117 |
@Test |
|
118 |
public void testHttpRequest() throws Exception { |
|
119 |
SearchUtils searchUtils= new SearchUtils(); |
|
120 |
log.info(searchUtils.getResult("doajarticles::eb8a123eb82b25013b0001d0e2d1842b")); |
|
121 |
} |
|
122 |
|
|
123 |
@Test |
|
124 |
public void testXpath() throws ParserConfigurationException, IOException, SAXException, XPathExpressionException { |
|
125 |
|
|
126 |
SearchUtils searchUtils= new SearchUtils(); |
|
127 |
log.info(searchUtils.getResultSearchUrl("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85")); |
|
128 |
ParsingClaimUtils parsingClaimUtils= new ParsingClaimUtils(searchUtils.getProjectSearchUrl("dedup_wf_001::88a1eedd1ffce63dccf51d8ce2053c85"),true); |
|
129 |
log.info("***bestlicense:"+parsingClaimUtils.getValueFromXMLAtrribute("bestlicense")); |
|
130 |
log.info("***embargoendyear:"+parsingClaimUtils.getValueFromXMLAtrribute("embargoendyear")); |
|
131 |
log.info("***embargoendyear:"+parsingClaimUtils.getValueFromXMLAtrribute("embargoendyear")); |
|
132 |
log.info("***Title:"+parsingClaimUtils.getValueFromXMLAtrribute("title")); |
|
133 |
log.info("***resulttypename:"+parsingClaimUtils.getValueFromXMLAtrribute("resulttypename")); |
|
134 |
|
|
135 |
} |
|
136 |
|
|
137 |
@Test |
|
138 |
public void testParsingDMF() throws IOException, SAXException, ParserConfigurationException { |
|
139 |
Result r=ParsingClaimUtils.getResultFromDMF("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
|
140 |
"<record xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:prov=\"http://www.openarchives.org/OAI/2.0/provenance\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:dr=\"http://www.driver-repository.eu/namespace/dr\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\">\n" + |
|
141 |
" <header xmlns=\"http://namespace.openaire.eu/\">\n" + |
|
142 |
" <dri:objIdentifier>crossref____::47593e13b24bcdd0f3d5573499f1d3a9</dri:objIdentifier>\n" + |
|
143 |
" <dri:recordIdentifier>10.1088/0004-637X/761/1/34</dri:recordIdentifier>\n" + |
|
144 |
" <dri:dateOfCollection></dri:dateOfCollection>\n" + |
|
145 |
" <dri:mdFormat></dri:mdFormat>\n" + |
|
146 |
" <dri:mdFormatInterpretation></dri:mdFormatInterpretation>\n" + |
|
147 |
" <dri:repositoryId></dri:repositoryId>\n" + |
|
148 |
" <dr:objectIdentifier></dr:objectIdentifier>\n" + |
|
149 |
" <dr:dateOfCollection>2014-10-10T14:59:49+00:00</dr:dateOfCollection>\n" + |
|
150 |
" <oaf:datasourceprefix>crossref____</oaf:datasourceprefix>\n" + |
|
151 |
" </header>\n" + |
|
152 |
" <metadata xmlns=\"http://namespace.openaire.eu/\">\n" + |
|
153 |
" <dc:dateAccepted>2012-01-01T00:00:00Z</dc:dateAccepted>\n" + |
|
154 |
" <dc:identifier>http://stacks.iop.org/0004-637X/761/i=1/a=34?key=crossref.d14dae8ac205453af63561a69c108e13</dc:identifier>\n" + |
|
155 |
" <dc:title>A THREE-DIMENSIONAL VIEW OF THE REMNANT OF NOVA PERSEI 1901 (GK Per)</dc:title>\n" + |
|
156 |
" <oaf:collectedDatasourceid>openaire____::crossref</oaf:collectedDatasourceid>\n" + |
|
157 |
" <oaf:accessrights></oaf:accessrights>\n" + |
|
158 |
" <oaf:hostedBy name=\"Unknown Repository\" id=\"openaire____::1256f046-bf1f-4afc-8b47-d0b147148b18\"/>\n" + |
|
159 |
" <oaf:collectedFrom name=\"Crossref\" id=\"openaire____::crossref\" />\n" + |
|
160 |
"\n" + |
|
161 |
" <dc:creator>Liimets, T.</dc:creator>\n" + |
|
162 |
" <dc:creator>Corradi, R. L. M.</dc:creator>\n" + |
|
163 |
" <dc:creator>Santander-García, M.</dc:creator>\n" + |
|
164 |
" <dc:creator>Villaver, E.</dc:creator>\n" + |
|
165 |
" <dc:creator>Rodríguez-Gil, P.</dc:creator>\n" + |
|
166 |
" <dc:creator>Verro, K.</dc:creator>\n" + |
|
167 |
" <dc:creator>Kolka, I.</dc:creator>\n" + |
|
168 |
"\n" + |
|
169 |
" <dc:identifier identifierType=\"doi\">10.1088/0004-637X/761/1/34</dc:identifier>\n" + |
|
170 |
" <dr:CobjIdentifier>10.1088/0004-637X/761/1/34</dr:CobjIdentifier>\n" + |
|
171 |
" </metadata>\n" + |
|
172 |
"</record>"); |
|
173 |
log.info(r.toString()); |
|
174 |
|
|
175 |
} |
|
59 | 176 |
} |
Also available in: Unified diff