1 /* 2 * ==================================================================== 3 * 4 * This code is subject to the freebxml License, Version 1.1 5 * 6 * Copyright (c) 2003 freebxml.org. All rights reserved. 7 * 8 * ==================================================================== 9 */ 10 11 package com.sun.xml.registry.ebxml; 12 13 import java.util.ArrayList; 14 import java.util.Collection; 15 import java.util.Iterator; 16 import java.util.Locale; 17 import javax.xml.registry.BulkResponse; 18 import javax.xml.registry.Query; 19 import javax.xml.registry.infomodel.InternationalString; 20 import javax.xml.registry.infomodel.LocalizedString; 21 import javax.xml.registry.infomodel.RegistryObject; 22 import javax.xml.registry.infomodel.RegistryPackage; 23 import junit.framework.*; 24 25 /*** 26 * A jUnit TestCase to test the ebxmlrr provider I18N issues. 27 * Uses a RegistryPackage as test material. 28 * 29 * @author Diego Ballve 30 */ 31 public class I18NTest extends TestCase { 32 33 static ApelonJAXRTestSetup setup = null; 34 35 /*** The UUID for the temporary test object */ 36 private static String testPackageUUID = null; 37 38 // The localized names to be tested 39 static final String intlNames[] = {"testPackageUS", 40 "testPackUK" , 41 "testPacagéé", 42 "testiPäkägö"}; 43 44 // The locales to be tested 45 static final String locales[][] = {{"en","us"}, 46 {"en","uk"}, 47 {"fr", null}, 48 {"fi", null}}; 49 50 51 public I18NTest(java.lang.String testName) { 52 super(testName); 53 } 54 55 public static void main(java.lang.String[] args) { 56 try { 57 junit.textui.TestRunner.run(suite()); 58 } catch (Throwable t) { 59 System.out.println("Throwable: " + t.getClass().getName() 60 + " Message: " + t.getMessage()); 61 t.printStackTrace(); 62 } 63 } 64 65 public static Test suite() throws Exception { 66 TestSuite suite = new TestSuite(I18NTest.class); 67 setup = new ApelonJAXRTestSetup(suite); 68 return setup; 69 } 70 71 // test methods 72 73 // 74 public void testAddInternationalStringPackage() throws Exception { 75 RegistryPackage pkg; 76 InternationalString names; 77 78 if (locales[0][1] == null) { 79 names = setup.lcm.createInternationalString( 80 new Locale(locales[0][0]), intlNames[0]); 81 } else { 82 names = setup.lcm.createInternationalString( 83 new Locale(locales[0][0], locales[0][1]), intlNames[0]); 84 } 85 86 for (int i = 1; i < locales.length; i++) { 87 if (locales[i][1] == null) { 88 names.addLocalizedString(setup.lcm.createLocalizedString( 89 new Locale(locales[i][0]), intlNames[i])); 90 } else { 91 names.addLocalizedString(setup.lcm.createLocalizedString( 92 new Locale(locales[i][0], locales[i][1]), intlNames[i])); 93 } 94 } 95 96 pkg = setup.lcm.createRegistryPackage(names); 97 98 pkg.setDescription(setup.lcm.createInternationalString("testPackage description")); 99 ArrayList al = new ArrayList(); 100 al.add(pkg); 101 System.err.println("\nSaving 1 RegistryPackage"); 102 BulkResponse br = setup.lcm.saveObjects(al); 103 assertTrue("testPackage creation Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 104 testPackageUUID = pkg.getKey().getId(); 105 } 106 107 public void testAddedLocales() throws Exception { 108 RegistryPackage pkg = null; 109 try { 110 pkg = (RegistryPackage)setup.bqm.getRegistryObject(testPackageUUID); 111 } catch (ClassCastException c) { 112 fail("RegistryObject for UUID '" + testPackageUUID + "' is not a RegistryPackage"); 113 } 114 if(pkg == null) { 115 fail("RegistryObject for UUID '" + testPackageUUID + "' doesn't exists in the registry"); 116 } else { 117 for (int i = 0; i < locales.length; i++) { 118 if (locales[i][1] == null) { 119 assertNotNull("Missing locale '" + locales[i][0] + "'!", 120 pkg.getName().getValue(new Locale(locales[i][0]))); 121 } else { 122 assertNotNull("Missing locale '" + locales[i][0] + "-" + locales[i][1] + "'!", 123 pkg.getName().getValue(new Locale(locales[i][0], locales[i][1]))); 124 } 125 } 126 } 127 } 128 129 public void testAddedIntlNames() throws Exception { 130 RegistryPackage pkg = null; 131 try { 132 pkg = (RegistryPackage)setup.bqm.getRegistryObject(testPackageUUID); 133 } catch (ClassCastException c) { 134 fail("RegistryObject for UUID '" + testPackageUUID + "' is not a RegistryPackage"); 135 } 136 if(pkg == null) { 137 fail("RegistryObject for UUID '" + testPackageUUID + "' doesn't exists in the registry"); 138 } else { 139 for (int i = 0; i < locales.length; i++) { 140 String value; 141 if (locales[i][1] == null) { 142 value = pkg.getName().getValue(new Locale(locales[i][0])); 143 } else { 144 value = pkg.getName().getValue(new Locale(locales[i][0], locales[i][1])); 145 } 146 assertTrue("Strings (encoding) messed up. Should be '" + intlNames[i] + "': " + value, 147 value.equals(intlNames[i])); 148 } 149 } 150 } 151 152 public void testRemoveInternationalStringPackage() throws Exception { 153 RegistryPackage pkg = null; 154 try { 155 pkg = (RegistryPackage)setup.bqm.getRegistryObject(testPackageUUID); 156 } catch (ClassCastException c) { 157 fail("RegistryObject for UUID '" + testPackageUUID + "' is not a RegistryPackage"); 158 } 159 if(pkg == null) { 160 fail("RegistryObject for UUID '" + testPackageUUID + "' doesn't exists in the registry"); 161 } else { 162 ArrayList keys = new ArrayList(1); 163 keys.add(pkg.getKey()); 164 BulkResponse br = setup.lcm.deleteObjects(keys); 165 assertTrue("testPackage removal Failed", br.getStatus() == BulkResponse.STATUS_SUCCESS); 166 } 167 } 168 169 /*** 170 * Utility method to lookup registry object based on name and type 171 */ 172 public RegistryObject findRegistryObject(String roName, String roType) 173 throws Exception 174 { 175 RegistryObject retVal = null; 176 177 String query = "select * from registryobject, name_ where id = parent and name_.value = '" + roName + "'" + 178 " and objecttype = '" + roType + "'"; 179 180 Query q = setup.dqm.createQuery(Query.QUERY_TYPE_SQL, query); 181 BulkResponse br = setup.dqm.executeQuery(q); 182 if(br.getStatus() == BulkResponse.STATUS_SUCCESS) 183 { 184 Collection c = br.getCollection(); 185 Iterator it = c.iterator(); 186 if(it.hasNext()) 187 retVal = (RegistryObject)it.next(); 188 } 189 else 190 { 191 throw new Exception("findRegistryObject Failed!"); 192 } 193 194 return retVal; 195 } 196 197 }

This page was automatically generated by Maven