KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > importer > ImporterComponentTest


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.importer;
18
19 import java.io.InputStream JavaDoc;
20 import java.io.InputStreamReader JavaDoc;
21
22 import org.alfresco.repo.security.authentication.AuthenticationComponent;
23 import org.alfresco.service.ServiceRegistry;
24 import org.alfresco.service.cmr.repository.NodeService;
25 import org.alfresco.service.cmr.repository.StoreRef;
26 import org.alfresco.service.cmr.view.ImporterService;
27 import org.alfresco.service.cmr.view.Location;
28 import org.alfresco.util.BaseSpringTest;
29 import org.alfresco.util.debug.NodeStoreInspector;
30
31
32 public class ImporterComponentTest extends BaseSpringTest
33 {
34     private ImporterService importerService;
35     private ImporterBootstrap importerBootstrap;
36     private NodeService nodeService;
37     private StoreRef storeRef;
38     private AuthenticationComponent authenticationComponent;
39
40     
41     @Override JavaDoc
42     protected void onSetUpInTransaction() throws Exception JavaDoc
43     {
44         nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
45         importerService = (ImporterService)applicationContext.getBean(ServiceRegistry.IMPORTER_SERVICE.getLocalName());
46         
47         importerBootstrap = (ImporterBootstrap)applicationContext.getBean("spacesBootstrap");
48         
49         this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
50         
51         this.authenticationComponent.setSystemUserAsCurrentUser();
52         
53         // Create the store
54
this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
55     }
56     
57     @Override JavaDoc
58     protected void onTearDownInTransaction() throws Exception JavaDoc
59     {
60         authenticationComponent.clearCurrentSecurityContext();
61         super.onTearDownInTransaction();
62     }
63     
64     public void testImport()
65         throws Exception JavaDoc
66     {
67         InputStream JavaDoc test = getClass().getClassLoader().getResourceAsStream("org/alfresco/repo/importer/importercomponent_test.xml");
68         InputStreamReader JavaDoc testReader = new InputStreamReader JavaDoc(test, "UTF-8");
69         Location location = new Location(storeRef);
70         importerService.importView(testReader, location, null, new ImportTimerProgress());
71         System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, storeRef));
72     }
73     
74     public void testBootstrap()
75     {
76         StoreRef bootstrapStoreRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
77         importerBootstrap.setStoreUrl(bootstrapStoreRef.toString());
78         importerBootstrap.bootstrap();
79         authenticationComponent.setSystemUserAsCurrentUser();
80         System.out.println(NodeStoreInspector.dumpNodeStore(nodeService, bootstrapStoreRef));
81     }
82 }
83
84
Popular Tags