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.JAXRException;
027: import javax.xml.registry.JAXRResponse;
028: import javax.xml.registry.RegistryService;
029: import javax.xml.registry.infomodel.Classification;
030: import javax.xml.registry.infomodel.ClassificationScheme;
031: import javax.xml.registry.infomodel.Key;
032:
033: import junit.framework.JUnit4TestAdapter;
034:
035: import org.apache.ws.scout.BaseTestCase;
036: import org.apache.ws.scout.Remover;
037: import org.junit.After;
038: import org.junit.Before;
039: import org.junit.Test;
040:
041: /**
042: * Tests publish classification schemes.
043: *
044: * Open source UDDI Browser <http://www.uddibrowser.org>
045: * to check your results.
046: *
047: * Based on query/publish tests written by
048: * <a href="mailto:anil@apache.org">Anil Saldhana</a>.
049: *
050: * @author <a href="mailto:dbhole@redhat.com">Deepak Bhole</a>
051: * @author <a href="mailto:anil@apache.org">Anil Saldhana</a>
052: * @author <a href="mailto:kstam@apache.org">Kurt Stam</a>
053: *
054: * @since Sep 27, 2005
055: */
056: public class JAXR005ClassificationSchemeTest extends BaseTestCase {
057: @Before
058: public void setUp() {
059: super .setUp();
060: }
061:
062: @After
063: public void tearDown() {
064: super .tearDown();
065: }
066:
067: @Test
068: public void testPublishClassificationScheme() {
069: login();
070: try {
071: RegistryService rs = connection.getRegistryService();
072: BusinessQueryManager bqm = rs.getBusinessQueryManager();
073: blm = rs.getBusinessLifeCycleManager();
074: Remover remover = new Remover(blm);
075:
076: ClassificationScheme cScheme = blm
077: .createClassificationScheme(
078: "testScheme -- APACHE SCOUT TEST",
079: "Sample Classification Scheme");
080: Classification classification = createClassificationForUDDI(bqm);
081: cScheme.addClassification(classification);
082:
083: ArrayList<ClassificationScheme> cSchemes = new ArrayList<ClassificationScheme>();
084: cSchemes.add(cScheme);
085:
086: BulkResponse br = blm.saveClassificationSchemes(cSchemes);
087: if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
088: System.out.println("Classification Saved");
089: Collection coll = br.getCollection();
090: Iterator iter = coll.iterator();
091: while (iter.hasNext()) {
092: Key key = (Key) iter.next();
093: System.out.println("Saved Key=" + key.getId());
094: cScheme.setKey(key);
095: remover.removeClassificationScheme(cScheme);
096: }//end while
097: } else {
098: System.err.println("JAXRExceptions "
099: + "occurred during save:");
100: Collection exceptions = br.getExceptions();
101: Iterator iter = exceptions.iterator();
102: while (iter.hasNext()) {
103: Exception e = (Exception) iter.next();
104: System.err.println(e.toString());
105: fail(e.toString());
106: }
107: }
108:
109: //Classificat
110: } catch (JAXRException e) {
111: e.printStackTrace();
112: fail(e.getMessage());
113: }
114: }
115:
116: private Classification createClassificationForUDDI(
117: BusinessQueryManager bqm) throws JAXRException {
118: //Scheme which maps onto uddi tmodel
119: ClassificationScheme udditmodel = bqm
120: .findClassificationSchemeByName(null, "uddi-org:types");
121:
122: Classification cl = blm.createClassification(udditmodel,
123: "wsdl", "wsdl");
124: return cl;
125: }
126:
127: public static junit.framework.Test suite() {
128: return new JUnit4TestAdapter(
129: JAXR005ClassificationSchemeTest.class);
130: }
131:
132: }
|