KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > impl > TestService


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5
6 package org.exoplatform.services.jcr.impl;
7
8
9 import java.io.ByteArrayInputStream JavaDoc;
10
11 import javax.jcr.Repository;
12
13 import org.exoplatform.container.PortalContainer;
14 import org.exoplatform.services.jcr.BaseTest;
15 import org.exoplatform.services.jcr.RepositoryService;
16 import org.exoplatform.services.jcr.config.ContainerEntry;
17 import org.exoplatform.services.jcr.config.RepositoryServiceConfig;
18 import org.exoplatform.services.jcr.impl.config.DummyConfig;
19 import org.exoplatform.services.jcr.impl.config.XMLConfig;
20 import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
21 import org.exoplatform.services.jcr.impl.core.TicketImpl;
22 import org.exoplatform.services.xml.querying.XMLQueryingService;
23
24
25 /**
26  * Created by The eXo Platform SARL .
27  *
28  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
29  * @version $Id: TestService.java,v 1.2 2004/09/22 13:54:55 geaz Exp $
30  */

31
32 public class TestService extends BaseTest {
33
34   private XMLQueryingService xmlQueryingService;
35   private RepositoryService repositoryService;
36
37   public void setUp() throws Exception JavaDoc {
38     super.setUp();
39     try {
40       xmlQueryingService = (XMLQueryingService) PortalContainer.getInstance().
41           getComponentInstanceOfType(XMLQueryingService.class);
42       repositoryService = (RepositoryService) PortalContainer.getInstance().
43           getComponentInstanceOfType(RepositoryService.class);
44
45     } catch (Exception JavaDoc ex) {
46       ex.printStackTrace();
47     }
48   }
49
50
51   public void testManager() throws Exception JavaDoc {
52
53     RepositoryServiceConfig config = new DummyConfig();
54
55     PortalContainer manager = PortalContainer.getInstance();
56     assertEquals(PortalContainer.getInstance(), manager.getParent());
57
58     RepositoryImpl rep = (RepositoryImpl) manager.getComponentInstance("mock");
59     assertNotNull(rep);
60     assertNotNull(rep.getRepositoryManager());
61     assertNotNull(rep.getContainer("ws"));
62     assertEquals("mock",rep.getName());
63
64     rep = (RepositoryImpl) manager.getComponentInstance("fs1");
65     assertNotNull(rep);
66     assertNotNull(rep.getRepositoryManager());
67     assertNotNull(rep.getContainer("ws"));
68     assertEquals("fs1",rep.getName());
69   }
70
71   public void testXMLConfig() throws Exception JavaDoc {
72     String JavaDoc str = "<repositories-config><default-repository name=\"mock\"/><repositories><repository name=\"mock\" manager=\"inmemory\"><workspaces><workspace name=\"ws\" default=\"true\"/></workspaces></repository></repositories><containers><container name=\"c.mock\" class=\"org.exoplatform.services.jcr.impl.storage.inmemory.ContainerImpl\"><properties><property name=\"name\" value=\"value\"/></properties></container></containers><managers><manager name=\"inmemory\" class=\"org.exoplatform.services.jcr.impl.storage.inmemory.RepositoryManagerImpl\"/></managers></repositories-config>";
73     ByteArrayInputStream JavaDoc bis = new ByteArrayInputStream JavaDoc(str.getBytes());
74     RepositoryServiceConfig config = new XMLConfig(xmlQueryingService, bis);
75     assertNotNull(config.getRepositoryEntry("mock"));
76     assertTrue("config.getRepositoryEntries().length!=1", config.getRepositoryEntries().length == 1);
77     assertNotNull("c.mock is null", config.getContainerEntry("c.mock"));
78     assertEquals("org.exoplatform.services.jcr.impl.storage.inmemory.ContainerImpl",
79                   config.getContainerEntry("c.mock").getType().getName());
80     assertEquals("value",
81                  config.getContainerEntry("c.mock").getParameters().getProperty("name"));
82     assertTrue("config.getSupportedContainerEntries().length!=1", config.getSupportedContainerEntries().length == 1);
83     assertNotNull(config.getRepositoryManagerEntry("inmemory"));
84     assertTrue(config.getSupportedRepositoryManagerEntries().length == 1);
85     assertNotNull(config.getWorkspaceEntry("mock","ws"));
86     assertTrue(config.getWorkspaceEntries().length == 1);
87   }
88
89   public void testReadDefaultXMLConfig() throws Exception JavaDoc {
90     RepositoryServiceConfig config = new XMLConfig(xmlQueryingService);
91     assertNotNull(config);
92     assertTrue(config.getRepositoryEntries().length>0);
93     assertNotNull(config.getDefaultRepositoryName());
94     log.debug("DEF NAME "+config.getDefaultRepositoryName());
95
96
97   }
98
99   public void testDefaultRepository() throws Exception JavaDoc {
100     TicketImpl ticket = (TicketImpl)repositoryService.getRepository().login(null, "ws");
101     log.debug("CONTAINER "+ticket.getContainer().getName());
102   }
103
104   public void testPortalContainerRegistration() throws Exception JavaDoc {
105     PortalContainer manager = PortalContainer.getInstance();
106
107     RepositoryService service = (RepositoryService) manager.getComponentInstanceOfType(RepositoryService.class);
108     assertNotNull(service);
109     Repository rep = service.getRepository("mock");
110     assertNotNull("Repository(1) is Null", rep);
111
112     RepositoryServiceConfig config = (RepositoryServiceConfig) manager.getComponentInstanceOfType(RepositoryServiceConfig.class);
113     assertNotNull("Config is null", config);
114     ContainerEntry entry = config.getContainerEntry("c.inmemory");
115     assertNotNull("'c.inmemory' entry not found!", entry);
116
117     assertEquals(config, service.getConfig());
118     String JavaDoc containerName = entry.getType().getName();
119     assertEquals("org.exoplatform.services.jcr.impl.storage.inmemory.ContainerImpl", containerName);
120     assertNotNull(Class.forName(containerName));
121
122     rep = service.getRepository("mock");
123     assertNotNull("Repository(2) is Null", rep);
124
125   }
126
127 }
128
Popular Tags