This project has retired. For details please refer to its Attic page.
UDDIClientTest 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.client;
16  
17  import static org.junit.Assert.assertEquals;
18  
19  import java.util.Map;
20  
21  import org.apache.juddi.v3.annotations.AnnotationProcessor;
22  import org.apache.juddi.v3.client.config.UDDIClerk;
23  import org.apache.juddi.v3.client.config.UDDIClient;
24  import org.apache.juddi.v3.client.transport.JAXWSv2TranslationTransport;
25  import org.apache.juddi.v3.client.transport.Transport;
26  import org.junit.Assert;
27  import org.junit.Test;
28  import org.uddi.api_v3.BusinessService;
29  
30  /**
31   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
32   */
33  public class UDDIClientTest {
34  
35          @Test
36          public void testReadingTheConfig() {
37                  try {
38                          UDDIClient client = new UDDIClient();
39                          client.start();
40                          client.getClientConfig().getUDDINode("default");
41                          assertEquals(3, client.getClientConfig().getUDDIClerks().size());
42                          Thread.sleep(500);
43                          client.stop();
44                  } catch (Exception e) {
45                          //we should not have any issues reading the config
46                          e.printStackTrace();
47                          Assert.fail();
48                  }
49          }
50  
51          @Test
52          public void testMultipleClientConfigFiles() {
53                  try {
54                          UDDIClient client = new UDDIClient("META-INF/uddi.xml");
55                          client.start();
56                          assertEquals("test-client", client.getName());
57  
58                          UDDIClient client2 = new UDDIClient("META-INF/uddi2.xml");
59                          client2.start();
60                          assertEquals("second-client", client2.getName());
61                          Thread.sleep(500);
62                          client.stop();
63                          client2.stop();
64  
65                  } catch (Exception e) {
66                          e.printStackTrace();
67                          Assert.fail("No exceptions are expected");
68                  }
69  
70          }
71  
72          @Test
73          public void testDefaultConfigFile() {
74                  try {
75                          UDDIClient client = new UDDIClient(null);
76                          //We're expecting the client defined in the META-INF/uddi.xml file.
77                          client.start();
78                          assertEquals("test-client", client.getName());
79                          Thread.sleep(500);
80                          client.stop();
81  
82                  } catch (Exception e) {
83                          e.printStackTrace();
84                          Assert.fail("No exceptions are expected");
85                  }
86  
87          }
88  
89          @Test
90          public void testDefaultManager() {
91                  try {
92                          //This is a special case where the client in the META-INF/uddi.xml file is 
93                          //instantiated and started simply by getting it.
94                          //This functionality was add for backwards compatibility. 
95                          UDDIClient client = new UDDIClient();
96                          client.start();
97                          assertEquals("test-client", client.getName());
98                          assertEquals("default", client.getClientConfig().getHomeNode().getName());
99                          Thread.sleep(500);
100                         client.stop();
101 
102                 } catch (Exception e) {
103                         e.printStackTrace();
104                         Assert.fail("No exceptions are expected");
105                 }
106 
107         }
108 
109         @Test
110         public void testReadingAnnotations() {
111                 try {
112                         UDDIClient client = new UDDIClient();
113                         Map<String, UDDIClerk> clerks = client.getClientConfig().getUDDIClerks();
114                         AnnotationProcessor ap = new AnnotationProcessor();
115                         if (clerks.containsKey("default")) {
116                                 UDDIClerk clerk = clerks.get("default");
117                                 BusinessService service = ap.readServiceAnnotations(
118                                         HelloWorldMockup.class.getName(), clerk.getUDDINode().getProperties());
119                                 assertEquals("uddi:juddi.apache.org:services-helloworld", service.getServiceKey());
120                         } else {
121                                 Assert.fail("Could not find expected clerk='default'");
122                         }
123                 } catch (Exception e) {
124                         //we should not have any issues reading the config
125                         e.printStackTrace();
126                         Assert.fail("No exceptions are expected");
127                 }
128 
129         }
130 
131         @Test
132         public void testReleaseVersion() {
133                 String v = Release.getjUDDIClientVersion();
134                 //Assert.assertNotSame(v, Release.UNKNOWN);
135                 //Apparently maven attaches the version info to the manifest after the tests are ran
136         }
137 
138         @Test
139         public void testDefaultManagerGetTransport() {
140                 try {
141                         //This is a special case where the client in the META-INF/uddi.xml file is 
142                         //instantiated and started simply by getting it.
143                         //This functionality was add for backwards compatibility. 
144                         UDDIClient client = new UDDIClient();
145                         client.start();
146                         assertEquals("test-client", client.getName());
147                         assertEquals("default", client.getClientConfig().getHomeNode().getName());
148                         Transport transport = client.getTransport("default");
149                         Assert.assertNotNull(transport);
150                         Assert.assertNotNull(transport.getJUDDIApiService());
151                         Assert.assertNotNull(transport.getUDDICustodyTransferService());
152                         Assert.assertNotNull(transport.getUDDIInquiryService());
153                         Assert.assertNotNull(transport.getUDDIPublishService());
154                         Assert.assertNotNull(transport.getUDDISecurityService());
155                         Assert.assertNotNull(transport.getUDDISubscriptionListenerService());
156                         Assert.assertNotNull(transport.getUDDISubscriptionService());
157 
158                         Thread.sleep(500);
159                         client.stop();
160 
161                 } catch (Exception e) {
162                         e.printStackTrace();
163                         Assert.fail("No exceptions are expected");
164                 }
165 
166         }
167 
168         /**
169          * gets UDDI v2 clients
170          *
171          * @throws Exception
172          */
173         @Test
174         public void getVersion2Clients() throws Exception {
175                 UDDIClient client = new UDDIClient("META-INF/uddiv2.xml");
176                 client.start();
177                 Transport transport = client.getTransport("default");
178                 Assert.assertNotNull(transport);
179                 Assert.assertEquals(transport.getClass().getCanonicalName(), JAXWSv2TranslationTransport.class.getCanonicalName());
180                 Assert.assertNotNull(transport.getUDDIInquiryService());
181                 Assert.assertNotNull(transport.getUDDIPublishService());
182                 Thread.sleep(500);
183                 client.stop();
184 
185         }
186 
187 }