001package org.kuali.ole.web;
002
003import org.apache.commons.io.FileUtils;
004import org.junit.After;
005import org.junit.Before;
006import org.junit.Ignore;
007import org.junit.Test;
008import org.kuali.ole.RepositoryBrowser;
009import org.kuali.ole.base.BaseTestCase;
010import org.kuali.ole.docstore.indexer.solr.IndexerService;
011import org.kuali.ole.docstore.model.enums.DocCategory;
012import org.kuali.ole.docstore.model.enums.DocFormat;
013import org.kuali.ole.docstore.model.enums.DocType;
014import org.mockito.Mock;
015import org.springframework.mock.web.MockHttpServletRequest;
016import org.springframework.mock.web.MockHttpServletResponse;
017import org.springframework.mock.web.MockServletContext;
018
019import java.util.ArrayList;
020import java.util.List;
021
022/**
023 * Created with IntelliJ IDEA.
024 * User: ?
025 * Date: 12/17/12
026 * Time: 12:03 AM
027 * To change this template use File | Settings | File Templates.
028 */
029@Ignore
030@Deprecated
031public class GetUUIDServlet_UT
032        extends BaseTestCase {
033
034    private RepositoryBrowser repositoryBrowser;
035    private MockHttpServletRequest  mockRequest  = new MockHttpServletRequest();
036    private MockHttpServletResponse mockResponse = new MockHttpServletResponse();
037    private MockServletContext mockServletContext = new MockServletContext();
038    GetUUIDServlet getUUIDServlet = new GetUUIDServlet();
039    private static final String RESULTS_JSP =
040               "/getUUIDResults.jsp";
041    @Mock
042    private IndexerService mockIndexerService;
043
044    @Override
045    @Before
046    public void setUp() throws Exception {
047        super.setUp();    //To change body of overridden methods use File | Settings | File Templates.
048    }
049
050    @After
051    public void tearDown() throws Exception {
052    }
053
054    @Test
055    public void testGetUUIDs() throws Exception {
056        List<String> uuidsList = new ArrayList<String>();
057        String category = DocCategory.WORK.getDescription();
058        String type = DocType.BIB.getDescription();
059        String format = DocFormat.MARC.getDescription();
060        String numUUIDs = "4";
061
062//        //Servlet code : Having problem with servlet context
063//        mockRequest.setParameter("category", category );
064//        mockRequest.setParameter("type", type );
065//        mockRequest.setParameter("format", format );
066//        mockRequest.setParameter("numUUIDs", numUUIDs );
067//        getUUIDServlet.service(mockRequest, mockResponse);
068//        getUUIDServlet.doPost(mockRequest, mockResponse);
069//        System.out.println(mockRequest.getAttribute("result"));
070//
071
072
073       try {
074            if (null != category && null != format && null != numUUIDs) {
075                uuidsList = getRepositoryBrowser()
076                        .getUUIDs(category.toLowerCase(), type.toLowerCase(), format.toLowerCase(),
077                                  new Integer(numUUIDs));
078            }
079        }
080        catch (Exception e) {
081            uuidsList.add(e.getMessage());
082        }
083
084        if(uuidsList.size() > 0 ){
085            System.out.println("UUIDs");
086            for(String uuid : uuidsList){
087            System.out.println(uuid);
088        }
089        }
090
091    }
092
093    public RepositoryBrowser getRepositoryBrowser() {
094        if (null == repositoryBrowser) {
095            repositoryBrowser = new RepositoryBrowser();
096        }
097        return repositoryBrowser;
098    }
099}