KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > filestore > FileContentStoreTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content.filestore;
18
19 import java.io.File JavaDoc;
20
21 import org.alfresco.repo.content.AbstractContentReadWriteTest;
22 import org.alfresco.repo.content.ContentStore;
23 import org.alfresco.repo.content.MimetypeMap;
24 import org.alfresco.service.cmr.repository.ContentReader;
25 import org.alfresco.util.TempFileProvider;
26
27 /**
28  * Tests read and write functionality for the store.
29  *
30  * @see org.alfresco.repo.content.filestore.FileContentStore
31  *
32  * @author Derek Hulley
33  */

34 public class FileContentStoreTest extends AbstractContentReadWriteTest
35 {
36     private FileContentStore store;
37     
38     @Override JavaDoc
39     public void setUp() throws Exception JavaDoc
40     {
41         super.setUp();
42         
43         // create a store that uses a subdirectory of the temp directory
44
File JavaDoc tempDir = TempFileProvider.getTempDir();
45         store = new FileContentStore(
46                 tempDir.getAbsolutePath() +
47                 File.separatorChar +
48                 getName());
49     }
50     
51     @Override JavaDoc
52     protected ContentStore getStore()
53     {
54         return store;
55     }
56     
57     public void testGetSafeContentReader() throws Exception JavaDoc
58     {
59         String JavaDoc template = "ABC {0}{1}";
60         String JavaDoc arg0 = "DEF";
61         String JavaDoc arg1 = "123";
62         String JavaDoc fakeContent = "ABC DEF123";
63
64         // get a good reader
65
ContentReader reader = getReader();
66         assertFalse("No content has been written to the URL yet", reader.exists());
67         
68         // now create a file for it
69
File JavaDoc file = store.createNewFile(reader.getContentUrl());
70         assertTrue("File store did not connect new file", file.exists());
71         assertTrue("Reader did not detect creation of the underlying file", reader.exists());
72         
73         // remove the underlying content
74
file.delete();
75         assertFalse("File not missing", file.exists());
76         assertFalse("Reader doesn't show missing content", reader.exists());
77         
78         // make a safe reader
79
ContentReader safeReader = FileContentReader.getSafeContentReader(reader, template, arg0, arg1);
80         // check it
81
assertTrue("Fake content doesn't exist", safeReader.exists());
82         assertEquals("Fake content incorrect", fakeContent, safeReader.getContentString());
83         assertEquals("Fake mimetype incorrect", MimetypeMap.MIMETYPE_TEXT_PLAIN, safeReader.getMimetype());
84         assertEquals("Fake encoding incorrect", "UTF-8", safeReader.getEncoding());
85         
86         // now repeat with a null reader
87
reader = null;
88         safeReader = FileContentReader.getSafeContentReader(reader, template, arg0, arg1);
89         // check it
90
assertTrue("Fake content doesn't exist", safeReader.exists());
91         assertEquals("Fake content incorrect", fakeContent, safeReader.getContentString());
92     }
93 }
94
Popular Tags