Project

General

Profile

« Previous | Next » 

Revision 47422

removed an invalid migration of the apis

View differences:

modules/dnet-openaireplus-workflows/trunk/src/test/java/eu/dnetlib/msro/openaireplus/api/objects/PublicationEntryTest.java
1
package eu.dnetlib.msro.openaireplus.api.objects;
2

  
3
import static org.mockito.Matchers.anyString;
4
import static org.mockito.Mockito.when;
5

  
6
import java.io.InputStreamReader;
7
import java.io.StringReader;
8
import java.util.ArrayList;
9
import java.util.Arrays;
10
import java.util.Properties;
11

  
12
import org.apache.velocity.app.VelocityEngine;
13
import org.dom4j.Document;
14
import org.dom4j.io.OutputFormat;
15
import org.dom4j.io.SAXReader;
16
import org.dom4j.io.XMLWriter;
17
import org.junit.Before;
18
import org.junit.Test;
19
import org.junit.runner.RunWith;
20
import org.mockito.Mock;
21
import org.mockito.invocation.InvocationOnMock;
22
import org.mockito.runners.MockitoJUnitRunner;
23
import org.mockito.stubbing.Answer;
24

  
25
import com.google.gson.Gson;
26

  
27
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
28

  
29
/**
30
 * Created by michele on 14/12/15.
31
 */
32
@RunWith(MockitoJUnitRunner.class)
33
public class PublicationEntryTest {
34

  
35
	private VelocityEngine ve;
36

  
37
	@Mock
38
	private ISLookUpService lookUpService;
39

  
40
	@Before
41
	public void setUp() throws Exception {
42

  
43
		final Properties props = new Properties();
44
		props.setProperty("resource.loader", "class");
45
		props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
46
		props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
47
		ve = new VelocityEngine();
48
		ve.init(props);
49

  
50
		when(lookUpService.quickSearchProfile(anyString())).thenAnswer(new Answer<Object>() {
51

  
52
			@Override
53
			public Object answer(final InvocationOnMock invocation) throws Throwable {
54
				final String query = invocation.getArguments()[0].toString();
55
				if (query.contains("dnet:result_typologies")) {
56
					return Arrays.asList("publication @@@ publication", "dataset @@@ dataset");
57
				} else if (query.contains("dnet:access_modes")) {
58
					return Arrays.asList("OPEN @@@ Open Access");
59
				} else if (query.contains("dnet:publication_resource")) {
60
					return Arrays.asList("0001 @@@ Journal Article");
61
				} else if (query.contains("dnet:pid_types")) {
62
					return Arrays.asList("oai @@@ Open Archive Initiative", "doi @@@ Digital object identifier");
63
				} else if (query.contains("dnet:languages")) {
64
					return Arrays.asList("ita @@@ Italian");
65
				} else if (query.contains("ContextDSResourceType")) {
66
					return Arrays.asList(
67
							"egi::classification::natsc::math::stats @@@ Statistics and Probability",
68
							"egi::classification::natsc::math::pure @@@ Pure Mathematics",
69
							"egi::classification::natsc::math @@@ Mathematics",
70
							"egi::classification::natsc @@@ Natural Sciences",
71
							"egi::classification @@@ EGI classification scheme",
72
							"egi @@@ EGI");
73
				} else {
74
					return new ArrayList<String>();
75
				}
76
			}
77
		});
78

  
79
		when(lookUpService.getResourceProfileByQuery(anyString())).thenAnswer(new Answer<Object>() {
80

  
81
			@Override
82
			public Object answer(final InvocationOnMock invocation) throws Throwable {
83
				return "REPO NAME @@@ repo________";
84
			}
85
		});
86
	}
87

  
88
	@Test
89
	public void testAsIndexRecord() throws Exception {
90
		final PublicationEntry pub = new PublicationEntry();
91
		pub.setOriginalId("ORIG_ID_1234");
92
		pub.setTitle("TEST TITLE <test>");
93
		pub.getAuthors().add("Michele Artini");
94
		pub.getAuthors().add("Claudio Atzori");
95
		pub.getAuthors().add("Alessia Bardi");
96
		pub.setPublisher("Test publisher");
97
		pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
98
		pub.setLanguage("ita");
99
		pub.setLicenseCode("OPEN");
100
		pub.setResourceType("0001");
101
		pub.setUrl("http://test.it/a=1&b=2");
102
		pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
103
		pub.getPids().add(new PidEntry("oai", "oai:1234"));
104
		pub.setCollectedFromId("test________::zenodo");
105
		pub.setHostedById("test________::UNKNOWN");
106
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
107
		pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
108
		pub.getContexts().add("egi::classification::natsc::math::pure");
109
		pub.getContexts().add("egi::classification::natsc::math::stats");
110
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
111

  
112
		final Document doc = (new SAXReader()).read(new StringReader(xml));
113

  
114
		final OutputFormat format = OutputFormat.createPrettyPrint();
115

  
116
		final XMLWriter writer = new XMLWriter(System.out, format);
117

  
118
		writer.write(doc);
119

  
120
		/* writer.close(); */
121

  
122
	}
123

  
124
	@Test
125
	public void testAsIndexRecord_json() throws Exception {
126
		final PublicationEntry pub = (new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record.json")), PublicationEntry.class);
127

  
128
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
129

  
130
		final Document doc = (new SAXReader()).read(new StringReader(xml));
131

  
132
		final OutputFormat format = OutputFormat.createPrettyPrint();
133

  
134
		final XMLWriter writer = new XMLWriter(System.out, format);
135

  
136
		writer.write(doc);
137

  
138
		/* writer.close(); */
139

  
140
	}
141

  
142
	@Test
143
	public void testAsIndexRecord_json_with_greek_chars() throws Exception {
144

  
145
		final PublicationEntry pub =
146
				(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_with_greek_chars.json")), PublicationEntry.class);
147

  
148
		final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
149

  
150
		final Document doc = (new SAXReader()).read(new StringReader(xml));
151

  
152
		final OutputFormat format = OutputFormat.createPrettyPrint();
153

  
154
		final XMLWriter writer = new XMLWriter(System.out, format);
155

  
156
		writer.write(doc);
157

  
158
		/* writer.close(); */
159

  
160
	}
161

  
162
}
modules/dnet-openaireplus-workflows/trunk/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record.json
1
{
2
  "originalId": "ORIG_ID_12345",
3
  "title": "TEST TITLE",
4
  "authors": [
5
	"Michele Artini",
6
	"Claudio Atzori",
7
	"Alessia Bardi"
8
  ],
9
  "publisher": "Test publisher",
10
  "description": "DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION",
11
  "language": "ita",
12
  "pids": [
13
	{
14
	  "type": "doi",
15
	  "value": "10.000/xyz-123"
16
	},
17
	{
18
	  "type": "oai",
19
	  "value": "oai:1234"
20
	}
21
  ],
22
  "licenseCode": "OPEN",
23
  "resourceType": "0001",
24
  "url": "http://test.it/xyz",
25
  "collectedFromId": "opendoar____::2659",
26
  "hostedById": "opendoar____::2367",
27
  "linksToProjects": [
28
	"info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus",
29
	"info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble"
30
  ],
31
  "contexts": [
32
	"egi::classification::natsc::math::pure",
33
	"egi::classification::natsc::math::stats"
34
  ]
35
}
modules/dnet-openaireplus-workflows/trunk/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/submit_test_record.sh
1
#!/bin/bash
2

  
3
curl -H "Content-Type: application/json" --data @test_record.json "http://localhost:8280/app/mvc/api/publications/feedObject"
modules/dnet-openaireplus-workflows/trunk/src/test/resources/eu/dnetlib/msro/openaireplus/api/objects/test_record_with_greek_chars.json
1
{
2
  "originalId": "ORIG_ID_12345",
3
  "title": "TEST TITLE WITH Greek Characters",
4
  "authors": [
5
	"αβγδεζηθικλμ νξοπρσςτυφχψω",
6
	"ΑΒΓΔΕΖΗΘΙΚΛ ΜΝΞΟΠΡΣΤΥΦΧΨΩ"
7
  ],
8
  "publisher": "âââââââ",
9
  "description": "Αν περιμένατε να βρίσκεται εδώ μια σελίδα και δεν υπάρχει, η σελίδα μπορεί να μην εμφανίζεται λόγω καθυστέρησης στην ανανέωση της βάσης δεδομένων, ή μπορεί να έχει διαγραφεί. (Δείτε την γρήγορη διαγραφή σελίδων για πιθανούς λόγους). Μπορείτε να δοκιμάστε την λειτουργία εκκαθάρισης, και να ελέγξετε το αρχείο διαγραφών.",
10
  "language": "ell",
11
  "pids": [
12
	{
13
	  "type": "doi",
14
	  "value": "10.000/xyz-123-gr"
15
	}
16
  ],
17
  "licenseCode": "EMBARGO",
18
  "embargoEndDate": "2018-02-02",
19
  "resourceType": "0001",
20
  "url": "http://test.it/xyz",
21
  "collectedFromId": "opendoar____::2659",
22
  "hostedById": "opendoar____::2367",
23
  "linksToProjects": [
24
	"info:eu-repo/grantAgreement/EC/FP7/123456/EU//Test"
25
  ],
26
  "contexts": [
27
	"egi::classification::natsc::math::stats"
28
  ]
29
}

Also available in: Unified diff