001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout.registry;
017:
018: import static org.junit.Assert.assertEquals;
019: import static org.junit.Assert.fail;
020:
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.Locale;
025:
026: import javax.xml.registry.BulkResponse;
027: import javax.xml.registry.BusinessLifeCycleManager;
028: import javax.xml.registry.BusinessQueryManager;
029: import javax.xml.registry.JAXRException;
030: import javax.xml.registry.JAXRResponse;
031: import javax.xml.registry.LifeCycleManager;
032: import javax.xml.registry.RegistryService;
033: import javax.xml.registry.infomodel.Concept;
034: import javax.xml.registry.infomodel.InternationalString;
035: import javax.xml.registry.infomodel.Key;
036: import javax.xml.registry.infomodel.Organization;
037: import javax.xml.registry.infomodel.Service;
038:
039: import junit.framework.JUnit4TestAdapter;
040:
041: import org.apache.ws.scout.BaseTestCase;
042: import org.junit.After;
043: import org.junit.Before;
044: import org.junit.Test;
045:
046: /**
047: */
048: public class JAXRLocaleTest extends BaseTestCase {
049: private BusinessLifeCycleManager blm = null;
050:
051: @Before
052: public void setUp() {
053: super .setUp();
054: }
055:
056: @After
057: public void tearDown() {
058: super .tearDown();
059: }
060:
061: @Test
062: public void testPublishOrganizationAndService() throws Exception {
063: login();
064:
065: RegistryService rs = connection.getRegistryService();
066: BusinessQueryManager bqm = rs.getBusinessQueryManager();
067: blm = rs.getBusinessLifeCycleManager();
068:
069: InternationalString is;
070: BulkResponse br;
071: Key key;
072: Locale locale = Locale.GERMAN;
073:
074: // create Organization
075:
076: Organization organization = (Organization) blm
077: .createObject(BusinessLifeCycleManager.ORGANIZATION);
078:
079: is = getIString(locale, "Apache Scout Org");
080: organization.setName(is);
081: is = getIString(locale, "This is the org for Apache Scout Test");
082: organization.setDescription(is);
083:
084: Collection<Organization> organizations = new ArrayList<Organization>();
085: organizations.add(organization);
086:
087: br = blm.saveOrganizations(organizations);
088: checkResponse(br);
089:
090: assertEquals(1, br.getCollection().size());
091: key = (Key) br.getCollection().iterator().next();
092:
093: Organization organization1 = (Organization) bqm
094: .getRegistryObject(key.getId(),
095: LifeCycleManager.ORGANIZATION);
096:
097: System.out.println(organization1.getName().getValue() + " "
098: + organization1.getDescription().getValue());
099:
100: assertEquals(organization.getName().getValue(locale),
101: organization1.getName().getValue(locale));
102:
103: assertEquals(organization.getDescription().getValue(locale),
104: organization1.getDescription().getValue(locale));
105:
106: // create Service
107: Service service = (Service) blm
108: .createObject(BusinessLifeCycleManager.SERVICE);
109:
110: is = getIString(locale, "Apache Scout Service");
111: service.setName(is);
112: is = getIString(locale,
113: "This is the service for Apache Scout Test");
114: service.setDescription(is);
115:
116: organization1.addService(service);
117:
118: Collection<Service> services = new ArrayList<Service>();
119: services.add(service);
120:
121: br = blm.saveServices(services);
122: checkResponse(br);
123:
124: assertEquals(1, br.getCollection().size());
125: key = (Key) br.getCollection().iterator().next();
126:
127: Service service1 = (Service) bqm.getRegistryObject(key.getId(),
128: LifeCycleManager.SERVICE);
129:
130: System.out.println(service1.getName().getValue() + " "
131: + service1.getDescription().getValue());
132:
133: assertEquals(service.getName().getValue(locale), service1
134: .getName().getValue(locale));
135:
136: assertEquals(service.getDescription().getValue(locale),
137: service1.getDescription().getValue(locale));
138:
139: //Cleanup
140: Collection<Key> serviceKeys = new ArrayList<Key>();
141: serviceKeys.add(key);
142: blm.deleteServices(serviceKeys);
143:
144: Collection<Key> orgKeys = new ArrayList<Key>();
145: orgKeys.add(organization1.getKey());
146: blm.deleteOrganizations(orgKeys);
147: }
148:
149: public void testPublishConcept() throws Exception {
150: login();
151:
152: RegistryService rs = connection.getRegistryService();
153: BusinessQueryManager bqm = rs.getBusinessQueryManager();
154: blm = rs.getBusinessLifeCycleManager();
155:
156: Locale locale = Locale.GERMAN;
157:
158: Concept concept = (Concept) blm
159: .createObject(BusinessLifeCycleManager.CONCEPT);
160: InternationalString is;
161:
162: is = getIString(locale,
163: "Apache Scout Concept -- APACHE SCOUT TEST");
164: concept.setName(is);
165: is = getIString(locale,
166: "This is the concept for Apache Scout Test");
167: concept.setDescription(is);
168:
169: Collection<Concept> concepts = new ArrayList<Concept>();
170: concepts.add(concept);
171:
172: BulkResponse br = blm.saveConcepts(concepts);
173: checkResponse(br);
174:
175: assertEquals(1, br.getCollection().size());
176: Key key = (Key) br.getCollection().iterator().next();
177:
178: Concept concept1 = (Concept) bqm.getRegistryObject(key.getId(),
179: LifeCycleManager.CONCEPT);
180:
181: System.out.println(concept1.getName().getValue() + " "
182: + concept1.getDescription().getValue());
183:
184: assertEquals(concept.getName().getValue(locale), concept1
185: .getName().getValue(locale));
186:
187: assertEquals(concept.getDescription().getValue(locale),
188: concept1.getDescription().getValue(locale));
189:
190: //cleanup
191: Collection<Key> conceptKeys = new ArrayList<Key>();
192: conceptKeys.add(concept1.getKey());
193: blm.deleteOrganizations(conceptKeys);
194: }
195:
196: private void checkResponse(BulkResponse br) throws JAXRException {
197: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
198: System.out.println("Object saved.");
199: Collection coll = br.getCollection();
200: Iterator iter = coll.iterator();
201: while (iter.hasNext()) {
202: Key key = (Key) iter.next();
203: System.out.println("Saved Key=" + key.getId());
204: }//end while
205: } else {
206: System.err.println("JAXRExceptions "
207: + "occurred during save:");
208: Collection exceptions = br.getExceptions();
209: Iterator iter = exceptions.iterator();
210: while (iter.hasNext()) {
211: Exception e = (Exception) iter.next();
212: System.err.println(e.toString());
213: fail(e.toString());
214: }
215: }
216: }
217:
218: private InternationalString getIString(Locale locale, String str)
219: throws JAXRException {
220: return blm.createInternationalString(locale, str);
221: }
222:
223: public static junit.framework.Test suite() {
224: return new JUnit4TestAdapter(JAXRLocaleTest.class);
225: }
226:
227: }
|