This project has retired. For details please refer to its Attic page.
SelectionTest 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.util.ArrayList;
18  import java.util.List;
19  import java.util.Properties;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  /**
25   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
26   */
27  public class SelectionTest {
28  
29  	
30  	@Test
31  	public void testRoundRobin() {
32  		List<String> eprs = new ArrayList<String>();
33  		eprs.add("epr1");
34  		eprs.add("epr2");
35  		eprs.add("epr3");
36  		Topology topology = new Topology(eprs);
37  		SelectionPolicy selection = new PolicyRoundRobin(null);
38  		
39  		Assert.assertEquals("epr2",selection.select(topology));
40  		Assert.assertEquals("epr3",selection.select(topology));
41  		Assert.assertEquals("epr1",selection.select(topology));
42  		Assert.assertEquals("epr2",selection.select(topology));
43  		Assert.assertEquals("epr3",selection.select(topology));
44  		Assert.assertEquals("epr1",selection.select(topology));
45  		Assert.assertEquals("epr2",selection.select(topology));
46  		
47  	}
48  	
49  	@Test
50  	public void testLocalFirst() {
51  		List<String> eprs = new ArrayList<String>();
52  		eprs.add("localhost:epr1");
53  		eprs.add("remotehost:epr2");
54  		eprs.add("remotehost:epr3");
55  		Topology topology = new Topology(eprs);
56  		
57  		SelectionPolicy selection = new PolicyLocalFirst(null);
58  		
59  		Assert.assertEquals("localhost:epr1",selection.select(topology));
60  		Assert.assertEquals("localhost:epr1",selection.select(topology));
61  		Assert.assertEquals("localhost:epr1",selection.select(topology));
62  		
63  		
64  	}
65  	
66  	@Test
67  	public void testLocalFirst2() {
68  		List<String> eprs = new ArrayList<String>();
69  		eprs.add("host1:epr1");
70  		eprs.add("host2:epr2");
71  		eprs.add("host3:epr3");
72  		Topology topology = new Topology(eprs);
73  		
74  		//If the epr contains the String 'host2:' it should get picked 
75  		Properties properties = new Properties();
76  		properties.put(PolicyLocalFirst.JUDDI_CLIENT_LOCAL, "host2:");
77  		SelectionPolicy selection = new PolicyLocalFirst(properties);
78  		
79  		Assert.assertEquals("host2:epr2",selection.select(topology));
80  		Assert.assertEquals("host2:epr2",selection.select(topology));
81  		Assert.assertEquals("host2:epr2",selection.select(topology));
82  		
83  	}
84  	
85  }