This project has retired. For details please refer to its Attic page.
JAXRLocaleTest xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.ws.scout.registry;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.fail;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Iterator;
25  import java.util.Locale;
26  
27  import javax.xml.registry.BulkResponse;
28  import javax.xml.registry.BusinessLifeCycleManager;
29  import javax.xml.registry.BusinessQueryManager;
30  import javax.xml.registry.JAXRException;
31  import javax.xml.registry.JAXRResponse;
32  import javax.xml.registry.LifeCycleManager;
33  import javax.xml.registry.RegistryService;
34  import javax.xml.registry.infomodel.Concept;
35  import javax.xml.registry.infomodel.InternationalString;
36  import javax.xml.registry.infomodel.Key;
37  import javax.xml.registry.infomodel.Organization;
38  import javax.xml.registry.infomodel.Service;
39  
40  import junit.framework.JUnit4TestAdapter;
41  
42  import org.apache.ws.scout.BaseTestCase;
43  import org.junit.After;
44  import org.junit.Before;
45  import org.junit.Test;
46  
47  /**
48   */
49  public class JAXRLocaleTest extends BaseTestCase
50  {
51      private BusinessLifeCycleManager blm = null;
52  
53      @Before
54      public void setUp()
55      {
56         super.setUp();
57      }
58  
59      @After
60      public void tearDown()
61      {
62          super.tearDown();
63      }
64  
65      @Test
66      public void testPublishOrganizationAndService() throws Exception {
67          login();
68  
69          RegistryService rs = connection.getRegistryService();
70          BusinessQueryManager bqm = rs.getBusinessQueryManager();
71          blm = rs.getBusinessLifeCycleManager();
72  
73          InternationalString is;
74          BulkResponse br;
75          Key key;
76          Locale locale = Locale.GERMAN;
77  
78          // create Organization
79          
80          Organization organization = (Organization) blm.createObject(BusinessLifeCycleManager.ORGANIZATION);
81  
82          is = getIString(locale, "Apache Scout Org");
83          is.setValue(Locale.JAPANESE, "Apache Scoot Org");
84          organization.setName(is);
85          is = getIString(locale, "This is the org for Apache Scout Test");
86          is.setValue(Locale.JAPANESE, "This is the org for Apache Scout Test");
87          organization.setDescription(is);
88  
89          Collection<Organization> organizations = new ArrayList<Organization>();
90          organizations.add(organization);
91  
92          br = blm.saveOrganizations(organizations);
93          checkResponse(br);
94  
95          assertEquals(1, br.getCollection().size());
96          key = (Key) br.getCollection().iterator().next();
97  
98          Organization organization1 = (Organization) bqm.getRegistryObject(key.getId(), LifeCycleManager.ORGANIZATION);
99  
100         System.out.println(organization1.getName().getValue() + " " + organization1.getDescription().getValue());
101         
102         assertEquals(organization.getName().getValue(locale),
103                      organization1.getName().getValue(locale));
104         assertEquals(organization.getName().getValue(Locale.JAPANESE),
105                 organization1.getName().getValue(Locale.JAPANESE));
106         
107         assertEquals(organization.getDescription().getValue(locale), 
108                      organization1.getDescription().getValue(locale));
109         assertEquals(organization.getDescription().getValue(Locale.JAPANESE), 
110                 organization1.getDescription().getValue(Locale.JAPANESE));
111 
112         // create Service
113         Service service = (Service) blm.createObject(BusinessLifeCycleManager.SERVICE);
114 
115         is = getIString(locale, "Apache Scout Service");
116         is.setValue(Locale.JAPANESE, "Apache Scoot Service");
117         service.setName(is);
118         is = getIString(locale, "This is the service for Apache Scout Test");
119         is.setValue(Locale.JAPANESE, "This is the service for Apache Scoot Test");
120         service.setDescription(is);
121 
122         organization1.addService(service);
123         
124         Collection<Service> services = new ArrayList<Service>();
125         services.add(service);
126 
127         br = blm.saveServices(services);
128         checkResponse(br);
129 
130         assertEquals(1, br.getCollection().size());
131         key = (Key) br.getCollection().iterator().next();
132 
133         Service service1 = (Service) bqm.getRegistryObject(key.getId(), LifeCycleManager.SERVICE);
134 
135         System.out.println(service1.getName().getValue() + " " + service1.getDescription().getValue());
136         
137         assertEquals(service.getName().getValue(locale),
138                      service1.getName().getValue(locale));
139         assertEquals(service.getName().getValue(Locale.JAPANESE),
140         			service1.getName().getValue(Locale.JAPANESE));
141         
142         assertEquals(service.getDescription().getValue(locale), 
143                      service1.getDescription().getValue(locale));
144         
145         //Cleanup
146         Collection<Key> serviceKeys = new ArrayList<Key>();
147         serviceKeys.add(key);
148         blm.deleteServices(serviceKeys);
149         
150         Collection<Key> orgKeys = new ArrayList<Key>();
151         orgKeys.add(organization1.getKey());
152         blm.deleteOrganizations(orgKeys); 
153     }
154     
155     public void testPublishConcept() throws Exception {
156         login();
157 
158         RegistryService rs = connection.getRegistryService();
159         BusinessQueryManager bqm = rs.getBusinessQueryManager();
160         blm = rs.getBusinessLifeCycleManager();
161 
162         Locale locale = Locale.GERMAN;
163 
164         Concept concept = (Concept) blm.createObject(BusinessLifeCycleManager.CONCEPT);
165         InternationalString is;
166 
167         is = getIString(locale, "Apache Scout Concept -- APACHE SCOUT TEST");
168         concept.setName(is);
169         is = getIString(locale, "This is the concept for Apache Scout Test");
170         concept.setDescription(is);
171 
172         Collection<Concept> concepts = new ArrayList<Concept>();
173         concepts.add(concept);
174 
175         BulkResponse br = blm.saveConcepts(concepts);
176         checkResponse(br);
177 
178         assertEquals(1, br.getCollection().size());
179         Key key = (Key) br.getCollection().iterator().next();
180 
181         Concept concept1 = (Concept) bqm.getRegistryObject(key.getId(), LifeCycleManager.CONCEPT);
182 
183         System.out.println(concept1.getName().getValue() + " " + concept1.getDescription().getValue());
184 
185       
186         assertEquals(concept.getName().getValue(locale),
187                       concept1.getName().getValue(locale));         
188 
189         assertEquals(concept.getDescription().getValue(locale), 
190                      concept1.getDescription().getValue(locale));
191         
192         //cleanup
193         Collection<Key> conceptKeys = new ArrayList<Key>();
194         conceptKeys.add(concept1.getKey());
195         blm.deleteOrganizations(conceptKeys);
196     }
197 
198     private void checkResponse(BulkResponse br) throws JAXRException {
199         if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
200         {
201             System.out.println("Object saved.");
202             Collection coll = br.getCollection();
203             Iterator iter = coll.iterator();
204             while (iter.hasNext())
205             {
206                 Key key = (Key) iter.next();
207                 System.out.println("Saved Key=" + key.getId());
208             }//end while
209         } else
210         {
211             System.err.println("JAXRExceptions " +
212                     "occurred during save:");
213             Collection exceptions = br.getExceptions();
214             Iterator iter = exceptions.iterator();
215             while (iter.hasNext())
216             {
217                 Exception e = (Exception) iter.next();
218                 System.err.println(e.toString());
219                 fail(e.toString());
220             }
221         }
222     }
223 
224     private InternationalString getIString(Locale locale, String str)
225             throws JAXRException
226     {
227         return blm.createInternationalString(locale, str);
228     }
229     
230     public static junit.framework.Test suite() {
231         return new JUnit4TestAdapter(JAXRLocaleTest.class);
232     }
233 
234 }