Package org.apache.myfaces.trinidad.convert

Examples of org.apache.myfaces.trinidad.convert.DateTimeConverter


    return new TestSuite(TrinidadDateTimeConverterTest.class);
  }
 
  public void testConveniencePatterns()
  {
    DateTimeConverter dtConv   = new DateTimeConverter();
    dtConv.setLocale(Locale.US);
   
    //this is what SimpleInputDateRenderer does
    if(dtConv.getTimeZone() == null)
    {
      TimeZone tz = null;
      tz = _mafct.getTimeZone();
      if(tz == null)
        tz = TimeZone.getDefault();
      dtConv.setTimeZone(tz);
    }
   
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String[] inputValue = {"15/2/2002", "January 4, 2004", "4-JAnuARY-2004", "JANUARY/4/2007", "Jan 4, 2004",
        "01/4/2004", "01-4-2004", "01.4.2004", "1/4/2004", "1-4-2004", "1.4.2004", "Jan/4/2004", "Jan-4-2004",
        "Jan.4.2004", "04-jan-2004", "4-jan-04", "4-jan-2004", "04-jAn-04", "04-JAN-04", "04-JAN-2004",
        "4-JAN-04", "4-JAN-2004", "January 4, 2004", "Jan 4, 2004"};

    for(int i = 0; i < inputValue.length; i++)
    {
      dtConv.getAsObject(facesContext, component, inputValue[i]);
    }
  }
View Full Code Here


    }
  }

  public void testFormatedPatterns()
  {
    DateTimeConverter dtConv   = new DateTimeConverter();
    dtConv.setLocale(Locale.US);
   
    //this is what SimpleInputDateRenderer does
    if(dtConv.getTimeZone() == null)
    {
      TimeZone tz = null;
      tz = _mafct.getTimeZone();
      if(tz == null)
        tz = TimeZone.getDefault();
      dtConv.setTimeZone(tz);
    }
   
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String[] inputValue = {"15/2/2002", "January 4, 2004", "4-JAnuARY-2004", "JANUARY/4/2007"};
    String[] formatedStrings = {"2/15/2002", "1/4/2004", "1/4/2004", "1/4/2007"};

    Date convertedDate = null;
    String returnedString = null;
    for(int i = 0; i < inputValue.length; i++)
    {
      convertedDate = (Date) dtConv.getAsObject(facesContext, component, inputValue[i]);
      returnedString = dtConv.getAsString(facesContext, component, convertedDate);
      assertEquals(returnedString, formatedStrings[i]);
    }
  }
View Full Code Here

    gcal.setTimeZone(DEFAULT_TIME_ZONE);
    // Make use of this date for testing.
    Date date = gcal.getTime();

    DateTimeConverter dtConv   = new DateTimeConverter();
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String inputValue          = "6/4/2999";

    dtConv.setDateStyle("shortish");
    dtConv.setLocale(Locale.ENGLISH);

    Date dt = (Date) dtConv.getAsObject(facesContext, component, inputValue);
    assertEquals(true, isEqual(date, dt));

    String exptectedStr = dtConv.getAsString(facesContext, component, dt);
    assertEquals(inputValue, exptectedStr);
    mock.verify();
  }
View Full Code Here

    gcal.setTimeZone(DEFAULT_TIME_ZONE);
    // Make use of this date for testing.
    Date date = gcal.getTime();

    DateTimeConverter dtConv   = new DateTimeConverter();
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String inputValue          = "6/4/1600";
    String secondaryPattern    = "MM/d/yyyy";

    dtConv.setLocale(Locale.US);
    dtConv.setDateStyle("Let us unset it ");
    dtConv.setType("Let us un set it");
    dtConv.setSecondaryPattern(secondaryPattern);

    // This should work fine
    Date dt = (Date) dtConv.getAsObject(facesContext, component, inputValue);
    assertEquals(true, isEqual(date, dt));

    try
    {
      dtConv.getAsString(facesContext, component, dt);
      fail("Use of secondary pattern in the above fashion is expected to fail here");
    }
    catch (RuntimeException ce)
    {
      // Just proceed . This is the expected state
    }

    dtConv.setDateStyle("shortish");
    dtConv.setType("date");

    // now we set date and type so this is expected to work fine.

    String expectedOut = dtConv.getAsString(facesContext, component, date);
    assertEquals(inputValue, expectedOut);

    mock.verify();
  }
View Full Code Here

    Mock mock = buildMockUIComponent(iterations);
    UIComponent component = (UIComponent) mock.proxy();
   
    for (int i = 0; i < validInputs.length; i++)
    {
      DateTimeConverter
        dtConv = (DateTimeConverter) getDateTimeConverter();
      dtConv.setLocale(Locale.ENGLISH);
      dtConv.setPattern(primaryPattern);
      dtConv.setSecondaryPattern(secondaryPatttern);
      dtConv.setTimeZone(DEFAULT_TIME_ZONE);
      dtConv.setType("INVALID"); // make this type invalid

      Date convDate = (Date) dtConv.getAsObject(facesContext, component,
                                                validInputs[i]);
      assertEquals(convDate, dt);
      mock.verify();
    }
  }
View Full Code Here

  {
    Object[][] data = _getDataForPatterns();

    for (int i = 0; i < data.length ; i++)
    {
      DateTimeConverter dtConv = new DateTimeConverter();
      dtConv.setPattern((String)data[i][0]);
      dtConv.setLocale((Locale)data[i][2]);
      dtConv.setTimeZone((TimeZone)data[i][3]);
      String inputValue = (String)data[i][1];

      javax.faces.convert.DateTimeConverter fdtConv
        = new javax.faces.convert.DateTimeConverter();
      fdtConv.setPattern((String)data[i][0]);
      fdtConv.setLocale((Locale)data[i][2]);
      fdtConv.setTimeZone((TimeZone)data[i][3]);

      Mock mock = buildMockUIComponent();
      UIComponent component = (UIComponent) mock.proxy();
      Date dtConvDate  = (Date)dtConv.getAsObject(facesContext, component, inputValue);
      Date fdtConvDate = (Date)fdtConv.getAsObject(facesContext, component, inputValue);
      //      assertEquals(dtConvDate, fdtConvDate);

      dtConv.getAsString(facesContext, component, dtConvDate);
      fdtConv.getAsString(facesContext, component, fdtConvDate);
      //      assertEquals(dtConvPattern, fdtConvPattern);
    }
  }
View Full Code Here

  }

  @Override
  protected javax.faces.convert.DateTimeConverter getDateTimeConverter()
  {
    return new DateTimeConverter();
  }
View Full Code Here

    return new TestSuite(TrinidadDateTimeConverterTest.class);
  }

  public void testConveniencePatterns()
  {
    DateTimeConverter dtConv   = new DateTimeConverter();
    dtConv.setLocale(Locale.US);

    //this is what SimpleInputDateRenderer does
    if(dtConv.getTimeZone() == null)
    {
      TimeZone tz = null;
      tz = _mafct.getTimeZone();
      if(tz == null)
        tz = TimeZone.getDefault();
      dtConv.setTimeZone(tz);
    }

    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String[] inputValue = {"15/2/2002", "January 4, 2004", "4-JAnuARY-2004", "JANUARY/4/2007", "Jan 4, 2004",
        "01/4/2004", "01-4-2004", "01.4.2004", "1/4/2004", "1-4-2004", "1.4.2004", "Jan/4/2004", "Jan-4-2004",
        "Jan.4.2004", "04-jan-2004", "4-jan-04", "4-jan-2004", "04-jAn-04", "04-JAN-04", "04-JAN-2004",
        "4-JAN-04", "4-JAN-2004", "January 4, 2004", "Jan 4, 2004"};

    for(int i = 0; i < inputValue.length; i++)
    {
      dtConv.getAsObject(facesContext, component, inputValue[i]);
    }
  }
View Full Code Here

    }
  }

  public void testFormatedPatterns()
  {
    DateTimeConverter dtConv   = new DateTimeConverter();
    dtConv.setLocale(Locale.US);

    //this is what SimpleInputDateRenderer does
    if(dtConv.getTimeZone() == null)
    {
      TimeZone tz = null;
      tz = _mafct.getTimeZone();
      if(tz == null)
        tz = TimeZone.getDefault();
      dtConv.setTimeZone(tz);
    }

    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String[] inputValue = {"15/2/2002", "January 4, 2004", "4-JAnuARY-2004", "JANUARY/4/2007"};
    String[] formatedStrings = {"2/15/2002", "1/4/2004", "1/4/2004", "1/4/2007"};

    Date convertedDate = null;
    String returnedString = null;
    for(int i = 0; i < inputValue.length; i++)
    {
      convertedDate = (Date) dtConv.getAsObject(facesContext, component, inputValue[i]);
      returnedString = dtConv.getAsString(facesContext, component, convertedDate);
      assertEquals(returnedString, formatedStrings[i]);
    }
  }
View Full Code Here

    gcal.setTimeZone(DEFAULT_TIME_ZONE);
    // Make use of this date for testing.
    Date date = gcal.getTime();

    DateTimeConverter dtConv   = new DateTimeConverter();
    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    String inputValue          = "6/4/2999";

    dtConv.setDateStyle("shortish");
    dtConv.setLocale(Locale.ENGLISH);

    Date dt = (Date) dtConv.getAsObject(facesContext, component, inputValue);
    assertEquals(true, isEqual(date, dt));

    String exptectedStr = dtConv.getAsString(facesContext, component, dt);
    assertEquals(inputValue, exptectedStr);
    mock.verify();
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.trinidad.convert.DateTimeConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.