1
|
package eu.dnetlib.parthenos.catalogue;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import org.apache.commons.io.IOUtils;
|
6
|
import org.apache.commons.lang3.StringUtils;
|
7
|
import org.junit.Test;
|
8
|
import org.springframework.core.io.ClassPathResource;
|
9
|
|
10
|
import static org.junit.Assert.*;
|
11
|
|
12
|
/**
|
13
|
* Created by Alessia Bardi on 15/03/2018.
|
14
|
*
|
15
|
* @author Alessia Bardi
|
16
|
*/
|
17
|
public class CatalogueAPIResponseTest {
|
18
|
|
19
|
private String pathToCreated200 = "eu/dnetlib/parthenos/registry/catalogue/responses/resourceCreatedResponse.json";
|
20
|
private String pathToCreationFailed = "eu/dnetlib/parthenos/registry/catalogue/responses/resourceCreationFailed.json";
|
21
|
|
22
|
@Test
|
23
|
public void testCreated200() throws IOException {
|
24
|
CatalogueAPIResponse res = new CatalogueAPIResponse();
|
25
|
res.setResponseBody(getString(pathToCreated200));
|
26
|
assertTrue(res.isSuccess());
|
27
|
assertTrue(res.hasParthenosRegistryResource());
|
28
|
assertNotNull(res.getParthenosRegistryResource());
|
29
|
assertNotNull(res.getParthenosRegistryResource().getUuid());
|
30
|
assertTrue(StringUtils.isBlank(res.getErrorMessage()));
|
31
|
}
|
32
|
|
33
|
@Test
|
34
|
public void testFailedCreation() throws IOException {
|
35
|
CatalogueAPIResponse res = new CatalogueAPIResponse();
|
36
|
res.setResponseBody(getString(pathToCreationFailed));
|
37
|
assertFalse(res.isSuccess());
|
38
|
assertFalse(res.hasParthenosRegistryResource());
|
39
|
assertNull(res.getParthenosRegistryResource());
|
40
|
assertTrue(StringUtils.isNotBlank(res.getErrorMessage()));
|
41
|
System.out.println(res.getErrorMessage());
|
42
|
}
|
43
|
|
44
|
private String getString(final String classpath) {
|
45
|
try {
|
46
|
final ClassPathResource resource = new ClassPathResource(classpath);
|
47
|
return IOUtils.toString(resource.getInputStream(), "UTF-8");
|
48
|
}catch(IOException e){
|
49
|
return null;
|
50
|
}
|
51
|
}
|
52
|
|
53
|
|
54
|
}
|