From do-not-reply at jboss.org Tue Jun 15 09:46:57 2010
Content-Type: multipart/mixed; boundary="===============4478584175332722177=="
MIME-Version: 1.0
From: do-not-reply at jboss.org
To: exo-jcr-commits at lists.jboss.org
Subject: [exo-jcr-commits] exo-jcr SVN: r2604 - in
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/utils:
io and 1 other directory.
Date: Tue, 15 Jun 2010 09:46:57 -0400
Message-ID: <201006151346.o5FDkvYt018828@svn01.web.mwc.hst.phx2.redhat.com>
--===============4478584175332722177==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: natasha.vakulenko
Date: 2010-06-15 09:46:56 -0400 (Tue, 15 Jun 2010)
New Revision: 2604
Added:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/=
jcr/impl/utils/io/
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/=
jcr/impl/utils/io/TestSpoolFile.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/=
jcr/impl/utils/io/TestSwapFile.java
Log:
EXOJCR-791: Added unit tests for SwapFile and SpoolFile.
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/servi=
ces/jcr/impl/utils/io/TestSpoolFile.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/impl/utils/io/TestSpoolFile.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/impl/utils/io/TestSpoolFile.java 2010-06-15 13:46:56 UTC (rev 2604)
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.jcr.impl.utils.io;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.File;
+
+import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Natasha Vakule=
nko
+ * @version $Id$ =
+ */
+
+public class TestSpoolFile extends TestCase
+{
+ private static final String dirName =3D "../";
+
+ private static final String fileName =3D "testSpoolFile";
+
+ public void testCreateTempFile() throws IOException
+ {
+ // This method creates a file on disk space.
+ // When calling a method delete() it should be removed.
+ SpoolFile sf =3D SpoolFile.createTempFile("prefix", "suffics", new F=
ile(dirName));
+ assertNotNull("File should be created.", sf);
+ assertTrue("File should be deleted.", sf.delete());
+ }
+
+ public void testAcquireFile() throws FileNotFoundException
+ {
+ SpoolFile sf =3D new SpoolFile(dirName + fileName);
+
+ // Add new holder of file, now file must be in use.
+ sf.acquire("holder");
+ assertTrue("File must be in use.", sf.inUse());
+
+ sf.release("holder");
+ sf.delete();
+
+ // Use non-existent file.
+ try
+ {
+ sf.acquire("anotherHolder");
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testReleaseFile() throws FileNotFoundException
+ {
+ SpoolFile sf =3D new SpoolFile(dirName + fileName);
+
+ // Add new holder of file.
+ sf.acquire("holder");
+
+ // Release file from holder.
+ sf.release("holder");
+
+ assertFalse("File should not have holders.", sf.inUse());
+ sf.delete();
+
+ // Use non-existent file.
+ try
+ {
+ sf.release("someHolder");
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testFileInUse() throws FileNotFoundException
+ {
+ SpoolFile sf =3D new SpoolFile(dirName + fileName);
+
+ sf.acquire("holder");
+ assertTrue("The file has holder. It must be in use.", sf.inUse());
+
+ sf.release("holder");
+ assertFalse("The file has no holder. It should not be in use.", sf.i=
nUse());
+
+ sf.delete();
+
+ // Work with non-existent file.
+ try
+ {
+ sf.inUse();
+ fail("FileNotFoundException should have been thrown.");
+ }
+ catch (FileNotFoundException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testDeleteFile() throws FileNotFoundException
+ {
+ // This method not creates a file on disk space.
+ SpoolFile sf =3D new SpoolFile(dirName + fileName);
+
+ // Add and release new holder of file.
+ sf.acquire("holder");
+ sf.release("holder");
+
+ // Now file is free. It can be deleted.
+ // File on disk does not exist. It will not be removed from disk spa=
ce.
+ assertFalse("Deleted file was not created on the disk.", sf.delete()=
);
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exo=
platform/services/jcr/impl/utils/io/TestSpoolFile.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/servi=
ces/jcr/impl/utils/io/TestSwapFile.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/impl/utils/io/TestSwapFile.java (rev 0)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services=
/jcr/impl/utils/io/TestSwapFile.java 2010-06-15 13:46:56 UTC (rev 2604)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see.
+ */
+package org.exoplatform.services.jcr.impl.utils.io;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.exoplatform.services.jcr.impl.util.io.SwapFile;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Natasha Vakule=
nko
+ * @version $Id$ =
+ */
+
+public class TestSwapFile extends TestCase
+{
+ private static final String dirName =3D "../";
+
+ private static final String fileName =3D "childSwapFile";
+
+ public void testCreateTempFile()
+ {
+ // Not applicable creation.
+ try
+ {
+ SwapFile.createTempFile("prefix", "suffix", new File(dirName));
+ fail("IOException should have been thrown.");
+ }
+ catch (IOException e)
+ {
+ // Ok.
+ }
+ }
+
+ public void testGetSwapFile() throws IOException
+ {
+ // Get swap file is possible only in this way.
+ SwapFile sf =3D SwapFile.get(new File(dirName), fileName);
+ assertNotNull("File should be created.", sf);
+ sf.spoolDone();
+ sf.delete();
+ }
+
+ public void testIsSpooled() throws IOException
+ {
+ SwapFile sf =3D SwapFile.get(new File(dirName), fileName);
+ assertFalse("Spool is not over.", sf.isSpooled());
+ sf.spoolDone();
+ assertTrue("Spool is over.", sf.isSpooled());
+ sf.delete();
+ }
+
+ public void testSpoolDone() throws IOException
+ {
+ SwapFile sf =3D SwapFile.get(new File(dirName), fileName);
+ sf.spoolDone();
+ assertTrue("Spool should be done.", sf.isSpooled());
+ sf.delete();
+ }
+
+ public void testDeleteSpoolFile() throws IOException
+ {
+ SwapFile sf =3D SwapFile.get(new File(dirName), fileName);
+ sf.spoolDone();
+
+ // File on disk does not exist. It will not be removed from disk spa=
ce.
+ assertFalse("Deleted file was not created on the disk.", sf.delete()=
);
+ }
+}
Property changes on: jcr/trunk/exo.jcr.component.core/src/test/java/org/exo=
platform/services/jcr/impl/utils/io/TestSwapFile.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
--===============4478584175332722177==--