This project has retired. For details please refer to its Attic page.
JAXR020ConceptTest 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.qa;
18  
19  import static org.junit.Assert.fail;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Iterator;
24  
25  import javax.xml.registry.BulkResponse;
26  import javax.xml.registry.BusinessQueryManager;
27  import javax.xml.registry.FindQualifier;
28  import javax.xml.registry.JAXRException;
29  import javax.xml.registry.JAXRResponse;
30  import javax.xml.registry.LifeCycleManager;
31  import javax.xml.registry.RegistryService;
32  import javax.xml.registry.infomodel.Classification;
33  import javax.xml.registry.infomodel.ClassificationScheme;
34  import javax.xml.registry.infomodel.Concept;
35  import javax.xml.registry.infomodel.ExternalLink;
36  import javax.xml.registry.infomodel.InternationalString;
37  import javax.xml.registry.infomodel.Key;
38  
39  import junit.framework.JUnit4TestAdapter;
40  
41  import org.apache.ws.scout.BaseTestCase;
42  import org.apache.ws.scout.Printer;
43  import org.apache.ws.scout.Remover;
44  import org.junit.After;
45  import org.junit.Before;
46  import org.junit.Test;
47  
48  /**
49   * Tests publish concepts.
50   * 
51   * Open source UDDI Browser  <http://www.uddibrowser.org>
52   * to check your results.
53   *
54   * Based on query/publish tests written by 
55   * <a href="mailto:anil@apache.org">Anil Saldhana</a>.
56   *
57   * @author <a href="mailto:dbhole@redhat.com">Deepak Bhole</a>
58   * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
59   * 
60   * @since Sep 27, 2005
61   */
62  public class JAXR020ConceptTest extends BaseTestCase
63  {
64      private static String CONCEPT_NAME = "Apache Scout Concept -- APACHE SCOUT TEST";
65      
66      @Before
67      public void setUp()
68      {
69         super.setUp();
70      }
71  
72      @After
73      public void tearDown()
74      {
75          super.tearDown();
76      }
77  
78      @Test
79      public void testPublishConcept()
80      {
81          login();
82          try
83          {
84              RegistryService rs = connection.getRegistryService();
85              BusinessQueryManager bqm = rs.getBusinessQueryManager();
86              blm = rs.getBusinessLifeCycleManager();
87             
88              Concept concept = blm.createConcept(null, CONCEPT_NAME, "");
89              InternationalString is = blm.createInternationalString("This is the concept for Apache Scout Test");
90              concept.setDescription(is);
91  
92              //Lets provide a link to juddi registry
93              ExternalLink wslink =
94                      blm.createExternalLink("http://to-rhaps4.toronto.redhat.com:9000/juddi",
95                              "juddi");
96              concept.addExternalLink(wslink);
97              Classification cl = createClassificationForUDDI(bqm);
98  
99              concept.addClassification(cl);
100 
101             Collection<Concept> concepts = new ArrayList<Concept>();
102             concepts.add(concept);
103 
104             Key key=null;
105             BulkResponse br = blm.saveConcepts(concepts);
106             if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
107             {
108                 System.out.println("Concept Saved");
109                 Collection coll = br.getCollection();
110                 Iterator iter = coll.iterator();
111                 while (iter.hasNext())
112                 {
113                     key = (Key) iter.next();
114                     System.out.println("Saved Key=" + key.getId());
115                 }//end while
116             } else
117             {
118                 System.err.println("JAXRExceptions " +
119                         "occurred during save:");
120                 Collection exceptions = br.getExceptions();
121                 Iterator iter = exceptions.iterator();
122                 while (iter.hasNext())
123                 {
124                     Exception e = (Exception) iter.next();
125                     System.err.println(e.toString());
126                     fail(e.toString());
127                 }
128             }
129             
130             Concept savedConcept = (Concept)bqm.getRegistryObject(key.getId(),LifeCycleManager.CONCEPT);
131             System.out.println("Save concept=" + savedConcept);
132             
133         } catch (JAXRException e)
134         {
135             e.printStackTrace();
136             fail(e.getMessage());
137         }
138     }
139 
140     private Classification createClassificationForUDDI(BusinessQueryManager bqm)
141             throws JAXRException
142     {
143         //Scheme which maps onto uddi tmodel
144         ClassificationScheme udditmodel = bqm.findClassificationSchemeByName(null, "uddi-org:types");
145 
146         Classification cl = blm.createClassification(udditmodel, "wsdl", "wsdl");
147         return cl;
148     }
149     
150     public void testDeleteConcept()
151     {
152         login();
153         try
154         {
155             RegistryService rs = connection.getRegistryService();
156             BusinessQueryManager bqm = rs.getBusinessQueryManager();
157             blm = rs.getBusinessLifeCycleManager();
158             Printerter.html#Printer">Printer printer = new Printer();
159             Removerver.html#Remover">Remover remover = new Remover(blm);
160 
161             Collection<String> findQualifiers = new ArrayList<String>();
162             findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
163             Collection<String> namePatterns = new ArrayList<String>();
164             namePatterns.add("%" + CONCEPT_NAME + "%");
165 
166             BulkResponse br = bqm.findConcepts(findQualifiers, namePatterns, null, null, null);
167 
168 //          check how many organisation we have matched
169             Collection concepts = br.getCollection();
170 
171             if (concepts == null)
172             {
173                 System.out.println("\n-- Matched 0 orgs");
174 
175             } else
176             {
177                 System.out.println("\n-- Matched " + concepts.size() + " concepts --\n");
178 
179                 // then step through them
180                 for (Iterator conceptIter = concepts.iterator(); conceptIter.hasNext();)
181                 {
182                     Concept c = (Concept) conceptIter.next();
183                     
184                     System.out.println("Id: " + c.getKey().getId());
185                     System.out.println("Name: " + c.getName().getValue());
186 
187                     // Links are not yet implemented in scout -- so concepts 
188                     // created via scout won't have links 
189                     printer.printExternalLinks(c);
190 
191                     // Print spacer between messages
192                     System.out.println(" --- ");
193                     
194                     remover.removeConcept(c);
195                     
196                     System.out.println(" === ");
197                 }
198             }//end else
199         } catch (JAXRException e)
200         {
201             e.printStackTrace();
202             fail(e.getMessage());
203         }
204     }
205     
206     public static junit.framework.Test suite() {
207         return new JUnit4TestAdapter(JAXR020ConceptTest.class);
208     }
209 
210 }