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 at7 * http://www.apache.org/licenses/LICENSE-2.08 * 9 * Unless required by applicable law or agreed to in writing, software10 * 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 and13 * limitations under the License.14 */15package org.apache.juddi.v3.client.mapping;
1617import java.util.ArrayList;
18import java.util.List;
19import java.util.Properties;
2021import org.junit.Assert;
22import org.junit.Test;
2324/**25 * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>26 */27publicclassSelectionTest {
282930 @Test
31publicvoid 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);
3839 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));
4647 }
4849 @Test
50publicvoid 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);
5657 SelectionPolicy selection = new PolicyLocalFirst(null);
5859 Assert.assertEquals("localhost:epr1",selection.select(topology));
60 Assert.assertEquals("localhost:epr1",selection.select(topology));
61 Assert.assertEquals("localhost:epr1",selection.select(topology));
626364 }
6566 @Test
67publicvoid 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);
7374//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);
7879 Assert.assertEquals("host2:epr2",selection.select(topology));
80 Assert.assertEquals("host2:epr2",selection.select(topology));
81 Assert.assertEquals("host2:epr2",selection.select(topology));
8283 }
8485 }