Package org.exoplatform.services.document.test

Source Code of org.exoplatform.services.document.test.TestMSXExcelDocumentReader

/*
* Copyright (C) 2009 eXo Platform SAS.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.exoplatform.services.document.test;

import org.exoplatform.services.document.impl.DocumentReaderServiceImpl;
import org.exoplatform.services.document.impl.MSXExcelDocumentReader;

import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
* Created by The eXo Platform SAS Author : Sergey Karpenko
* <sergey.karpenko@exoplatform.com.ua>
*
* @version $Id: $
*/

public class TestMSXExcelDocumentReader extends BaseStandaloneTest
{

   DocumentReaderServiceImpl service;

   @Override
   public void setUp() throws Exception
   {
      super.setUp();
      service = new DocumentReaderServiceImpl(null);
      service.addDocumentReader(new MSXExcelDocumentReader());
   }

   public void testGetContentAsString() throws Exception
   {
      InputStream is = TestMSXExcelDocumentReader.class.getResourceAsStream("/test.xlsx");
      try
      {
         String text =
            service.getDocumentReader("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
               .getContentAsText(is);

         String expected =
            "Ronaldo Eric Cantona Kaka Ronaldonho " + "ID Group Functionality Executor Begin End Tested "
               + "XNNL XNNL Xay dung vung quan li nguyen lieu NamPH "
               + getDate(2005, 2, 2)
               + " "
               + getDate(2005, 10, 2)
               + " Tested "
               + "XNNL XNNL XNNL_HAVEST NamPH 1223554.0 "
               + getDate(2005, 10, 1)
               + " Tested "
               + "XNNL XNNL XNNL_PIECE_OF_GROUND NamPH "
               + getDate(2005, 10, 12)
               + " "
               + getDate(2005, 10, 2)
               + " Tested "
               + "XNNL XNNL XNNL_76 NamPH TRUE() "
               + getDate(1984, 12, 10)
               + " No "
               + "XNNL XNNL XNNL_CREATE_REAP NamPH none "
               + getDate(2005, 10, 3)
               + " No "
               + "XNNL XNNL XNNL_SCALE NamPH "
               + getDate(1984, 12, 10)
               + " "
               + getDate(2005, 10, 5)
               + " Tested "
               + "XNNL XNNL LASUCO_PROJECT NamPH "
               + getDate(2005, 10, 5)
               + " "
               + getDate(2005, 10, 6)
               + " No "
               + "XNNL XNNL LASUCO_PROJECT NamPH Tested "
               + "XNNL XNNL XNNL_BRANCH NamPH "
               + getDate(2005, 12, 12)
               + " "
               + getDate(2005, 6, 10)
               + " Tested "
               + "XNNL XNNL XNNL_SUGAR_RACE NamPH "
               + getDate(2005, 5, 9)
               + " "
               + getDate(2005, 6, 10)
               + " No "
               + "XNNL XNNL F_XNNL_DISTRI NamPH "
               + getDate(2005, 5, 9)
               + " "
               + getDate(2005, 6, 10)
               + " Tested "
               + "XNNL XNNL XNNL_LASUCO_USER NamPH "
               + getDate(2005, 9, 9)
               + " "
               + getDate(2005, 6, 10) + " No";

         assertEquals("Wrong string returned", normalizeWhitespaces(expected), normalizeWhitespaces(text));
      }
      finally
      {
         is.close();
      }
   }

   public String getDate(int year, int month, int day)
   {
      Calendar date = Calendar.getInstance();
      date.setTimeInMillis(0);
      date.set(year, month - 1, day, 0, 0, 0);
     
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
      return (dateFormat.format(date.getTime()));
   }

}
TOP

Related Classes of org.exoplatform.services.document.test.TestMSXExcelDocumentReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.