Revision 57900
Added by Alessia Bardi over 4 years ago
modules/dnet-parthenos-publisher/trunk/test/main/java/eu/dnetlib/parthenos/publisher/ParthenosPublisherControllerTest.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.parthenos.publisher; |
2 | 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; |
|
3 | 7 |
import eu.dnetlib.parthenos.jrr.JRRPublisher; |
4 | 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; |
|
5 | 14 |
import org.junit.Test; |
6 | 15 |
import org.junit.runner.RunWith; |
7 | 16 |
import org.springframework.beans.factory.annotation.Autowired; |
8 | 17 |
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
9 | 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; |
|
10 | 22 |
import org.springframework.test.context.junit4.SpringRunner; |
11 | 23 |
import org.springframework.test.web.servlet.MockMvc; |
24 |
import org.springframework.web.client.RestTemplate; |
|
25 |
import org.springframework.web.util.UriComponentsBuilder; |
|
12 | 26 |
|
27 |
import java.net.URI; |
|
28 |
import java.net.URISyntaxException; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
|
|
13 | 32 |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; |
14 | 33 |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
15 | 34 |
|
... | ... | |
21 | 40 |
@RunWith(SpringRunner.class) |
22 | 41 |
@WebMvcTest(ParthenosPublisherController.class) |
23 | 42 |
public class ParthenosPublisherControllerTest { |
43 |
|
|
24 | 44 |
@Autowired |
25 | 45 |
private MockMvc mvc; |
26 | 46 |
|
... | ... | |
48 | 68 |
|
49 | 69 |
@Test |
50 | 70 |
public void testJRROk() throws Exception { |
51 |
mvc.perform(post("/publishJRR")).andExpect(status().is4xxClientError()); |
|
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()); |
|
52 | 77 |
} |
53 | 78 |
|
79 |
@Test |
|
80 |
public void test() { |
|
54 | 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"); |
|
55 | 93 |
|
94 |
} else { |
|
95 |
System.out.println("not ok: "+res.getStatusCodeValue()); |
|
96 |
} |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
|
|
56 | 101 |
} |
Also available in: Unified diff
Testing latest method for publishing on JRR