1
|
package eu.dnetlib.parthenos.publisher;
|
2
|
|
3
|
import com.google.common.collect.Lists;
|
4
|
import com.google.common.collect.Maps;
|
5
|
import com.google.gson.Gson;
|
6
|
import com.google.gson.GsonBuilder;
|
7
|
import eu.dnetlib.parthenos.jrr.JRRPublisher;
|
8
|
import eu.dnetlib.parthenos.jrr.JRRPublisherHelper;
|
9
|
import org.apache.http.NameValuePair;
|
10
|
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
11
|
import org.apache.http.client.methods.HttpPost;
|
12
|
import org.apache.http.client.utils.URIBuilder;
|
13
|
import org.apache.http.message.BasicNameValuePair;
|
14
|
import org.junit.Test;
|
15
|
import org.junit.runner.RunWith;
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
17
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
18
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
19
|
import org.springframework.http.HttpEntity;
|
20
|
import org.springframework.http.HttpMethod;
|
21
|
import org.springframework.http.ResponseEntity;
|
22
|
import org.springframework.test.context.junit4.SpringRunner;
|
23
|
import org.springframework.test.web.servlet.MockMvc;
|
24
|
import org.springframework.web.client.RestTemplate;
|
25
|
import org.springframework.web.util.UriComponentsBuilder;
|
26
|
|
27
|
import java.net.URI;
|
28
|
import java.net.URISyntaxException;
|
29
|
import java.util.List;
|
30
|
import java.util.Map;
|
31
|
|
32
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
33
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
34
|
|
35
|
/**
|
36
|
* Created by Alessia Bardi on 29/08/2017.
|
37
|
*
|
38
|
* @author Alessia Bardi
|
39
|
*/
|
40
|
@RunWith(SpringRunner.class)
|
41
|
@WebMvcTest(ParthenosPublisherController.class)
|
42
|
public class ParthenosPublisherControllerTest {
|
43
|
|
44
|
@Autowired
|
45
|
private MockMvc mvc;
|
46
|
|
47
|
@MockBean
|
48
|
private ParthenosPublisherHelper parthenosPublisherHelper;
|
49
|
|
50
|
@MockBean
|
51
|
private JRRPublisherHelper jrrPublisherHelper;
|
52
|
|
53
|
@Test
|
54
|
public void publishOK() throws Exception {
|
55
|
mvc.perform(post("/publish").param("record", "<aTestRecord>value</aTestRecord>").param("parthenosTarget", "VIRTUOSO"))
|
56
|
.andExpect(status().isOk());
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void testEx() throws Exception {
|
61
|
mvc.perform(post("/publish")).andExpect(status().is4xxClientError());
|
62
|
}
|
63
|
|
64
|
@Test
|
65
|
public void testJRREx() throws Exception {
|
66
|
mvc.perform(post("/publishJRR")).andExpect(status().is4xxClientError());
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testJRROk() throws Exception {
|
71
|
//{"typeNamespace":"http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/","datasourceApi":"api_________::parthenos___::parthenos::topLevel","typeName":"D14_Software","datasourceName":"PARTHENOS"}
|
72
|
(mvc.perform(post("/publishJRR")
|
73
|
.param("typeNamespace", "http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/" )
|
74
|
.param("datasourceApi", "api_________::parthenos___::parthenos::topLevel")
|
75
|
.param("typeName", "D14_Software")
|
76
|
.param("datasourceName", "PARTHENOS"))).andExpect(status().isOk());
|
77
|
}
|
78
|
|
79
|
@Test
|
80
|
public void test() {
|
81
|
|
82
|
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://beta-parthenos.d4science.org:8080/parthenos/publishJRR")
|
83
|
.queryParam("typeNamespace", "http://www.ics.forth.gr/isl/CRMext/CRMdig.rdfs/")
|
84
|
.queryParam("typeName", "X_Type")
|
85
|
.queryParam("datasourceApi", "api_________::parthenos___::parthenos::test")
|
86
|
.queryParam("datasourceName", "X");
|
87
|
URI uri = builder.build().toUri();
|
88
|
System.out.println("Request goes to " + uri.toString());
|
89
|
RestTemplate restTemplate = new RestTemplate();
|
90
|
ResponseEntity<Integer> res = restTemplate.exchange(uri, HttpMethod.POST, null, Integer.class);
|
91
|
if (res.getStatusCode().is2xxSuccessful()) {
|
92
|
System.out.println("ok");
|
93
|
|
94
|
} else {
|
95
|
System.out.println("not ok: "+res.getStatusCodeValue());
|
96
|
}
|
97
|
|
98
|
}
|
99
|
|
100
|
|
101
|
}
|