commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap Componenttest.betwixt Componenttest.java POTest.betwixt POTest.java TestNoWrap.java po_add_test.xml
Date Mon, 08 Jul 2002 16:40:06 GMT
jvanzyl     2002/07/08 09:40:06

  Added:       betwixt/src/test/org/apache/commons/betwixt/nowrap
                        Componenttest.betwixt Componenttest.java
                        POTest.betwixt POTest.java TestNoWrap.java
                        po_add_test.xml
  Log:
  o Adding a test for collections that should not be wrapped by a
    plural wrapper.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/Componenttest.betwixt
  
  Index: Componenttest.betwixt
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <info primitiveTypes="element">
    <element name="componenttest">
      <element name="compdescription" property="compDescription"/>
      <addDefaults/>
    </element>
  </info>
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/Componenttest.java
  
  Index: Componenttest.java
  ===================================================================
  package org.apache.commons.betwixt.nowrap;
  
  public class Componenttest
  {
  
      private String compDescription = "";
  
      public Componenttest()
      {
          System.out.println("-- INSTANTIATING NEW COMPONENTTEST");
      }
  
      public void setCompDescription(String s)
      {
          System.out.println("SET component description");
          compDescription = s;
      }
  
      public String getCompDescription()
      {
          System.out.println("GET component description");
          return compDescription;
      }
  }
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/POTest.betwixt
  
  Index: POTest.betwixt
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <info primitiveTypes="element">
    <element name="content">
      <element name="printingno" property="printingNumber"/>
      <addDefaults/>
    </element>
  </info>
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/POTest.java
  
  Index: POTest.java
  ===================================================================
  package org.apache.commons.betwixt.nowrap;
  
  // Java Core Classes
  import java.util.ArrayList;
  import java.util.List;
  
  
  public class POTest
  {
  
      private List componentTests;
  
      private String printingNumber = "";
  
      public POTest()
      {
          System.out.println("-- INSTANTIATING NEW PO");
          componentTests = new ArrayList();
      }
  
      public List getComponenttests()
      {
          System.out.println("-- GET PO.getComponents");
          return this.componentTests;
      }
  
      public void setComponenttests(List componentTests)
      {
      }
  
      public void addComponenttest(Componenttest c)
      {
          System.out.println("-- ADD PO.addComponent");
          componentTests.add(c);
      }
  
      public void setPrintingNumber(String s)
      {
          System.out.println("-- SET PO.setPrintingNumber");
          printingNumber = s;
      }
  
      public String getPrintingNumber()
      {
          System.out.println("-- GET PO.getPrintingNumber");
          return printingNumber;
      }
  }
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/TestNoWrap.java
  
  Index: TestNoWrap.java
  ===================================================================
  package org.apache.commons.betwixt.nowrap;
  
  import java.util.ArrayList;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.IOException;
  
  import org.apache.commons.betwixt.io.BeanReader;
  import org.apache.commons.betwixt.io.BeanWriter;
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
  import org.apache.commons.betwixt.strategy.NoOpPluralStemmer;
  import org.apache.commons.betwixt.strategy.DefaultPluralStemmer;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Test harness for the base PO object
   *
   * @author <a href="mailto:john@zenplex.com">John Thorhauer</a>
   * @version $Id: TestNoWrap.java,v 1.1 2002/07/08 16:40:06 jvanzyl Exp $
   */
  public class TestNoWrap
      extends TestCase
  {
      private POTest po;
  
      /**
       * A unit test suite for JUnit
       */
      public static Test suite()
      {
          return new TestSuite(TestNoWrap.class);
      }
  
      /**
       * Constructor for the TestScarabSettings object
       *
       * @param testName
       */
      public TestNoWrap(String testName)
      {
          super(testName);
      }
  
      /**
       * Description of the Method
       */
      public void testRoundTrip()
          throws Exception
      {
          load();
          write();
      }
  
      /**
       * Description of the Method
       */
      public void load()
          throws Exception
      {
          String xmlLocation = "src/test/org/apache/commons/betwixt/nowrap/po_add_test.xml";
  
          FileInputStream in = new FileInputStream(new File(xmlLocation));
  
          // create a new BeanReader
          BeanReader reader = createBeanReader(POTest.class);
          po = (POTest) reader.parse(in);
      }
  
      /**
       * Description of the Method
       */
      public void write()
          throws Exception
      {
          // Let's try to write the bean
          BeanWriter beanWriter = new BeanWriter();
          beanWriter.setXMLIntrospector(createXMLIntrospector());
          beanWriter.setWriteIDs(false);
          beanWriter.enablePrettyPrint();
          System.out.println(po);
          beanWriter.write(po);
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------
  
      /**
       * Description of the Method
       */
      protected BeanReader createBeanReader(Class beanClass)
          throws Exception
      {
          BeanReader reader = new BeanReader();
          reader.setXMLIntrospector(createXMLIntrospector());
          reader.registerBeanClass(beanClass);
          return reader;
      }
  
      /**
       * ### it would be really nice to move this somewhere shareable across Maven
       * / Turbine projects. Maybe a static helper method - question is what to
       * call it???
       */
      protected XMLIntrospector createXMLIntrospector()
      {
          XMLIntrospector introspector = new XMLIntrospector();
  
          // set elements for attributes to true
          introspector.setAttributesForPrimitives(false);
  
          // wrap collections in an XML element
          introspector.setWrapCollectionsInElement(false);
  
          // turn bean elements first letter into lower case
          introspector.setNameMapper( new DecapitalizeNameMapper() );
  
          // Set default plural stemmer.
          introspector.setPluralStemmer( new DefaultPluralStemmer() );
  
          return introspector;
      }
  }
  
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/nowrap/po_add_test.xml
  
  Index: po_add_test.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
      
  <content>
    <printingno>555008805581</printingno>
  
    <componenttest>
      <compdescription>Text</compdescription>
    </componenttest>
    <componenttest>
      <compdescription>Binding</compdescription>
    </componenttest>
    <componenttest>
      <compdescription>Paper Cover</compdescription>
    </componenttest>
  
  </content>
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message