1 22 package org.objectweb.petals.kernel.configuration; 23 24 import java.lang.reflect.Method ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import junit.framework.TestCase; 29 30 import org.easymock.classextension.EasyMock; 31 import org.objectweb.petals.kernel.admin.ContainerInformation; 32 import org.objectweb.petals.util.LoggingUtil; 33 34 39 public class ConfigurationServiceTest extends TestCase { 40 41 public void testFindNotTaken() { 42 List <String > taken = new ArrayList <String >(); 43 taken.add("0"); 44 taken.add("1"); 45 ConfigurationService configurationService = new ConfigurationService( 46 EasyMock.createMock(LoggingUtil.class)); 47 configurationService.id = "0"; 48 assertEquals(configurationService.findNotTaken(taken, 0, 255), "2"); 49 } 50 51 public void testFindNotTakenValues() { 52 List <String > taken = new ArrayList <String >(); 53 taken.add("0"); 54 taken.add("1"); 55 ConfigurationService configurationService = new ConfigurationService( 56 EasyMock.createMock(LoggingUtil.class)); 57 configurationService.id = "0"; 58 59 List <String > ports = new ArrayList <String >(); 60 ports.add("16400"); 61 ports.add("16200"); 62 ports.add("16300"); 63 ports.add("8081"); 64 ports.add("8082"); 65 configurationService.jndiPort = "16400"; 66 configurationService.tcpPort = "16200"; 67 configurationService.htmlPort = "8081"; 68 configurationService.jmxPort = "8081"; 69 configurationService.domainPort = "16300"; 70 71 configurationService.findNotTakenValues(taken, ports); 72 73 assertEquals(configurationService.id, "2"); 74 assertEquals(configurationService.jndiPort, "16401"); 75 assertEquals(configurationService.tcpPort, "16201"); 76 } 77 78 public void testIsInitialized() { 79 ConfigurationService configurationService = new ConfigurationService( 80 EasyMock.createMock(LoggingUtil.class)); 81 assertFalse(configurationService.isInitialized()); 82 } 83 84 public void testSetUpConfiguration() throws SecurityException , 85 NoSuchMethodException { 86 ConfigurationService configurationService = EasyMock.createMock( 87 ConfigurationService.class, 88 new Method [] {ConfigurationService.class.getDeclaredMethod( 89 "findNotTakenValues", new Class [] {List .class, List .class})}); 90 LoggingUtil loggingUtil = EasyMock.createNiceMock(LoggingUtil.class); 91 92 List <ContainerInformation> containers = new ArrayList <ContainerInformation>(); 93 ContainerInformation containerInformation = new ContainerInformation(); 94 containerInformation.setHost("127.0.0.1"); 95 containerInformation.setUid(10); 96 containers.add(containerInformation); 97 List <String > ids = new ArrayList <String >(); 98 ids.add(null); 99 List <String > takenPorts = new ArrayList <String >(); 100 takenPorts.add(null); 101 takenPorts.add(null); 102 takenPorts.add(null); 103 takenPorts.add(null); 104 takenPorts.add(null); 105 configurationService.findNotTakenValues(ids, takenPorts); 106 107 EasyMock.replay(configurationService); 108 109 configurationService.host = "127.0.0.1"; 110 configurationService.log = loggingUtil; 111 configurationService.setContainers(containers); 112 113 configurationService.setUpConfiguration(); 114 } 115 } 116 | Popular Tags |