Author: sergiykarpenko
Date: 2010-08-27 04:46:34 -0400 (Fri, 27 Aug 2010)
New Revision: 2997
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/BaseStandaloneTest.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestHtmlDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSExcelDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSOutlookDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSWordDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXExcelDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXPPTDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXWordDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestOpenOfficeDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPDFDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPPTDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPropertiesExtracting.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestTextPlainDocumentReader.java
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestXMLDocumentReader.java
Log:
EXOJCR-886: tests updated
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/BaseStandaloneTest.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/BaseStandaloneTest.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/BaseStandaloneTest.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -83,4 +83,11 @@
return f.delete();
}
+ public String normalizeWhitespaces(String str)
+ {
+ str = str.trim();
+ str = str.replaceAll("\\s+", " ");
+ return str;
+ }
+
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestHtmlDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestHtmlDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestHtmlDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -32,21 +32,28 @@
public class TestHtmlDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestHtmlDocumentReader.class.getResourceAsStream("/test.html");
- String mimeType = mimetypeResolver.getMimeType("test.html");
+ try
+ {
+ String mimeType = mimetypeResolver.getMimeType("test.html");
- DocumentReader dr = service_.getDocumentReader(mimeType);
- String text = dr.getContentAsText(is);
- // TODO text is too huge, need small test file
+ DocumentReader dr = service.getDocumentReader(mimeType);
+ String text = dr.getContentAsText(is);
+ assertTrue(text.contains("This is the third maintenance release of the
redesigned 2.0"));
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSExcelDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSExcelDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSExcelDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,46 +31,42 @@
public class TestMSExcelDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestMSExcelDocumentReader.class.getResourceAsStream("/test.xls");
- String text =
service_.getDocumentReader("application/excel").getContentAsText(is);
- System.out.println(" text [" + text + "]");
- /*
- * String etalon =
- * "Ronaldo Eric Cantona Kaka Ronaldonho ID Group Functionality Executor Begin
End Tested "
- * +
- * "XNNL XNNL Xay dung vung quan li nguyen lieu NamPH 2005-02-02
00:00:00.000+0200 2005-10-02 00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_HAVEST NamPH 1223554.0 2005-10-01 00:00:00.000+0300 Tested
"
- * +
- * "XNNL XNNL XNNL_PIECE_OF_GROUND NamPH 2005-10-12 00:00:00.000+0300
2005-10-02 00:00:00.000+0300 Tested "
- * +"XNNL XNNL XNNL_76 NamPH TRUE 1984-12-10 00:00:00.000+0200 No "
- * +"XNNL XNNL XNNL_CREATE_REAP NamPH none 2005-10-03 00:00:00.000+0300 No
"
- * +
- * "XNNL XNNL XNNL_SCALE NamPH 1984-12-10 00:00:00.000+0200 2005-10-05
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL LASUCO_PROJECT NamPH 2005-10-05 00:00:00.000+0300 2005-10-06
00:00:00.000+0300 No "
- * +"XNNL XNNL LASUCO_PROJECT NamPH Tested "+
- * "XNNL XNNL XNNL_BRANCH NamPH 2005-12-12 00:00:00.000+0200 2005-06-10
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_SUGAR_RACE NamPH 2005-05-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 No "
- * +
- * "XNNL XNNL F_XNNL_DISTRI NamPH 2005-05-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_LASUCO_USER NamPH 2005-09-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 No "
- * ; System.out.println(" etalon ["+etalon+"]");
- * assertEquals("String length is
incorect",etalon.length(),text.length());
- * assertEquals("Wrong string returned",etalon ,text );
- */
+ try
+ {
+ String text =
service.getDocumentReader("application/excel").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 2005-02-02
00:00:00.000+0200 2005-10-02 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_HAVEST NamPH 1223554.0 2005-10-01 00:00:00.000+0300
Tested "
+ + "XNNL XNNL XNNL_PIECE_OF_GROUND NamPH 2005-10-12 00:00:00.000+0300
2005-10-02 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_76 NamPH TRUE() 1984-12-10 00:00:00.000+0200 No
"
+ + "XNNL XNNL XNNL_CREATE_REAP NamPH none 2005-10-03 00:00:00.000+0300
No "
+ + "XNNL XNNL XNNL_SCALE NamPH 1984-12-10 00:00:00.000+0200 2005-10-05
00:00:00.000+0300 Tested "
+ + "XNNL XNNL LASUCO_PROJECT NamPH 2005-10-05 00:00:00.000+0300
2005-10-06 00:00:00.000+0300 No "
+ + "XNNL XNNL LASUCO_PROJECT NamPH Tested "
+ + "XNNL XNNL XNNL_BRANCH NamPH 2005-12-12 00:00:00.000+0200
2005-06-10 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_SUGAR_RACE NamPH 2005-05-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 No "
+ + "XNNL XNNL F_XNNL_DISTRI NamPH 2005-05-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_LASUCO_USER NamPH 2005-09-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 No";
+ assertEquals("Wrong string returned", normalizeWhitespaces(expected),
normalizeWhitespaces(text));
+ }
+ finally
+ {
+ is.close();
+ }
+
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSOutlookDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSOutlookDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSOutlookDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -32,12 +32,12 @@
public class TestMSOutlookDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
@@ -45,9 +45,15 @@
String name = "/test.msg";
InputStream is = BasicTestCase.class.getResourceAsStream(name);
assertNotNull(is);
-
- String text =
service_.getDocumentReader("application/vnd.ms-outlook").getContentAsText(is);
- String etalon = "Goooogle\n" + "theme\n" + "Hello, this is
the test outlook message.\r\n";
- assertEquals("Wrong string returned", etalon, text);
+ try
+ {
+ String text =
service.getDocumentReader("application/vnd.ms-outlook").getContentAsText(is);
+ String etalon = "Goooogle\n" + "theme\n" + "Hello, this
is the test outlook message.\r\n";
+ assertEquals("Wrong string returned", etalon, text);
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSWordDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSWordDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSWordDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,38 +31,42 @@
public class TestMSWordDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsStringTemplate() throws Exception
{
InputStream is =
TestMSWordDocumentReader.class.getResourceAsStream("/test.dot");
- String text =
service_.getDocumentReader("application/msworddot").getContentAsText(is);
- System.out.println("text [" + text + "]");
- String etalon = "exotest";
- System.out.println("etalon [" + etalon + "]");
-
- System.out.println("[" + text.length() + "] [" +
etalon.length() + "]");
- assertEquals("Wrong string returned", etalon, text);
+ try
+ {
+ String text =
service.getDocumentReader("application/msworddot").getContentAsText(is);
+ String etalon = "exotest";
+ assertEquals("Wrong string returned", etalon, text);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testGetContentAsStringDoc() throws Exception
{
InputStream is =
TestMSWordDocumentReader.class.getResourceAsStream("/test.doc");
- String text =
service_.getDocumentReader("application/msword").getContentAsText(is);
- System.out.println("text [" + text + "]");
+ try
+ {
+ String text =
service.getDocumentReader("application/msword").getContentAsText(is);
+ assertTrue(text
+ .contains("Before the test starts there is a directions section, which
takes a few minutes to read"));
- /*
- * String etalon = "Hello.\n" +"This is the test document
12345\n"
- * +"Table\n" +"Title One Two\n" +"Hello_Title Hello_One
Hello_Two\n";
- * System.out.println("etalon ["+etalon+"]");
- * System.out.println("["+text.length()+"]
["+etalon.length()+"]");
- * assertEquals("Wrong string returned",etalon ,text );
- */
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXExcelDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXExcelDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXExcelDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,47 +31,44 @@
public class TestMSXExcelDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
@Override
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestMSXExcelDocumentReader.class.getResourceAsStream("/test.xlsx");
- String text =
service_.getDocumentReader("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").getContentAsText(is);
- System.out.println(" text [" + text + "]");
- /*
- * String etalon =
- * "Ronaldo Eric Cantona Kaka Ronaldonho ID Group Functionality Executor Begin
End Tested "
- * +
- * "XNNL XNNL Xay dung vung quan li nguyen lieu NamPH 2005-02-02
00:00:00.000+0200 2005-10-02 00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_HAVEST NamPH 1223554.0 2005-10-01 00:00:00.000+0300 Tested
"
- * +
- * "XNNL XNNL XNNL_PIECE_OF_GROUND NamPH 2005-10-12 00:00:00.000+0300
2005-10-02 00:00:00.000+0300 Tested "
- * +"XNNL XNNL XNNL_76 NamPH TRUE 1984-12-10 00:00:00.000+0200 No "
- * +"XNNL XNNL XNNL_CREATE_REAP NamPH none 2005-10-03 00:00:00.000+0300 No
"
- * +
- * "XNNL XNNL XNNL_SCALE NamPH 1984-12-10 00:00:00.000+0200 2005-10-05
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL LASUCO_PROJECT NamPH 2005-10-05 00:00:00.000+0300 2005-10-06
00:00:00.000+0300 No "
- * +"XNNL XNNL LASUCO_PROJECT NamPH Tested "+
- * "XNNL XNNL XNNL_BRANCH NamPH 2005-12-12 00:00:00.000+0200 2005-06-10
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_SUGAR_RACE NamPH 2005-05-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 No "
- * +
- * "XNNL XNNL F_XNNL_DISTRI NamPH 2005-05-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 Tested "
- * +
- * "XNNL XNNL XNNL_LASUCO_USER NamPH 2005-09-09 00:00:00.000+0300 2005-06-10
00:00:00.000+0300 No "
- * ; System.out.println(" etalon ["+etalon+"]");
- * assertEquals("String length is
incorect",etalon.length(),text.length());
- * assertEquals("Wrong string returned",etalon ,text );
- */
+ 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 2005-02-02
00:00:00.000+0200 2005-10-02 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_HAVEST NamPH 1223554.0 2005-10-01 00:00:00.000+0300
Tested "
+ + "XNNL XNNL XNNL_PIECE_OF_GROUND NamPH 2005-10-12 00:00:00.000+0300
2005-10-02 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_76 NamPH TRUE() 1984-12-10 00:00:00.000+0200 No
"
+ + "XNNL XNNL XNNL_CREATE_REAP NamPH none 2005-10-03 00:00:00.000+0300
No "
+ + "XNNL XNNL XNNL_SCALE NamPH 1984-12-10 00:00:00.000+0200 2005-10-05
00:00:00.000+0300 Tested "
+ + "XNNL XNNL LASUCO_PROJECT NamPH 2005-10-05 00:00:00.000+0300
2005-10-06 00:00:00.000+0300 No "
+ + "XNNL XNNL LASUCO_PROJECT NamPH Tested "
+ + "XNNL XNNL XNNL_BRANCH NamPH 2005-12-12 00:00:00.000+0200
2005-06-10 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_SUGAR_RACE NamPH 2005-05-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 No "
+ + "XNNL XNNL F_XNNL_DISTRI NamPH 2005-05-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 Tested "
+ + "XNNL XNNL XNNL_LASUCO_USER NamPH 2005-09-09 00:00:00.000+0300
2005-06-10 00:00:00.000+0300 No";
+ assertEquals("Wrong string returned", normalizeWhitespaces(expected),
normalizeWhitespaces(text));
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXPPTDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXPPTDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXPPTDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,25 +31,32 @@
public class TestMSXPPTDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
@Override
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestMSXPPTDocumentReader.class.getResourceAsStream("/test.pptx");
- String text =
-
service_.getDocumentReader("application/vnd.openxmlformats-officedocument.presentationml.presentation")
- .getContentAsText(is);
- String etalon =
- "TEST POWERPOINT\n" + "Manchester United \n" + "AC
Milan\n" + "SLIDE 2 \n" + "Eric Cantona\n" + "Kaka\n"
- + "Ronaldo\n" + "The natural scients universitys\n";
+ try
+ {
+ String text =
+
service.getDocumentReader("application/vnd.openxmlformats-officedocument.presentationml.presentation")
+ .getContentAsText(is);
+ String etalon =
+ "TEST POWERPOINT\n" + "Manchester United \n" + "AC
Milan\n" + "SLIDE 2 \n" + "Eric Cantona\n" + "Kaka\n"
+ + "Ronaldo\n" + "The natural scients universitys\n";
- assertEquals("Wrong string returned", etalon, text);
+ assertEquals("Wrong string returned", etalon, text);
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXWordDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXWordDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestMSXWordDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -29,27 +29,36 @@
*/
public class TestMSXWordDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
@Override
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsStringDoc() throws Exception
{
InputStream is =
TestMSXWordDocumentReader.class.getResourceAsStream("/test.docx");
- String text =
service_.getDocumentReader("application/vnd.openxmlformats-officedocument.wordprocessingml.document").getContentAsText(is);
- System.out.println("text [" + text + "]");
+ try
+ {
+ String text =
+
service.getDocumentReader("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
+ .getContentAsText(is);
+ System.out.println("text [" + text + "]");
- /*
- * String etalon = "Hello.\n" +"This is the test document
12345\n"
- * +"Table\n" +"Title One Two\n" +"Hello_Title Hello_One
Hello_Two\n";
- * System.out.println("etalon ["+etalon+"]");
- * System.out.println("["+text.length()+"]
["+etalon.length()+"]");
- * assertEquals("Wrong string returned",etalon ,text );
- */
+ /*
+ * String etalon = "Hello.\n" +"This is the test document
12345\n"
+ * +"Table\n" +"Title One Two\n" +"Hello_Title
Hello_One Hello_Two\n";
+ * System.out.println("etalon ["+etalon+"]");
+ * System.out.println("["+text.length()+"]
["+etalon.length()+"]");
+ * assertEquals("Wrong string returned",etalon ,text );
+ */
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestOpenOfficeDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestOpenOfficeDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestOpenOfficeDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,52 +31,59 @@
public class TestOpenOfficeDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestOpenOfficeDocumentReader.class.getResourceAsStream("/test.odt");
- String text =
service_.getDocumentReader("application/vnd.oasis.opendocument.text").getContentAsText(is);
- System.out.println("[" + text + "]");
- /*
- * String etalon = "Subscription:" +
- * "\tEULA with add on warranties and non GPL viral effect (all Customer's
development free of GPL license limitations). This agreement continues to be valid even if
customers do not renew their subscription.\n"
- * +
- * "\tProduct documentation including user and admin guides to eXo platform
portal, ECM, JCR, and Portlet Container. (currently we have all the docs accessible for
free but it will not)\n"
- * +
- * "\tAccess to all Flash tutorial gives a visual guide to eXo platform and
demonstrates a comprehensive tutorial that enhance the understanding of eXo products.
(only part of Flash tutorials are accessible for free)\n"
- * +
- * "\tAdvanced Installer is an application that makes it quick and easy to
install eXo platform products with simple clicks and allows better configuration to
integrate existing database and directories (LDAP) in a multi platform
environment.\n"
- * +
- * "\tUnlimited access to online premium forum (customer request tracking?)
support, you will get answer from eXo platform company technical specialist employees.
(TODO) \n"
- * +
- * "\tUnlimited email support within 48 hours response time for limited
contact names per CPU.(i think we may join it with prev item using term customer request
tracking with email notification)\n"
- * +
- * "\tUpdate alert will send out email periodically to subscribers all the
latest change in eXo documentations, flash tutorials, and product services.
(TODO)\n"
- * +
- * "\tTechnical code improvement alert will send out email periodically to
subscribers to inform of all the latest code patches, latest version, latest code
improvement download. (TODO)\n"
- * +
- * "\tKnowledge Base subscribers can access to all of eXo platform wiki
knowledge bases. (TODO, i do not think we may put it into agreement yet)\n"
- * +
- * "\tFeature Request Priority As customers you have priorities to request the
latest features improvement for any of eXo products next version. (what does it
mean?)\n"
- * + "\n" +
- * "Subscription is annual and per CPU because it is the unit of load increase
and so more support demand. Subscription advantages are:\n"
- * + "\tEULA � it is obligatory to be Subscriber to get EULA\n" +
- * "\tAdditional documentations (Guides, Flash tutorials)\n" +
- * "\tAdditional software (Installer)\n" +
- * "\tAdditional product/documentation changes notifications\n" +
- * "\tProfessional support: limited contact name (3 customer contact with 1
eXo contact per CPU), 48 hours to answer via email\n"
- * + "\tFeature request priority (also depending on CPU number)\n" +
"\n";
- * System.out.println("["+etalon+"]");
- * System.out.println("TEXT size ["+text.
- * length()+"] ETALON LEN ["+etalon.length()+"]");
- * assertEquals("Wrong string returned", etalon, text);
- */
+ try
+ {
+ String text =
service.getDocumentReader("application/vnd.oasis.opendocument.text").getContentAsText(is);
+ System.out.println("[" + text + "]");
+ /*
+ * String etalon = "Subscription:" +
+ * "\tEULA with add on warranties and non GPL viral effect (all
Customer's development free of GPL license limitations). This agreement continues to
be valid even if customers do not renew their subscription.\n"
+ * +
+ * "\tProduct documentation including user and admin guides to eXo platform
portal, ECM, JCR, and Portlet Container. (currently we have all the docs accessible for
free but it will not)\n"
+ * +
+ * "\tAccess to all Flash tutorial gives a visual guide to eXo platform and
demonstrates a comprehensive tutorial that enhance the understanding of eXo products.
(only part of Flash tutorials are accessible for free)\n"
+ * +
+ * "\tAdvanced Installer is an application that makes it quick and easy to
install eXo platform products with simple clicks and allows better configuration to
integrate existing database and directories (LDAP) in a multi platform
environment.\n"
+ * +
+ * "\tUnlimited access to online premium forum (customer request tracking?)
support, you will get answer from eXo platform company technical specialist employees.
(TODO) \n"
+ * +
+ * "\tUnlimited email support within 48 hours response time for limited
contact names per CPU.(i think we may join it with prev item using term customer request
tracking with email notification)\n"
+ * +
+ * "\tUpdate alert will send out email periodically to subscribers all the
latest change in eXo documentations, flash tutorials, and product services.
(TODO)\n"
+ * +
+ * "\tTechnical code improvement alert will send out email periodically to
subscribers to inform of all the latest code patches, latest version, latest code
improvement download. (TODO)\n"
+ * +
+ * "\tKnowledge Base subscribers can access to all of eXo platform wiki
knowledge bases. (TODO, i do not think we may put it into agreement yet)\n"
+ * +
+ * "\tFeature Request Priority As customers you have priorities to request
the latest features improvement for any of eXo products next version. (what does it
mean?)\n"
+ * + "\n" +
+ * "Subscription is annual and per CPU because it is the unit of load
increase and so more support demand. Subscription advantages are:\n"
+ * + "\tEULA � it is obligatory to be Subscriber to get EULA\n" +
+ * "\tAdditional documentations (Guides, Flash tutorials)\n" +
+ * "\tAdditional software (Installer)\n" +
+ * "\tAdditional product/documentation changes notifications\n" +
+ * "\tProfessional support: limited contact name (3 customer contact with 1
eXo contact per CPU), 48 hours to answer via email\n"
+ * + "\tFeature request priority (also depending on CPU number)\n" +
"\n";
+ * System.out.println("["+etalon+"]");
+ * System.out.println("TEXT size ["+text.
+ * length()+"] ETALON LEN ["+etalon.length()+"]");
+ * assertEquals("Wrong string returned", etalon, text);
+ */
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPDFDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPDFDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPDFDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,21 +31,27 @@
public class TestPDFDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestPDFDocumentReader.class.getResourceAsStream("/test.pdf");
- String text =
service_.getDocumentReader("application/pdf").getContentAsText(is);
- String etalon = "Hello\nThis is my first Cocoon page!\npage 1 \n";
+ try
+ {
+ String text =
service.getDocumentReader("application/pdf").getContentAsText(is);
+ String expected = "Hello This is my first Cocoon page! page 1";
- System.out.println("[" + text + "]");
- // assertEquals("Wrong string returned",etalon ,text );
+ assertEquals("Wrong string returned", normalizeWhitespaces(expected),
normalizeWhitespaces(text));
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPPTDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPPTDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPPTDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,21 +31,28 @@
public class TestPPTDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestPPTDocumentReader.class.getResourceAsStream("/test.ppt");
- String text =
service_.getDocumentReader("application/powerpoint").getContentAsText(is);
- String etalon =
- "TEST POWERPOINT\n" + "Manchester United \n" + "AC
Milan\n" + "SLIDE 2 \n" + "Eric Cantona\n" + "Kaka\n"
- + "Ronaldo\n" + "The natural scients universitys\n\n";
- assertEquals("Wrong string returned", etalon, text);
+ try
+ {
+ String text =
service.getDocumentReader("application/powerpoint").getContentAsText(is);
+ String etalon =
+ "TEST POWERPOINT\n" + "Manchester United \n" + "AC
Milan\n" + "SLIDE 2 \n" + "Eric Cantona\n" + "Kaka\n"
+ + "Ronaldo\n" + "The natural scients
universitys\n\n";
+ assertEquals("Wrong string returned", etalon, text);
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPropertiesExtracting.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPropertiesExtracting.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestPropertiesExtracting.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,66 +31,122 @@
public class TestPropertiesExtracting extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ // service = new DocumentReaderServiceImpl(null);
+ // InitParams params = new InitParams();
+ // service.addDocumentReader(new TextPlainDocumentReader(params));
+ // service.addDocumentReader(new XMLDocumentReader());
+ // service.addDocumentReader(new HTMLDocumentReader(null));
+ // service.addDocumentReader(new MSExcelDocumentReader());
+ // service.addDocumentReader(new MSOutlookDocumentReader());
+ // service.addDocumentReader(new MSWordDocumentReader());
+ // service.addDocumentReader(new MSXExcelDocumentReader());
+ // service.addDocumentReader(new MSXPPTDocumentReader());
+ // service.addDocumentReader(new MSXWordDocumentReader());
+ // service.addDocumentReader(new OpenOfficeDocumentReader());
+ // service.addDocumentReader(new PDFDocumentReader());
+ // service.addDocumentReader(new PPTDocumentReader());
}
public void testPDFDocumentReaderService() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/test.pdf");
- DocumentReader rdr = service_.getDocumentReader("application/pdf");
- Properties props = rdr.getProperties(is);
- printProps(props);
+ try
+ {
+ DocumentReader rdr = service.getDocumentReader("application/pdf");
+ Properties props = rdr.getProperties(is);
+ printProps(props);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testPDFDocumentReaderServiceXMPMetadata() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/MyTest.pdf");
- DocumentReader rdr = service_.getDocumentReader("application/pdf");
+ try
+ {
+ DocumentReader rdr = service.getDocumentReader("application/pdf");
- Properties testprops = rdr.getProperties(is);
- printProps(testprops);
+ Properties testprops = rdr.getProperties(is);
+ printProps(testprops);
- Properties etalon = new Properties();
- etalon.put(DCMetaData.TITLE, "Test de convertion de fichier tif");
- etalon.put(DCMetaData.CREATOR, "Christian Klaus");
- etalon.put(DCMetaData.SUBJECT, "20080901 TEST Christian Etat OK");
- Calendar c = ISO8601.parseEx("2008-09-01T08:01:10+00:00");;
- etalon.put(DCMetaData.DATE, c);
+ Properties etalon = new Properties();
+ etalon.put(DCMetaData.TITLE, "Test de convertion de fichier tif");
+ etalon.put(DCMetaData.CREATOR, "Christian Klaus");
+ etalon.put(DCMetaData.SUBJECT, "20080901 TEST Christian Etat OK");
+ Calendar c = ISO8601.parseEx("2008-09-01T08:01:10+00:00");;
+ etalon.put(DCMetaData.DATE, c);
- evalProps(etalon, testprops);
+ evalProps(etalon, testprops);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testWordDocumentReaderService() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/test.doc");
- Properties props =
service_.getDocumentReader("application/msword").getProperties(is);
- printProps(props);
+ try
+ {
+ Properties props =
service.getDocumentReader("application/msword").getProperties(is);
+ printProps(props);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testPPTDocumentReaderService() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/test.ppt");
- Properties props =
service_.getDocumentReader("application/powerpoint").getProperties(is);
- printProps(props);
+ try
+ {
+ Properties props =
service.getDocumentReader("application/powerpoint").getProperties(is);
+ printProps(props);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testExcelDocumentReaderService() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/test.xls");
- Properties props =
service_.getDocumentReader("application/excel").getProperties(is);
- printProps(props);
+ try
+ {
+ Properties props =
service.getDocumentReader("application/excel").getProperties(is);
+ printProps(props);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testOODocumentReaderService() throws Exception
{
InputStream is =
TestPropertiesExtracting.class.getResourceAsStream("/test.odt");
- Properties props =
service_.getDocumentReader("application/vnd.oasis.opendocument.text").getProperties(is);
- printProps(props);
+ try
+ {
+ Properties props =
service.getDocumentReader("application/vnd.oasis.opendocument.text").getProperties(is);
+ printProps(props);
+ }
+ finally
+ {
+ is.close();
+ }
}
private void printProps(Properties props)
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestTextPlainDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestTextPlainDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestTextPlainDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,28 +31,42 @@
public class TestTextPlainDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestTextPlainDocumentReader.class.getResourceAsStream("/test.txt");
- String text =
service_.getDocumentReader("text/plain").getContentAsText(is);
- assertEquals("Wrong string returned", "This is a test text\n",
text);
+ try
+ {
+ String text =
service.getDocumentReader("text/plain").getContentAsText(is);
+ assertEquals("Wrong string returned", "This is a test
text\n", text);
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testGetContentAsStringWithEncoding() throws Exception
{
InputStream is =
TestTextPlainDocumentReader.class.getResourceAsStream("/testUTF8.txt");
- String text =
service_.getDocumentReader("text/plain").getContentAsText(is,
"UTF-8");
- String etalon =
- "\ufeff\u0426\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u0438\u0439
\u0442\u0435\u043a\u0441\u0442. \u042d\u0442\u043e
\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.";
- assertEquals("Wrong string returned", etalon, text);
+ try
+ {
+ String text =
service.getDocumentReader("text/plain").getContentAsText(is,
"UTF-8");
+ String expected =
+ "\ufeff\u0426\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u0438\u0439
\u0442\u0435\u043a\u0441\u0442. \u042d\u0442\u043e
\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0442\u0435\u043a\u0441\u0442.";
+ assertEquals("Wrong string returned", expected, text);
+ }
+ finally
+ {
+ is.close();
+ }
}
}
Modified:
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestXMLDocumentReader.java
===================================================================
---
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestXMLDocumentReader.java 2010-08-27
07:03:02 UTC (rev 2996)
+++
core/trunk/exo.core.component.document/src/test/java/org/exoplatform/services/document/test/TestXMLDocumentReader.java 2010-08-27
08:46:34 UTC (rev 2997)
@@ -31,38 +31,58 @@
public class TestXMLDocumentReader extends BaseStandaloneTest
{
- DocumentReaderService service_;
+ DocumentReaderService service;
public void setUp() throws Exception
{
super.setUp();
- service_ =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
+ service =
(DocumentReaderService)getComponentInstanceOfType(DocumentReaderService.class);
}
public void testGetContentAsString() throws Exception
{
InputStream is =
TestXMLDocumentReader.class.getResourceAsStream("/test.xml");
- String text =
service_.getDocumentReader("text/xml").getContentAsText(is);
- String expected = "John\n" + " Alice\n" + "
Reminder\n" + " Don't forget it this weekend!";
- assertEquals("Wrong string returned", expected, text.trim());
+ try
+ {
+ String text =
service.getDocumentReader("text/xml").getContentAsText(is);
+ String expected = "John\n" + " Alice\n" + "
Reminder\n" + " Don't forget it this weekend!";
+ assertEquals("Wrong string returned", expected, text.trim());
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testCDATAGetContentAsString() throws Exception
{
InputStream is =
TestXMLDocumentReader.class.getResourceAsStream("/testCDATA.xml");
- String text =
service_.getDocumentReader("text/xml").getContentAsText(is);
- String expected = "This is a text inside CDATA.";
- assertEquals("Wrong string returned", expected, text.trim());
+ try
+ {
+ String text =
service.getDocumentReader("text/xml").getContentAsText(is);
+ String expected = "This is a text inside CDATA.";
+ assertEquals("Wrong string returned", expected, text.trim());
+ }
+ finally
+ {
+ is.close();
+ }
}
public void testI18ngetContentAsString() throws Exception
{
InputStream is =
TestXMLDocumentReader.class.getResourceAsStream("/testUTF8.xml");
- String text =
service_.getDocumentReader("text/xml").getContentAsText(is);
- final String expected =
- "\u0426\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u0438\u0439
\u0442\u0435\u043a\u0441\u0442.\n"
- + "Archim\u00E8de et Lius \u00E0 Ch\u00E2teauneuf testing chars en
\u00E9t\u00E9";
- assertEquals("Wrong string returned", expected, text.trim());
+ try
+ {
+ String text =
service.getDocumentReader("text/xml").getContentAsText(is);
+ final String expected =
+ "\u0426\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u0438\u0439
\u0442\u0435\u043a\u0441\u0442.\n"
+ + "Archim\u00E8de et Lius \u00E0 Ch\u00E2teauneuf testing chars en
\u00E9t\u00E9";
+ assertEquals("Wrong string returned", expected, text.trim());
+ }
+ finally
+ {
+ is.close();
+ }
}
-
}