Package org.apache.juddi.handler

Source Code of org.apache.juddi.handler.SaveTModelHandlerTests

/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.juddi.handler;

import org.apache.juddi.datatype.CategoryBag;
import org.apache.juddi.datatype.Description;
import org.apache.juddi.datatype.IdentifierBag;
import org.apache.juddi.datatype.KeyedReference;
import org.apache.juddi.datatype.OverviewDoc;
import org.apache.juddi.datatype.RegistryObject;
import org.apache.juddi.datatype.UploadRegister;
import org.apache.juddi.datatype.request.AuthInfo;
import org.apache.juddi.datatype.request.SaveTModel;
import org.apache.juddi.datatype.tmodel.TModel;
import org.apache.juddi.util.xml.XMLUtils;
import org.w3c.dom.Element;

/**
* @author anou_mana@apache.org
*/
public class  SaveTModelHandlerTests extends HandlerTestCase
{
  private static final String TEST_ID = "juddi.handler.DeleteSaveTModel.test";
  private  SaveTModelHandler handler = null;

  public  SaveTModelHandlerTests(String arg0)
  {
    super(arg0);
  }

  public static void main(String[] args)
  {
    junit.textui.TestRunner.run( SaveTModelHandlerTests.class);
  }

  public void setUp()
  {
    HandlerMaker maker = HandlerMaker.getInstance();
    handler = ( SaveTModelHandler)maker.lookup( SaveTModelHandler.TAG_NAME);
  }

  private RegistryObject getRegistryObject()
  {
    AuthInfo authInfo = new AuthInfo();
    authInfo.setValue("6f157513-844e-4a95-a856-d257e6ba9726");

    OverviewDoc overDoc = new OverviewDoc();
    overDoc.setOverviewURL("http://www.juddi.org/service.html");
    overDoc.addDescription(new Description("over-doc Descr"));
    overDoc.addDescription(new Description("over-doc Descr Two","en"));

    CategoryBag catBag = new CategoryBag();
    catBag.addKeyedReference(new KeyedReference("catBagKeyName","catBagKeyValue"));
    catBag.addKeyedReference(new KeyedReference("uuid:dfddb58c-4853-4a71-865c-f84509017cc7","catBagKeyName2","catBagKeyValue2"));

    IdentifierBag idBag = new IdentifierBag();
    idBag.addKeyedReference(new KeyedReference("idBagKeyName","idBagkeyValue"));
    idBag.addKeyedReference(new KeyedReference("uuid:f78a135a-4769-4e79-8604-54d440314bc0","idBagKeyName2","idBagkeyValue2"));

    TModel tModel = new TModel();
    tModel.setTModelKey("uuid:269855db-62eb-4862-8e5a-1b06f2753038");
    tModel.setOperator("jUDDI");
    tModel.setAuthorizedName("Guest");
    tModel.setName("jUDDI TModel");
    tModel.addDescription(new Description("tModel whatever"));
    tModel.addDescription(new Description("tModel whatever too","fr"));
    tModel.setCategoryBag(catBag);
    tModel.setIdentifierBag(idBag);
    tModel.setOverviewDoc(overDoc);

    SaveTModel object = new SaveTModel();
    object.setAuthInfo(authInfo);
    object.addTModel(tModel);
    object.addTModel(tModel);
    object.addUploadRegister(new UploadRegister("http://www.juddi.org/businessEntity.xml"));
    object.addUploadRegister(new UploadRegister("http://www.sourceforge.net/businessService.xml"));
    object.addUploadRegister(new UploadRegister("http://www.uddi.org/bindingTemplate.xml"));

    return object;

  }

  private Element getMarshalledElement(RegistryObject regObject)
  {
    Element parent = XMLUtils.newRootElement();
    Element child = null;

    if(regObject == null)
      regObject = this.getRegistryObject();

    handler.marshal(regObject,parent);
    child = (Element)parent.getFirstChild();
    parent.removeChild(child);

    return child;
  }

  public void testMarshal()
  {
    Element child = getMarshalledElement(null);

    String marshalledString = this.getXMLString(child);

    assertNotNull("Marshalled  SaveTModel ", marshalledString);

  }

  public void testUnMarshal()
  {

    Element child = getMarshalledElement(null);
    RegistryObject regObject = handler.unmarshal(child);

    assertNotNull("UnMarshalled  SaveTModel ", regObject);

  }

  public void testMarshUnMarshal()
  {
    Element child = getMarshalledElement(null);

    String marshalledString = this.getXMLString(child);

    assertNotNull("Marshalled  SaveTModel ", marshalledString);

    RegistryObject regObject = handler.unmarshal(child);

    child = getMarshalledElement(regObject);

    String unMarshalledString = this.getXMLString(child);

    assertNotNull("Unmarshalled  SaveTModel ", unMarshalledString);

    boolean equals = marshalledString.equals(unMarshalledString);

    assertEquals("Expected SaveTModel: ", marshalledString, unMarshalledString );
  }

}
TOP

Related Classes of org.apache.juddi.handler.SaveTModelHandlerTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.