1 22 package org.objectweb.petals.jbi.component.context; 23 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 import javax.jbi.component.ComponentContext; 28 29 import junit.framework.TestCase; 30 31 import org.easymock.classextension.EasyMock; 32 import org.objectweb.petals.jbi.component.context.ComponentContextImpl; 33 import org.objectweb.petals.jbi.component.context.InstallationContextImpl; 34 import org.objectweb.petals.tools.jbicommon.descriptor.ComponentDescription; 35 import org.objectweb.petals.tools.jbicommon.descriptor.Identification; 36 37 43 public class InstallationContextImplTest extends TestCase { 44 45 private InstallationContextImpl installationContextImpl; 46 47 private ComponentContextImpl componentContextImpl; 48 49 public void setUp() { 50 ComponentDescription componentDescription = EasyMock 51 .createMock(ComponentDescription.class); 52 EasyMock.expect(componentDescription.getComponentClassName()) 53 .andReturn("testClassName").anyTimes(); 54 List <String > classpaths = new ArrayList <String >(); 55 classpaths.add("server.jar"); 56 EasyMock.expect(componentDescription.getComponentClassPath()) 57 .andReturn(classpaths).anyTimes(); 58 59 Identification identification = EasyMock 60 .createMock(Identification.class); 61 EasyMock.expect(identification.getName()).andReturn("compoName") 62 .anyTimes(); 63 EasyMock.replay(identification); 64 65 EasyMock.expect(componentDescription.getIdentification()).andReturn( 66 identification).anyTimes(); 67 EasyMock.replay(componentDescription); 68 69 componentContextImpl = new ComponentContextImpl(); 70 componentContextImpl.installationRoot = "install"; 71 72 installationContextImpl = new InstallationContextImpl( 73 componentDescription, componentContextImpl, true); 74 } 75 76 public void testGetClassPathElements() { 77 List result = installationContextImpl.getClassPathElements(); 78 assertNotNull("The result of getClassPathElements must not be null",result); 79 assertFalse("The list of classpath elements must not be empty",result.isEmpty()); 80 assertEquals(result.get(0), 81 "server.jar"); 82 } 83 84 public void testGetComponentClassName() { 85 String result = installationContextImpl.getComponentClassName(); 86 assertNotNull("The result of getComponentClassName must not be null",result); 87 assertFalse("The result of getComponentClassName must not be empty",result.length() == 0); 88 assertEquals(result,"testClassName"); 89 } 90 91 public void testGetComponentName() { 92 String result = installationContextImpl.getComponentName(); 93 assertNotNull("The result of getComponentName must not be null",result); 94 assertFalse("The result of getComponentName must not be empty",result.length() == 0); 95 assertEquals(result, "compoName"); 96 } 97 98 public void testGetContext() { 99 ComponentContext result = installationContextImpl.getContext(); 100 assertNotNull("The result of getContext must not be null",result); 101 assertEquals(result.getInstallRoot(), 102 componentContextImpl.getInstallRoot()); 103 } 104 105 public void testGetInstallationDescriptorExtension() { 106 assertNull(installationContextImpl.getInstallationDescriptorExtension()); 107 } 108 109 public void testGetInstallRoot() { 110 String result = installationContextImpl.getInstallRoot(); 111 assertNotNull("The result of getInstallRoot must not be null",result); 112 assertFalse("The result of getInstallRoot must not be empty",result.length() == 0); 113 assertEquals(result, "install"); 114 } 115 116 public void testIsInstall() { 117 assertTrue(installationContextImpl.isInstall()); 118 } 119 120 public void testSetClassPathElements() { 121 125 List <String > classPathElements = null; 126 129 try { 130 installationContextImpl.setClassPathElements(classPathElements); 131 fail("No exception was raised"); 132 } catch (Exception e) { 133 } 135 139 classPathElements = new ArrayList <String >(); 140 143 try { 144 installationContextImpl.setClassPathElements(classPathElements); 145 fail("No exception was raised"); 146 } catch (Exception e) { 147 } 149 153 classPathElements.add("some class path"); 154 157 try { 158 installationContextImpl.setClassPathElements(classPathElements); 159 } catch (Exception e) { 160 e.printStackTrace(); 161 fail("Error during method invokation"); 162 } 163 assertEquals("The classPathElements ware not properly set",installationContextImpl.getClassPathElements(), classPathElements); 164 } 165 166 } 167 | Popular Tags |