This project has retired. For details please refer to its Attic page.
JUDDI_100_ClientSubscriptionInfoIntegrationTest 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.v3.tck;
16  
17  import javax.xml.ws.BindingProvider;
18  import org.apache.commons.configuration.ConfigurationException;
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.apache.juddi.api_v3.Clerk;
22  import org.apache.juddi.api_v3.ClientSubscriptionInfo;
23  import org.apache.juddi.api_v3.ClientSubscriptionInfoDetail;
24  import org.apache.juddi.api_v3.DeleteClientSubscriptionInfo;
25  import org.apache.juddi.api_v3.Node;
26  import org.apache.juddi.api_v3.SaveClerk;
27  import org.apache.juddi.api_v3.SaveClientSubscriptionInfo;
28  import org.apache.juddi.api_v3.SaveNode;
29  import org.apache.juddi.v3.client.config.UDDIClient;
30  import org.apache.juddi.v3.client.transport.Transport;
31  import org.apache.juddi.v3_service.JUDDIApiPortType;
32  import org.junit.AfterClass;
33  import org.junit.Assert;
34  import org.junit.Assume;
35  import org.junit.BeforeClass;
36  import org.junit.Test;
37  import org.uddi.v3_service.UDDISecurityPortType;
38  
39  /**
40   * jUDDI specific tests
41   *
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 JUDDI_100_ClientSubscriptionInfoIntegrationTest {
46  
47          private static UDDISecurityPortType security = null;
48          private static JUDDIApiPortType publisher = null;
49          private static Log logger = LogFactory.getLog(JUDDI_100_ClientSubscriptionInfoIntegrationTest.class);
50          private static String authInfo = null;
51          private static UDDIClient manager;
52  
53          @BeforeClass
54          public static void startRegistry() throws ConfigurationException {
55                  if (!TckPublisher.isEnabled()) return;
56                  manager = new UDDIClient();
57                  manager.start();
58  
59  
60                  logger.debug("Getting auth tokens..");
61                  try {
62                          Transport transport = manager.getTransport("uddiv3");
63  
64                          security = transport.getUDDISecurityService();
65                          authInfo = TckSecurity.getAuthToken(security, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
66  
67                          publisher = transport.getJUDDIApiService();
68                          if (!TckPublisher.isUDDIAuthMode()) {
69                                  TckSecurity.setCredentials((BindingProvider) publisher, TckPublisher.getRootPublisherId(), TckPublisher.getRootPassword());
70                          }
71                  } catch (Exception e) {
72                          logger.error(e.getMessage(), e);
73                          Assert.fail("Could not obtain authInfo token.");
74                  }
75                  JUDDI_300_MultiNodeIntegrationTest.testSetupReplicationConfig();
76          }
77  
78          @AfterClass
79          public static void stopRegistry() throws ConfigurationException {
80                  manager.stop();
81          }
82  
83          @Test
84          public void addClientSubscriptionInfo() throws Exception {
85                  if (!TckPublisher.isEnabled()) return;
86               Assume.assumeTrue(TckPublisher.isJUDDI());
87  
88                  ClientSubscriptionInfo clientSubscriptionInfo = new ClientSubscriptionInfo();
89  
90                  Node node = new Node();
91                  node.setSecurityUrl("http://localhost:8080/services");
92                  node.setCustodyTransferUrl("http://localhost:8080/services");
93                  node.setDescription("TEST");
94                  node.setInquiryUrl("http://localhost:8080/services");
95                  node.setPublishUrl("http://localhost:8080/services");
96                  node.setSubscriptionListenerUrl("http://localhost:8080/services");
97                  node.setSubscriptionUrl("http://localhost:8080/services");
98                  node.setProxyTransport(org.apache.juddi.v3.client.transport.JAXWSTransport.class.getCanonicalName());
99                  
100                 node.setName("addClientSubscriptionInfoNode");
101                 node.setClientName("addClientSubscriptionInfoNode");
102 
103                 Clerk clerk = new Clerk();
104                 clerk.setName("addClientSubscriptionInfoClerk");
105                 clerk.setPublisher("root");
106                 clerk.setNode(node);
107 
108                 Clerk toClerk = new Clerk();
109                 toClerk.setName("addClientSubscriptionInfoClerk2");
110                 toClerk.setPublisher("root");
111                 toClerk.setNode(node);
112 
113                 clientSubscriptionInfo.setFromClerk(clerk);
114                 clientSubscriptionInfo.setToClerk(toClerk);
115 
116                 clientSubscriptionInfo.setSubscriptionKey("mykey");
117 
118                 SaveClientSubscriptionInfo saveClientSubscriptionInfo = new SaveClientSubscriptionInfo();
119                 saveClientSubscriptionInfo.setAuthInfo(authInfo);
120                 saveClientSubscriptionInfo.getClientSubscriptionInfo().add(clientSubscriptionInfo);
121 
122                 try {
123                         SaveNode sni = new SaveNode();
124                         sni.setAuthInfo(authInfo);
125                         sni.getNode().add(node);
126                         publisher.saveNode(sni);
127                         
128                         saveClerk(clerk);
129                         saveClerk(toClerk);
130                         ClientSubscriptionInfoDetail detail = publisher.saveClientSubscriptionInfo(saveClientSubscriptionInfo);
131 
132                         Assert.assertEquals("mykey", detail.getClientSubscriptionInfo().get(0).getSubscriptionKey());
133 
134                         DeleteClientSubscriptionInfo deleteInfo = new DeleteClientSubscriptionInfo();
135                         deleteInfo.setAuthInfo(authInfo);
136                         deleteInfo.getSubscriptionKey().add("mykey");
137                         publisher.deleteClientSubscriptionInfo(deleteInfo);
138 
139                 } catch (Exception e) {
140                         logger.error(e.getMessage(), e);
141                         Assert.fail("No exception should be thrown");
142                 } 
143         }
144 
145         
146 
147         private Clerk saveClerk(Clerk clerk) throws Exception {
148                 SaveClerk saveClerkInfo = new SaveClerk();
149                 saveClerkInfo.setAuthInfo(authInfo);
150 
151                 saveClerkInfo.getClerk().add(clerk);
152                 return publisher.saveClerk(saveClerkInfo).getClerk().get(0);
153         }
154 }