This project has retired. For details please refer to its Attic page.
ServiceLocatorTest 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.mapping;
16  
17  import java.net.URL;
18  import java.util.ArrayList;
19  import java.util.List;
20  import java.util.Properties;
21  import java.util.UUID;
22  import org.apache.commons.configuration.ConfigurationException;
23  import org.apache.juddi.v3.client.config.UDDIClient;
24  
25  import org.junit.Assert;
26  import org.junit.Ignore;
27  import org.junit.Test;
28  
29  /**
30   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
31   */
32  public class ServiceLocatorTest {
33  	
34  	@Test @Ignore
35  	public void testRoundRobin() {
36  		try {
37  			List<String> eprs = new ArrayList<String>();
38  			eprs.add("epr1");
39  			eprs.add("epr2");
40  			eprs.add("epr3");
41  			
42  			
43  			Properties properties = new Properties();
44  			ServiceLocator locator = new ServiceLocator(null, new URLLocalizerDefaultImpl(), properties);
45  			System.out.println(locator);
46  			locator.shutdown();
47  		} catch (Exception e) {
48  			e.printStackTrace();
49  			Assert.fail(e.getMessage());
50  			
51  		}
52  		
53  	}
54  
55      @Test
56      public void testJUDDI_939() throws Exception {
57              UDDIClient uddiClient = new UDDIClient();
58              ServiceLocator serviceLocator = uddiClient.getServiceLocator("default");
59              Assert.assertNotNull(serviceLocator);
60              serviceLocator.setPolicy(PolicyRoundRobin.class.getName());
61              //serviceLocator.withCache(new URL("http", "0.0.0.0", 0, ""));
62      }
63      
64       @Test(expected = ConfigurationException.class)
65      public void testJUDDI_939_1() throws Exception {
66              UDDIClient uddiClient = new UDDIClient();
67              ServiceLocator serviceLocator = uddiClient.getServiceLocator(UUID.randomUUID().toString());
68              Assert.fail();
69      }
70      
71      
72      /**
73       * this test requires a running juddi node on port 8080 and is therefore disabled from this context
74       * @throws Exception 
75       */
76      @Ignore
77      @Test
78      public void testJUDDI_939_2() throws Exception {
79          String uddiServiceId = "uddi:juddi.apache.org:services-inquiry";
80          try {
81              UDDIClient uddiClient = new UDDIClient();
82              ServiceLocator serviceLocator = uddiClient.getServiceLocator("default8080");
83              serviceLocator.setPolicy(PolicyRoundRobin.class.getName());
84              //serviceLocator.withCache(new URL("http://localhost:8080/juddiv3/services/"));
85              String endpoint = serviceLocator.lookupEndpoint(uddiServiceId);
86              Assert.assertNotNull(endpoint);
87              
88              String endpoint2 = serviceLocator.lookupEndpoint(uddiServiceId);
89              Assert.assertNotNull(endpoint2);
90              Assert.assertNotEquals(endpoint2, endpoint);
91  
92          } catch (Exception e) {
93              throw new Exception("Could not resolve endpoint '" + uddiServiceId + "'.", e);
94          }
95  
96      }
97  
98  
99  	
100 }