View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.repository;
17  
18  import org.junit.Before;
19  import org.junit.Test;
20  import org.kuali.ole.BaseTestCase;
21  import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
22  import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
23  import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
24  import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
25  import org.kuali.ole.docstore.service.BeanLocator;
26  import org.kuali.ole.docstore.service.IngestNIndexHandlerService;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  
30  import java.io.File;
31  import java.net.URL;
32  import java.util.Iterator;
33  import java.util.List;
34  
35  import static junit.framework.Assert.assertNotNull;
36  
37  /**
38   * Created by IntelliJ IDEA.
39   * User: pvsubrah
40   * Date: 9/14/11
41   * Time: 10:22 AM
42   * To change this template use File | Settings | File Templates.
43   */
44  public class CheckoutManager_UT
45          extends BaseTestCase {
46  
47      private              IngestNIndexHandlerService ingestNIndexHandlerService = BeanLocator
48              .getIngestNIndexHandlerService();
49      private static final Logger                     LOG                        = LoggerFactory
50              .getLogger(CheckoutManager_UT.class);
51  
52      @Before
53      public void setUp() throws Exception {
54          super.setUp();
55      }
56  
57      @Test
58      public void testCheckOut() throws Exception {
59          URL resource = getClass().getResource("request.xml");
60          File file = new File(resource.toURI());
61          String inputFile = readFile(file);
62          Request request = new RequestHandler().toObject(inputFile);
63          Response response = ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);
64          assertNotNull(response);
65          List<RequestDocument> docStoreDocuments = request.getRequestDocuments();
66  
67          CheckoutManager checkoutManager = new CheckoutManager();
68          for (Iterator<RequestDocument> iterator = docStoreDocuments.iterator(); iterator.hasNext(); ) {
69              RequestDocument next = iterator.next();
70              String checkedOutContent = checkoutManager.checkOut(next.getUuid(), "mockUser", "checkout");
71              assertNotNull(checkedOutContent);
72  
73          }
74      }
75  
76      @Test
77      public void testCheckOutForInstance() throws Exception {
78  
79          /* List<String> bibIds = new ArrayList<String>();
80        ;
81        List<String> instanceIds = new ArrayList<String>();
82        ;
83  
84        URL resource = getClass().getResource("/org/kuali/ole/repository/requestInstance.xml");
85        File file = new File(resource.toURI());
86        String input = FileUtils.readFileToString(file);
87        RequestHandler rh = new RequestHandler();
88        Request request = rh.toObject(input);
89        Response response = ingestNIndexHandlerService.ingestNIndexRequestDocuments(request);
90        for (ResponseDocument resDoc : response.getDocuments()) {
91            bibIds.add(resDoc.getUuid());
92            for (ResponseDocument linkedDoc : resDoc.getLinkedDocuments()) {
93                instanceIds.add(linkedDoc.getUuid());
94            }
95        }
96        System.out.println("instance:" + instanceIds);*/
97          CheckoutManager checkoutManager = new CheckoutManager();
98          //        for (String instanceId : instanceIds) {
99          String checkedOutContent = checkoutManager
100                 .checkOut("1143e0b5-53ca-41e2-8655-e0a76fe930f6", "mockUser", "checkout");
101         LOG.info("checkedOutContent " + checkedOutContent);
102 
103         //        }
104     }
105 
106 }