1 package org.kuali.ole.web;
2
3 import org.apache.commons.io.FileUtils;
4 import org.junit.After;
5 import org.junit.Before;
6 import org.junit.Ignore;
7 import org.junit.Test;
8 import org.kuali.ole.base.BaseTestCase;
9 import org.kuali.ole.docstore.model.enums.DocFormat;
10 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
11 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
12 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
13 import org.kuali.ole.docstore.service.BeanLocator;
14 import org.kuali.ole.docstore.service.DocumentServiceImpl;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.mock.web.MockHttpServletRequest;
18 import org.springframework.mock.web.MockHttpServletResponse;
19 import org.springframework.util.FileCopyUtils;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.net.URISyntaxException;
24 import java.net.URL;
25
26
27
28
29
30
31
32
33 @Ignore
34 public class DocumentServlet_UT
35 extends BaseTestCase {
36 private Response response = null;
37 private Logger logger = LoggerFactory.getLogger(DocumentServlet_UT.class);
38 DocumentServlet documentServlet = new DocumentServlet();
39 private MockHttpServletRequest mockRequest = new MockHttpServletRequest();
40 private MockHttpServletResponse mockResponse = new MockHttpServletResponse();
41
42
43 @Override
44 @Before
45 public void setUp() throws Exception {
46 super.setUp();
47 }
48
49 @After
50 public void tearDown() throws Exception {
51 }
52 @Ignore
53 @Test
54 public void testProcessForIngest() throws Exception {
55 byte[] fileContent = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("repository/request.xml"));
56 mockRequest.setParameter("docAction", "ingestContent");
57 mockRequest.setParameter("stringContent", new String(fileContent));
58 documentServlet.doGet(mockRequest, mockResponse);
59 }
60
61 @Ignore
62 @Test
63 public void testProcessForCheckin() throws Exception {
64 String existingUUIDToCheckIn = null;
65 Request requestObjectIngest = getRequestObjectIngest();
66 DocumentServiceImpl d = BeanLocator.getDocumentServiceImpl();
67 Response response1 = d.process(requestObjectIngest);
68 existingUUIDToCheckIn = response1.getDocuments().get(0).getUuid();
69 URL resource = getClass().getResource("repository/checkInRequest.xml");
70 File file = new File(resource.toURI());
71 RequestHandler requestHandler = new RequestHandler();
72 Request request = requestHandler.toObject(readFile(file));
73 request.getRequestDocuments().get(0).setId(existingUUIDToCheckIn);
74 System.out.println("req content for checkIn-->" + new RequestHandler().toXML(request));
75 mockRequest.setParameter("docAction", "checkIn");
76 mockRequest.setParameter("stringContent", new RequestHandler().toXML(request));
77 documentServlet.doGet(mockRequest, mockResponse);
78 }
79 @Ignore
80 @Test
81 public void testProcessForCheckOut() throws Exception {
82 DocumentServiceImpl d = BeanLocator.getDocumentServiceImpl();
83 Request request = getRequestObjectIngest();
84 Response responseIngest = d.process(request);
85 String responseString = new org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler().toXML(responseIngest);
86 System.out.println("responseString Ingest " + responseString);
87 String marcUUID = responseIngest.getDocuments().get(0).getUuid();
88 String instanceUUID = responseIngest.getDocuments().get(1).getUuid();
89 String dublinUUID = responseIngest.getDocuments().get(2).getUuid();
90 String dublinUnqUUID = responseIngest.getDocuments().get(3).getUuid();
91
92
93 mockRequest.setParameter("docAction", "checkOut");
94 mockRequest.setParameter("uuid", marcUUID);
95 mockRequest.setParameter("docFormat", DocFormat.MARC.getDescription());
96 documentServlet.doGet(mockRequest, mockResponse);
97
98
99 mockRequest.setParameter("docAction", "checkOut");
100 mockRequest.setParameter("uuid", instanceUUID);
101 mockRequest.setParameter("docFormat", DocFormat.OLEML.getDescription());
102 documentServlet.doGet(mockRequest, mockResponse);
103
104
105 mockRequest.setParameter("docAction", "checkOut");
106 mockRequest.setParameter("uuid", dublinUUID);
107 mockRequest.setParameter("docFormat", DocFormat.DUBLIN_CORE.getDescription());
108 documentServlet.doGet(mockRequest, mockResponse);
109
110
111 mockRequest.setParameter("docAction", "checkOut");
112 mockRequest.setParameter("uuid", dublinUnqUUID);
113 mockRequest.setParameter("docFormat", DocFormat.DUBLIN_UNQUALIFIED.getDescription());
114 documentServlet.doGet(mockRequest, mockResponse);
115
116
117 mockRequest.setParameter("docAction", "checkOut");
118 mockRequest.setParameter("uuid", "111");
119 mockRequest.setParameter("docFormat", DocFormat.MARC.getDescription());
120 try {
121 documentServlet.doGet(mockRequest, mockResponse);
122 }
123 catch (Exception e) {
124 System.out.println("Invalid UUID checkout");
125 }
126 }
127
128 @Ignore
129 @Test
130 public void testProcessForDelete() throws Exception {
131 DocumentServiceImpl d = BeanLocator.getDocumentServiceImpl();
132 Request request = getRequestObjectIngest();
133 Response responseIngest = d.process(request);
134 String responseString = new org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler().toXML(responseIngest);
135 System.out.println("Ingest Response" + responseString);
136 String marcUUID = responseIngest.getDocuments().get(0).getUuid();
137 String instanceUUID = responseIngest.getDocuments().get(1).getUuid();
138 String dublinUUID = responseIngest.getDocuments().get(2).getUuid();
139 String dublinUnqUUID = responseIngest.getDocuments().get(3).getUuid();
140
141 String UUIDsToDelete = marcUUID + "," + instanceUUID + "," + dublinUUID + "," + dublinUnqUUID;
142
143 mockRequest.setParameter("identifierType", "UUID");
144 mockRequest.setParameter("docAction", "delete");
145 mockRequest.setParameter("requestContent", UUIDsToDelete);
146 documentServlet.doGet(mockRequest, mockResponse);
147
148 }
149
150 private Request getRequestObjectIngest() throws URISyntaxException, IOException {
151 File inputDir = new File(this.getClass().getResource("repository/request.xml").toURI());
152 String fileContent = FileUtils.readFileToString(inputDir);
153 RequestHandler rh = new RequestHandler();
154 Request request = rh.toObject(fileContent);
155 return request;
156 }
157 }