/**
 *
 * Copyright 2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.geronimo.messaging.cluster.topology;

import java.net.InetAddress;
import java.util.Set;

import org.apache.geronimo.messaging.NodeInfo;
import org.apache.geronimo.messaging.NodeTopology;

import junit.framework.TestCase;

/**
 *
 * @version $Revision: 1.1 $ $Date: 2004/06/10 23:12:24 $
 */
public class RingTopologyManagerTest extends TestCase
{

    public void testGetNeighbours1() throws Exception {
        InetAddress address = InetAddress.getLocalHost();

        RingTopologyManager manager = new RingTopologyManager();
        
        NodeInfo node1 = new NodeInfo("node1", address, 1234);
        manager.addNode(node1);
        
        NodeTopology topology = manager.factoryTopology();
        Set neighbours = topology.getNeighbours(node1);
        assertEquals(0, neighbours.size());
    }

    public void testGetNeighbours2() throws Exception {
        InetAddress address = InetAddress.getLocalHost();

        RingTopologyManager manager = new RingTopologyManager();
        
        NodeInfo node1 = new NodeInfo("node1", address, 1234);
        manager.addNode(node1);
        NodeInfo node2 = new NodeInfo("node2", address, 1234);
        manager.addNode(node2);
        
        NodeTopology topology = manager.factoryTopology();
        Set neighbours = topology.getNeighbours(node1);
        assertEquals(1, neighbours.size());
        assertTrue(neighbours.contains(node2));
        neighbours = topology.getNeighbours(node2);
        assertEquals(1, neighbours.size());
        assertTrue(neighbours.contains(node1));
    }

    public void testGetNeighbours3() throws Exception {
        InetAddress address = InetAddress.getLocalHost();

        RingTopologyManager manager = new RingTopologyManager();
        
        NodeInfo node1 = new NodeInfo("node1", address, 1234);
        manager.addNode(node1);
        NodeInfo node2 = new NodeInfo("node2", address, 1234);
        manager.addNode(node2);
        NodeInfo node3 = new NodeInfo("node3", address, 1234);
        manager.addNode(node3);
        
        NodeTopology topology = manager.factoryTopology();
        Set neighbours = topology.getNeighbours(node1);
        assertEquals(2, neighbours.size());
        assertTrue(neighbours.contains(node2));
        assertTrue(neighbours.contains(node3));
        neighbours = topology.getNeighbours(node2);
        assertEquals(2, neighbours.size());
        assertTrue(neighbours.contains(node1));
        assertTrue(neighbours.contains(node3));
        neighbours = topology.getNeighbours(node3);
        assertEquals(2, neighbours.size());
        assertTrue(neighbours.contains(node1));
        assertTrue(neighbours.contains(node2));
    }

    public void testGetPath() throws Exception {
        InetAddress address = InetAddress.getLocalHost();

        RingTopologyManager manager = new RingTopologyManager();
        
        NodeInfo node1 = new NodeInfo("node1", address, 1234);
        manager.addNode(node1);
        NodeInfo node2 = new NodeInfo("node2", address, 1234);
        manager.addNode(node2);
        NodeInfo node3 = new NodeInfo("node3", address, 1234);
        manager.addNode(node3);
        
        NodeTopology topology = manager.factoryTopology();
        NodeInfo[] path = topology.getPath(node1, node3);
        assertEquals(2, path.length);
        assertEquals(node2, path[0]);
        assertEquals(node3, path[1]);

        path = topology.getPath(node3, node1);
        assertEquals(2, path.length);
        assertEquals(node2, path[0]);
        assertEquals(node1, path[1]);
    }
    
}

@@ -894,17 +894,17 @@
 sion: 1.
-1
+2
  $ $Date
@@ -915,21 +915,21 @@
 04/0
-6/10 23:12:24
+7/20 00:27:28
  $%0A 
@@ -3781,32 +3781,222 @@
 addNode(node3);%0A
+        NodeInfo node4 = new NodeInfo(%22node4%22, address, 1234);%0A        manager.addNode(node4);%0A        NodeInfo node5 = new NodeInfo(%22node5%22, address, 1234);%0A        manager.addNode(node5);%0A
         %0A       
@@ -4039,32 +4039,33 @@
 toryTopology();%0A
+%0A
         NodeInfo
@@ -4099,16 +4099,140 @@
 node
-1, node3
+2, node3);%0A        assertEquals(1, path.length);%0A        assertEquals(node3, path%5B0%5D);%0A%0A        path = topology.getPath(node2, node4
 );%0A 
@@ -4285,33 +4285,33 @@
 ssertEquals(node
-2
+3
 , path%5B0%5D);%0A    
@@ -4327,25 +4327,25 @@
 tEquals(node
-3
+4
 , path%5B1%5D);%0A
@@ -4385,16 +4385,16 @@
 node
-3
+2
 , node
-1
+5
 );%0A 
@@ -4455,17 +4455,17 @@
 als(node
-2
+1
 , path%5B0
@@ -4497,17 +4497,141 @@
 node
-1, path%5B1
+5, path%5B1%5D);%0A%0A        path = topology.getPath(node2, node1);%0A        assertEquals(1, path.length);%0A        assertEquals(node1, path%5B0
 %5D);%0A
@@ -4636,15 +4636,11 @@
 ;%0A    %7D%0A
-    
 %0A%7D%0A

Improve the JUnit tests of RingTopologyManager.