This project has retired. For details please refer to its Attic page.
API_170_CustodyTransferTest xref
View Javadoc
1   /*
2    * Copyright 2014 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.api.impl;
17  
18  import java.rmi.RemoteException;
19  import javax.xml.datatype.XMLGregorianCalendar;
20  import javax.xml.ws.Holder;
21  import org.apache.commons.configuration.ConfigurationException;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.juddi.Registry;
25  import org.apache.juddi.v3.tck.TckBusiness;
26  import org.apache.juddi.v3.tck.TckFindEntity;
27  import org.apache.juddi.v3.tck.TckPublisher;
28  import org.apache.juddi.v3.tck.TckSecurity;
29  import org.apache.juddi.v3.tck.TckTModel;
30  import org.junit.AfterClass;
31  import org.junit.Assert;
32  import org.junit.BeforeClass;
33  import org.junit.Test;
34  import org.uddi.api_v3.BusinessDetail;
35  import org.uddi.api_v3.GetBusinessDetail;
36  import org.uddi.api_v3.GetOperationalInfo;
37  import org.uddi.api_v3.OperationalInfos;
38  import org.uddi.custody_v3.KeyBag;
39  import org.uddi.custody_v3.TransferEntities;
40  import org.uddi.custody_v3.TransferToken;
41  import org.uddi.v3_service.UDDISecurityPortType;
42  
43  /**
44   *
45   * @author alex
46   */
47  public class API_170_CustodyTransferTest {
48          
49          private static Log logger = LogFactory.getLog(API_030_BusinessEntityTest.class);
50          private static API_010_PublisherTest api010 = new API_010_PublisherTest();
51          private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
52          private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
53          private static TckFindEntity tckFindEntity = new TckFindEntity(new UDDIInquiryImpl());
54          private static String authInfoMary = null;
55          private static String authInfoSam = null;
56  
57          @BeforeClass
58          public static void setup() throws ConfigurationException {
59                  Registry.start();
60                  logger.info("API_030_BusinessEntityTest");
61                  logger.debug("Getting auth token..");
62                  try {
63                          api010.saveJoePublisher();
64                          api010.saveSamSyndicator();
65                          UDDISecurityPortType security = new UDDISecurityImpl();
66                          authInfoMary = TckSecurity.getAuthToken(security, TckPublisher.getMaryPublisherId(), TckPublisher.getMaryPassword());
67                          authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
68                          String authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
69                          tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
70                          tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
71                          tckTModel.saveMaryPublisherTmodel(authInfoMary);
72                          tckTModel.saveSamSyndicatorTmodel(authInfoSam);
73                  } catch (RemoteException e) {
74                          logger.error(e.getMessage(), e);
75                          Assert.fail("Could not obtain authInfo token.");
76                  }
77          }
78  
79          @AfterClass
80          public static void stopRegistry() throws ConfigurationException {
81                  tckTModel.deleteCreatedTModels(authInfoMary);
82                  tckTModel.deleteCreatedTModels(authInfoSam);
83                  Registry.stop();
84          }
85  
86          
87          @Test
88          public void testTransfer() throws Exception{
89                   UDDIInquiryImpl inquire = new UDDIInquiryImpl();
90                   
91                   
92                  //save sam's business
93                  tckBusiness.saveSamSyndicatorBusiness(authInfoSam);
94                  
95                  //save mary's business
96                  tckBusiness.saveMaryPublisherBusiness(authInfoMary);
97                  
98                  GetOperationalInfo goi = new GetOperationalInfo();
99                  goi.getEntityKey().add(TckBusiness.SAM_BUSINESS_KEY);
100                 
101                 OperationalInfos operationalInfo = inquire.getOperationalInfo(goi);
102                 Assert.assertEquals(operationalInfo.getOperationalInfo().get(0).getAuthorizedName(), TckPublisher.getSamPublisherId());
103                 
104                 //sam wants to transfer to mary, get a token
105                 UDDICustodyTransferImpl custody = new UDDICustodyTransferImpl();
106                 KeyBag kb = new  KeyBag();
107                 kb.getKey().add(TckBusiness.SAM_BUSINESS_KEY);
108                 Holder<String> node = new Holder<String>();
109                 Holder<XMLGregorianCalendar> expires = new Holder<XMLGregorianCalendar>();
110                 Holder<byte[]> token = new Holder<byte[]>();
111                 custody.getTransferToken(authInfoSam,kb , node, expires, token);
112                 
113                 //use mary's account to accept and transfer
114                 TransferEntities te = new TransferEntities();
115                 te.setAuthInfo(authInfoMary);
116                 te.setKeyBag(kb);
117                 te.setTransferToken(new TransferToken());
118                 te.getTransferToken().setExpirationTime(expires.value);
119                 te.getTransferToken().setNodeID(node.value);
120                 te.getTransferToken().setOpaqueToken(token.value);
121                 custody.transferEntities(te);
122                 
123                
124               
125                 operationalInfo = inquire.getOperationalInfo(goi);
126                 
127                 Assert.assertEquals(operationalInfo.getOperationalInfo().get(0).getAuthorizedName(), TckPublisher.getMaryPublisherId());
128                 tckBusiness.deleteBusiness(authInfoMary, TckBusiness.SAM_BUSINESS_XML, TckBusiness.SAM_BUSINESS_KEY);
129                 tckBusiness.deleteBusiness(authInfoMary, TckBusiness.MARY_BUSINESS_XML, TckBusiness.MARY_BUSINESS_KEY);
130         }
131 }