This project has retired. For details please refer to its Attic page.
API_030_BusinessEntityTest xref
View Javadoc
1   /*
2    * Copyright 2001-2009 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    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.juddi.api.impl;
16  
17  import java.rmi.RemoteException;
18  import java.util.UUID;
19  
20  import org.apache.commons.configuration.ConfigurationException;
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  import org.apache.juddi.Registry;
24  import org.apache.juddi.auth.MockWebServiceContext;
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.BusinessEntity;
36  import org.uddi.api_v3.Name;
37  import org.uddi.api_v3.SaveBusiness;
38  import org.uddi.v3_service.UDDISecurityPortType;
39  
40  /**
41   * @author <a href="mailto:jfaath@apache.org">Jeff Faath</a>
42   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
43   * @author <a href="mailto:alexoree@apache.org">Alex O'Ree</a>
44   */
45  public class API_030_BusinessEntityTest {
46  
47          private static Log logger = LogFactory.getLog(API_030_BusinessEntityTest.class);
48          private static API_010_PublisherTest api010 = new API_010_PublisherTest();
49          private static TckTModel tckTModel = new TckTModel(new UDDIPublicationImpl(), new UDDIInquiryImpl());
50          private static TckBusiness tckBusiness = new TckBusiness(new UDDIPublicationImpl(), new UDDIInquiryImpl());
51          private static TckFindEntity tckFindEntity = new TckFindEntity(new UDDIInquiryImpl());
52          private static String authInfoJoe = null;
53          private static String authInfoSam = null;
54  
55          @BeforeClass
56          public static void setup() throws ConfigurationException {
57                  Registry.start();
58                  logger.info("API_030_BusinessEntityTest");
59                  logger.debug("Getting auth token..");
60                  try {
61                          api010.saveJoePublisher();
62                          api010.saveSamSyndicator();
63                          UDDISecurityPortType security = new UDDISecurityImpl();
64                          authInfoJoe = TckSecurity.getAuthToken(security, TckPublisher.getJoePublisherId(), TckPublisher.getJoePassword());
65                          authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
66                          String authInfoUDDI = TckSecurity.getAuthToken(security, TckPublisher.getUDDIPublisherId(), TckPublisher.getUDDIPassword());
67                          tckTModel.saveUDDIPublisherTmodel(authInfoUDDI);
68                          tckTModel.saveTModels(authInfoUDDI, TckTModel.TMODELS_XML);
69                  } catch (RemoteException e) {
70                          logger.error(e.getMessage(), e);
71                          Assert.fail("Could not obtain authInfo token.");
72                  }
73          }
74  
75          @AfterClass
76          public static void stopRegistry() throws ConfigurationException {
77                  tckTModel.deleteCreatedTModels(authInfoJoe);
78                  Registry.stop();
79          }
80  
81          @Test
82          public void testJoePublisherBusinessEntity() {
83                  try {
84                          tckTModel.saveJoePublisherTmodel(authInfoJoe);
85  
86                          tckBusiness.saveJoePublisherBusiness(authInfoJoe);
87                          tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
88                  } catch (Exception e) {
89                          e.printStackTrace();
90  
91                  } finally {
92                          tckTModel.deleteJoePublisherTmodel(authInfoJoe);
93                  }
94          }
95  
96          @Test
97          public void testSamSyndicatorBusiness() {
98                  try {
99                          tckTModel.saveSamSyndicatorTmodel(authInfoSam);
100                         tckBusiness.saveSamSyndicatorBusiness(authInfoSam);
101                         tckBusiness.deleteSamSyndicatorBusiness(authInfoSam);
102                 } finally {
103                         tckTModel.deleteSamSyndicatorTmodel(authInfoSam);
104                 }
105         }
106 
107         @Test
108         public void testJoePublisherBusinessEntitySignature() {
109                 try {
110                         tckTModel.saveJoePublisherTmodel(authInfoJoe);
111                         tckBusiness.saveJoePublisherBusinessX509Signature(authInfoJoe);
112                         tckFindEntity.findAllBusiness();
113                         tckTModel.saveSamSyndicatorTmodel(authInfoSam);
114                         tckBusiness.saveSamSyndicatorBusiness(authInfoSam);
115 
116                         //find the signed business
117                         tckFindEntity.findAllSignedBusiness();
118 
119                         tckBusiness.deleteSamSyndicatorBusiness(authInfoSam);
120                         tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
121 
122                 } finally {
123                         tckTModel.deleteJoePublisherTmodel(authInfoJoe);
124                         tckTModel.deleteSamSyndicatorTmodel(authInfoSam);
125                 }
126         }
127 
128         /**
129          * simulates a multinode registry via replication and attempts to save
130          * content that is owned by another node.
131          *
132          * @throws Exception
133          */
134         @Test
135         public void testJIRA727() throws Exception {
136                 UDDIPublicationImplExt pubRemoteNode = new UDDIPublicationImplExt(new MockWebServiceContext(null));
137                 UDDIPublicationImpl pubLocalNode = new UDDIPublicationImpl();
138                 UDDISecurityPortType security = new UDDISecurityImpl();
139                 authInfoSam = TckSecurity.getAuthToken(security, TckPublisher.getSamPublisherId(), TckPublisher.getSamPassword());
140                 SaveBusiness sb = new SaveBusiness();
141                 sb.setAuthInfo(authInfoSam);
142                 BusinessEntity be = new BusinessEntity();
143                 be.getName().add(new Name("testJIRA727", "en"));
144                 String node = "testJIRA727Node" + UUID.randomUUID().toString();
145                 sb.getBusinessEntity().add(be);
146                 BusinessDetail saveBusinessFudge = pubRemoteNode.saveBusinessFudge(sb, node);
147 
148                 sb = new SaveBusiness();
149                 sb.setAuthInfo(authInfoSam);
150                 sb.getBusinessEntity().add(saveBusinessFudge.getBusinessEntity().get(0));
151                 try {
152                         saveBusinessFudge = pubLocalNode.saveBusiness(sb);
153                         Assert.fail("unexpected success");
154                 } catch (Exception ex) {
155                         logger.warn(ex.getMessage());
156                         logger.debug(ex);
157                 }
158 
159         }
160 }