1 5 package org.exoplatform.services.resources.test; 6 7 import java.util.* ; 8 import org.exoplatform.container.PortalContainer; 9 import org.exoplatform.services.database.HibernateService; 10 import org.exoplatform.services.log.LogService; 11 import org.exoplatform.services.log.LogUtil; 12 import org.exoplatform.services.resources.*; 13 import org.exoplatform.test.BasicTestCase; 14 21 public class TestResourceBundleService extends BasicTestCase { 22 final static private String PROPERTIES = "language=en\nproperty=property" ; 23 final static private String PROPERTIES_FR = "language=fr" ; 24 final static private String PROPERTIES_FR_UPDATE= "language=fr\nproperty=fr-property" ; 25 26 private ResourceBundleService service_ ; 27 28 public TestResourceBundleService(String name) { 29 super(name); 30 } 31 32 public void setUp() throws Exception { 33 PortalContainer manager = PortalContainer.getInstance(); 34 service_ = (ResourceBundleService) manager.getComponentInstanceOfType(ResourceBundleService.class) ; 35 LogUtil.setLevel("org.exoplatform.services.resources", LogService.DEBUG, true) ; 36 LogUtil.setLevel("org.exoplatform.services.database", LogService.DEBUG, true) ; 37 } 38 39 public void tearDown() throws Exception { 40 PortalContainer manager = PortalContainer.getInstance(); 41 HibernateService hservice = 42 (HibernateService) manager.getComponentInstanceOfType(HibernateService.class) ; 43 hservice.closeSession(); 44 } 45 46 public void testResourceBundleService() throws Exception { 47 ResourceBundle res = 48 service_.getResourceBundle("locale.test.resources.test", Locale.ENGLISH) ; 49 assertTrue("Expect to find the ResourceBundle", res != null); 50 res = service_.getResourceBundle("locale.test.resources.test", Locale.FRANCE) ; 51 assertTrue("Expect to find the ResourceBundle", res != null); 52 assertEquals("Expect the french resource bundle", "French", res.getString("language")); 53 54 ResourceBundleData data = service_.createResourceBundleDataInstance(); 55 data.setName("locale.test"); data.setData(PROPERTIES); 56 service_.saveResourceBundle(data) ; 57 data = service_.createResourceBundleDataInstance(); 58 data.setName("locale.test"); 59 data.setLanguage(Locale.FRANCE.getLanguage()); 60 data.setData(PROPERTIES_FR); 61 service_.saveResourceBundle(data) ; 62 63 res = service_.getResourceBundle("locale.test", Locale.ENGLISH) ; 64 assertTrue("Expect to find the ResourceBundle", res != null); 65 66 res = service_.getResourceBundle("locale.test", Locale.FRANCE) ; 67 assertTrue("Expect to find the ResourceBundle", res != null); 68 assertEquals("Expect French locale bundle", "fr", res.getString("language")); 69 assertEquals("Expect French locale bundle", "property", res.getString("property")); 70 71 data.setData(PROPERTIES_FR_UPDATE); 72 service_.saveResourceBundle(data) ; 73 res = service_.getResourceBundle("locale.test", Locale.FRANCE) ; 74 assertEquals("Expect French locale bundle", "fr-property", res.getString("property")); 75 76 77 Query q = new Query(null, null) ; 78 List l = service_.findResourceDescriptions(q).getAll() ; 79 for(int i = 0; i < l.size() ; i ++) { 80 ResourceBundleDescription impl = (ResourceBundleDescription)l.get(i); 81 System.out.println("====> " + impl.getId()) ; 82 } 83 assertTrue("Expect at least 4 locale properties resources", l.size() >= 4); 84 85 int sizeBeforeRemove = l.size() ; 86 data = service_.getResourceBundleData(data.getId()); 87 service_.removeResourceBundleData(data.getId()); 88 l = service_.findResourceDescriptions(q).getAll() ; 89 assertEquals("Expect 2 locale properties resources", sizeBeforeRemove - 1 , l.size()); 90 } 91 92 protected String getDescription() { 93 return "Test Resource Bundle Service" ; 94 } 95 } | Popular Tags |