Home » geronimo-2.2-source-release » org.apache.geronimo.deployment.service » [javadoc | source]

    1   /**
    2    *
    3    * Copyright 2003-2004 The Apache Software Foundation
    4    *
    5    *  Licensed under the Apache License, Version 2.0 (the "License");
    6    *  you may not use this file except in compliance with the License.
    7    *  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   package org.apache.geronimo.deployment.service;
   18   
   19   import java.net.URI;
   20   import java.net.URL;
   21   import java.io.File;
   22   import java.util.ArrayList;
   23   
   24   import junit.framework.TestCase;
   25   import org.apache.geronimo.deployment.xbeans.ConfigurationDocument;
   26   import org.apache.geronimo.deployment.xbeans.ConfigurationType;
   27   import org.apache.geronimo.deployment.xbeans.GbeanType;
   28   import org.apache.geronimo.deployment.DeploymentContext;
   29   import org.apache.geronimo.deployment.FooBarBean;
   30   import org.apache.geronimo.kernel.config.ConfigurationModuleType;
   31   import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContext;
   32   import org.apache.geronimo.j2ee.j2eeobjectnames.J2eeContextImpl;
   33   import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
   34   import org.apache.geronimo.gbean.GBeanData;
   35   import org.apache.geronimo.gbean.ReferenceCollection;
   36   import org.apache.geronimo.gbean.ReferenceCollectionListener;
   37   
   38   /**
   39    * @version $Rev:  $ $Date:  $
   40    */
   41   public class ServiceConfigBuilderTest extends TestCase {
   42   
   43       public void testJavaBeanXmlAttribute() throws Exception {
   44           ReferenceCollection referenceCollection = new MockReferenceCollection();
   45           JavaBeanXmlAttributeBuilder javaBeanXmlAttributeBuilder = new JavaBeanXmlAttributeBuilder();
   46           //this is kind of cheating, we rely on the builder to iterate through existing members of the collection.
   47           referenceCollection.add(javaBeanXmlAttributeBuilder);
   48           ServiceConfigBuilder builder = new ServiceConfigBuilder(URI.create("test/foo"), null, referenceCollection, null, null);
   49           ClassLoader cl = Thread.currentThread().getContextClassLoader();
   50           URL plan1 = cl.getResource("services/plan1.xml");
   51           ConfigurationDocument doc = ConfigurationDocument.Factory.parse(plan1);
   52           ConfigurationType plan = doc.getConfiguration();
   53           File outFile = File.createTempFile("foo", "bar");
   54           outFile.delete();
   55           if (!outFile.mkdirs()) {
   56               fail("could not create temp dir");
   57           }
   58           try {
   59               DeploymentContext context = new DeploymentContext(outFile, URI.create("foo/bar"), ConfigurationModuleType.SERVICE, URI.create("foo"), "domain", "server", null);
   60               J2eeContext j2eeContext = new J2eeContextImpl("domain", "server", "null", "test", "configtest", "foo", NameFactory.J2EE_MODULE);
   61               GbeanType[] gbeans = plan.getGbeanArray();
   62               ServiceConfigBuilder.addGBeans(gbeans, cl, j2eeContext, context);
   63               GBeanData[] beanDatas = context.getGBeans();
   64               assertEquals(1, beanDatas.length);
   65               GBeanData data = beanDatas[0];
   66               FooBarBean fooBarBean = (FooBarBean) data.getAttribute("fooBarBean");
   67               assertNotNull(fooBarBean);
   68               assertEquals("foo", fooBarBean.getFoo());
   69               assertEquals(10, fooBarBean.getBar());
   70               FooBarBean inner = fooBarBean.getBean();
   71               assertNotNull(inner);
   72               assertEquals("foo2", inner.getFoo());
   73               assertEquals(100, inner.getBar());
   74               assertNull(inner.getBean());
   75           } finally {
   76               recursiveDelete(outFile);
   77           }
   78       }
   79   
   80       private void recursiveDelete(File file) {
   81   
   82           File[] list = file.listFiles();
   83           if (list != null) {
   84               for (int i = 0; i < list.length; i++) {
   85                   File file1 = list[i];
   86                   if (file1.isDirectory()) {
   87                       recursiveDelete(file1);
   88                   }
   89               }
   90           }
   91           file.delete();
   92       }
   93   
   94       private static class MockReferenceCollection extends ArrayList implements ReferenceCollection {
   95   
   96           public void addReferenceCollectionListener(ReferenceCollectionListener listener) {
   97   
   98           }
   99   
  100           public void removeReferenceCollectionListener(ReferenceCollectionListener listener) {
  101   
  102           }
  103       }
  104   }

Home » geronimo-2.2-source-release » org.apache.geronimo.deployment.service » [javadoc | source]