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.qa;
017:
018: import static org.junit.Assert.fail;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Iterator;
023:
024: import javax.xml.registry.BulkResponse;
025: import javax.xml.registry.BusinessQueryManager;
026: import javax.xml.registry.FindQualifier;
027: import javax.xml.registry.JAXRException;
028: import javax.xml.registry.JAXRResponse;
029: import javax.xml.registry.LifeCycleManager;
030: import javax.xml.registry.RegistryService;
031: import javax.xml.registry.infomodel.Classification;
032: import javax.xml.registry.infomodel.ClassificationScheme;
033: import javax.xml.registry.infomodel.Concept;
034: import javax.xml.registry.infomodel.ExternalLink;
035: import javax.xml.registry.infomodel.InternationalString;
036: import javax.xml.registry.infomodel.Key;
037:
038: import junit.framework.JUnit4TestAdapter;
039:
040: import org.apache.ws.scout.BaseTestCase;
041: import org.apache.ws.scout.Printer;
042: import org.apache.ws.scout.Remover;
043: import org.junit.After;
044: import org.junit.Before;
045: import org.junit.Test;
046:
047: /**
048: * Tests publish concepts.
049: *
050: * Open source UDDI Browser <http://www.uddibrowser.org>
051: * to check your results.
052: *
053: * Based on query/publish tests written by
054: * <a href="mailto:anil@apache.org">Anil Saldhana</a>.
055: *
056: * @author <a href="mailto:dbhole@redhat.com">Deepak Bhole</a>
057: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
058: *
059: * @since Sep 27, 2005
060: */
061: public class JAXR020ConceptTest extends BaseTestCase {
062: private static String CONCEPT_NAME = "Apache Scout Concept -- APACHE SCOUT TEST";
063:
064: @Before
065: public void setUp() {
066: super .setUp();
067: }
068:
069: @After
070: public void tearDown() {
071: super .tearDown();
072: }
073:
074: @Test
075: public void testPublishConcept() {
076: login();
077: try {
078: RegistryService rs = connection.getRegistryService();
079: BusinessQueryManager bqm = rs.getBusinessQueryManager();
080: blm = rs.getBusinessLifeCycleManager();
081:
082: Concept concept = blm.createConcept(null, CONCEPT_NAME, "");
083: InternationalString is = blm
084: .createInternationalString("This is the concept for Apache Scout Test");
085: concept.setDescription(is);
086:
087: //Lets provide a link to juddi registry
088: ExternalLink wslink = blm.createExternalLink(
089: "http://to-rhaps4.toronto.redhat.com:9000/juddi",
090: "juddi");
091: concept.addExternalLink(wslink);
092: Classification cl = createClassificationForUDDI(bqm);
093:
094: concept.addClassification(cl);
095:
096: Collection<Concept> concepts = new ArrayList<Concept>();
097: concepts.add(concept);
098:
099: Key key = null;
100: BulkResponse br = blm.saveConcepts(concepts);
101: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
102: System.out.println("Concept Saved");
103: Collection coll = br.getCollection();
104: Iterator iter = coll.iterator();
105: while (iter.hasNext()) {
106: key = (Key) iter.next();
107: System.out.println("Saved Key=" + key.getId());
108: }//end while
109: } else {
110: System.err.println("JAXRExceptions "
111: + "occurred during save:");
112: Collection exceptions = br.getExceptions();
113: Iterator iter = exceptions.iterator();
114: while (iter.hasNext()) {
115: Exception e = (Exception) iter.next();
116: System.err.println(e.toString());
117: fail(e.toString());
118: }
119: }
120:
121: Concept savedConcept = (Concept) bqm.getRegistryObject(key
122: .getId(), LifeCycleManager.CONCEPT);
123: System.out.println("Save concept=" + savedConcept);
124:
125: } catch (JAXRException e) {
126: e.printStackTrace();
127: fail(e.getMessage());
128: }
129: }
130:
131: private Classification createClassificationForUDDI(
132: BusinessQueryManager bqm) throws JAXRException {
133: //Scheme which maps onto uddi tmodel
134: ClassificationScheme udditmodel = bqm
135: .findClassificationSchemeByName(null, "uddi-org:types");
136:
137: Classification cl = blm.createClassification(udditmodel,
138: "wsdl", "wsdl");
139: return cl;
140: }
141:
142: public void testDeleteConcept() {
143: login();
144: try {
145: RegistryService rs = connection.getRegistryService();
146: BusinessQueryManager bqm = rs.getBusinessQueryManager();
147: blm = rs.getBusinessLifeCycleManager();
148: Printer printer = new Printer();
149: Remover remover = new Remover(blm);
150:
151: Collection<String> findQualifiers = new ArrayList<String>();
152: findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
153: Collection<String> namePatterns = new ArrayList<String>();
154: namePatterns.add("%" + CONCEPT_NAME + "%");
155:
156: BulkResponse br = bqm.findConcepts(findQualifiers,
157: namePatterns, null, null, null);
158:
159: // check how many organisation we have matched
160: Collection concepts = br.getCollection();
161:
162: if (concepts == null) {
163: System.out.println("\n-- Matched 0 orgs");
164:
165: } else {
166: System.out.println("\n-- Matched " + concepts.size()
167: + " concepts --\n");
168:
169: // then step through them
170: for (Iterator conceptIter = concepts.iterator(); conceptIter
171: .hasNext();) {
172: Concept c = (Concept) conceptIter.next();
173:
174: System.out.println("Id: " + c.getKey().getId());
175: System.out.println("Name: "
176: + c.getName().getValue());
177:
178: // Links are not yet implemented in scout -- so concepts
179: // created via scout won't have links
180: printer.printExternalLinks(c);
181:
182: // Print spacer between messages
183: System.out.println(" --- ");
184:
185: remover.removeConcept(c);
186:
187: System.out.println(" === ");
188: }
189: }//end else
190: } catch (JAXRException e) {
191: e.printStackTrace();
192: fail(e.getMessage());
193: }
194: }
195:
196: public static junit.framework.Test suite() {
197: return new JUnit4TestAdapter(JAXR020ConceptTest.class);
198: }
199:
200: }
|