Java Code Examples for javax.faces.convert.ConverterException

The following are top voted examples for showing how to use javax.faces.convert.ConverterException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: oscm   File: DurationConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Conversion to server representation, so converting days to milliseconds.
 * Prior to the conversion the input value is validated.
 */
@Override
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    try {
        // Checks if mandatory and not empty
        new ParameterValueValidator().validate(context, component, value);
    } catch (ValidatorException e) {
        throw new ConverterException(e.getFacesMessage());
    }

    // Validation passed; so if the value is empty it's not mandatory
    if (value == null || value.trim().length() == 0) {
        return null;
    } else {
        Long durationInMs = DurationValidation.convertDurationToMs(context,
                value);
        if (durationInMs != null) {
            return durationInMs.toString();
        } else {
            throw new ConverterException(
                    ParameterValueValidator.getFacesMessage(component,
                            context));
        }
    }
}
 
Example 2
Project: oscm   File: DurationConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Conversion to portal representation as String.
 */
@Override
public String getAsString(FacesContext context, UIComponent component,
        Object object) {
    if (object == null) {
        return null;
    }
    String value = object.toString();
    if (value.trim().length() == 0) {
        return null;
    }
    long durationInMs;
    try {
        durationInMs = Long.parseLong(value);
    } catch (NumberFormatException e) {
        throw new ConverterException(
                ParameterValueValidator.getFacesMessage(component, context));
    }
    long days = durationInMs / DurationValidation.MILLISECONDS_PER_DAY;
    return String.valueOf(days);
}
 
Example 3
Project: oscm   File: CurrencyConverter.java   Source Code and License 6 votes vote down vote up
/**
 * Conversion to server representation, so converting currency to internal
 * integer with cents format. Prior to the conversion the input value is
 * validated.
 * 
 * @param context
 *            JSF context.
 * @param component
 *            Component which value will be processed.
 * @param value
 *            Value.
 */
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    final PriceConverter converter = getConverter(context);

    try {
        return converter.parse(value);
    } catch (ParseException e) {
        String msg = e.getMessage();
        if (msg != null
                && msg.equals("ERROR_PRICEMODEL_INVALID_FRACTIONAL_PART")) {
            throw new ConverterException(JSFUtils.getFacesMessage(
                    component, context,
                    BaseBean.ERROR_PRICEMODEL_INVALID_FRACTIONAL_PART));
        }
        throw new ConverterException(JSFUtils.getFacesMessage(component,
                context, BaseBean.ERROR_PRICEMODEL_INPUT));
    }
}
 
Example 4
Project: myfaces-trinidad   File: ShortConverter.java   Source Code and License 6 votes vote down vote up
@Override
public Object getAsObject(
  FacesContext context, 
  UIComponent component,
  String value) 
{
  try
  {
    return super.getAsObject(context, component, value);
  }
  catch(ConverterException ce)
  {
   
    throw ConverterUtils.getIntegerConverterException(context, 
                                                      component, 
                                                      ce,
                                                      value,
                                                      CONVERT_MESSAGE_ID,
                                                      MAXIMUM_MESSAGE_ID,
                                                      _SHORT_MAX,
                                                      MINIMUM_MESSAGE_ID,
                                                      _SHORT_MIN);
  }     
  
}
 
Example 5
Project: myfaces-trinidad   File: UIXEditableValueTemplate.java   Source Code and License 6 votes vote down vote up
private void _addConversionErrorMessage(
   FacesContext       context,
   ConverterException ce,
   Object             value)
{
  FacesMessage message = ce.getFacesMessage();

  if (message == null)
  {
    Object label = _getLabel();
    message = MessageFactory.getMessage(context,
                                        CONVERSION_MESSAGE_ID,
                                        new Object[]{label, value,
                                                     ce.getMessage()},
                                        label);
  }
  else
  {
    message = _wrapMessage(message);
  }

  context.addMessage(getClientId(context), message);
}
 
Example 6
Project: myfaces-trinidad   File: NumberConverter.java   Source Code and License 6 votes vote down vote up
@Override
public Object getAsObject(
  FacesContext context,
  UIComponent component,
  String value)
  throws ConverterException
{
  Object number = super.getAsObject(context, component, value);
  if (number == null) // bug 4137626
    return null;

  // this is causing issue TRINIDAD-690    
  number = 
    DateTimeConverter.__typeConvert(context, this, component, value, number);
  return number;
}
 
Example 7
Project: myfaces-trinidad   File: ByteConverter.java   Source Code and License 6 votes vote down vote up
@Override
public Object getAsObject(
  FacesContext context, 
  UIComponent component,
  String value) 
{
  try
  {
    return super.getAsObject(context, component, value);
  }
  catch(ConverterException ce)
  {

    throw ConverterUtils.getIntegerConverterException(context, 
                                                      component, 
                                                      ce,
                                                      value,
                                                      CONVERT_MESSAGE_ID,
                                                      MAXIMUM_MESSAGE_ID,
                                                      _BYTE_MAX,
                                                      MINIMUM_MESSAGE_ID,
                                                      _BYTE_MIN);
  }     
  
}
 
Example 8
Project: oscm   File: POServiceConverterTest.java   Source Code and License 6 votes vote down vote up
/**
 * Test for getting value with unescaped comma.
 * 
 * @throws ParseException
 */
@Test
public void testGetAsObjectWithComma() throws ConverterException, ParseException {
    UIComponent component = getComponent();
    POService actual = (POService) converter.getAsObject(context,
            component, poServiceAsStringWithComma);
    
    Assert.assertEquals(actual.getKey(), 10001);
    Assert.assertEquals(actual.getPictureUrl(),
            "/image?type=SERVICE_IMAGE&serviceKey=10001");
    Assert.assertEquals(actual.getProviderName(), "Fujitsu, INC.");
    Assert.assertEquals(actual.getServiceName(),
            "Hello Kitty November 6.66 1234:");
    Assert.assertEquals(actual.getStatusSymbol(), "status_NOT_ACTIVE");
    Assert.assertEquals(actual.getVersion(), 5);
}
 
Example 9
Project: myfaces-trinidad   File: TrinidadNumberConverterTest.java   Source Code and License 6 votes vote down vote up
@Override
protected void doTestStrictNess(
  MockFacesContext context,
  MockUIComponentWrapper wrapper,
  Locale locale,
  String inputValue)
{
   NumberConverter converter = getNumberConverter();
   converter.setLocale(locale);
   context.getViewRoot().setLocale(locale);
   try
   {
     // ADF Converter is not lenient.
     converter.getAsObject(context, wrapper.getUIComponent(), inputValue);
     fail("Expected converter exception");
   }
   catch (ConverterException ce)
   {
     ; // We expected a exception to occur
   }
}
 
Example 10
Project: oscm   File: PricedParameterRowTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCreatePricedParameterRowListCreateMissing()
        throws ConverterException {
    product.getPriceModel().setSelectedParameters(null);

    int size = parameterList.size()
            + parameterWithOption.getParameterDefinition()
                    .getParameterOptions().size();
    size--; // one parameter is of type string, must not be listed

    List<PricedParameterRow> selectedParameters;

    selectedParameters = PricedParameterRow.createPricedParameterRowList(
            product, false, true, false, true, true);
    Assert.assertEquals(size, selectedParameters.size());
    for (PricedParameterRow row : selectedParameters) {
        Assert.assertNotNull(row.getPricedParameter());
    }
}
 
Example 11
Project: oscm   File: PricedParameterRowTest.java   Source Code and License 6 votes vote down vote up
@Test
public void testCreatePricedParameterRowList_NotIncludeConfigurableOneTimeParams()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow.createPricedParameterRowList(
            product, true, true, true, true, false);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());

}
 
Example 12
Project: oscm   File: PricedParameterRowTest.java   Source Code and License 6 votes vote down vote up
@Test
public void createPricedParameterRowListForSubscription()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow
            .createPricedParameterRowListForSubscription(product);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());
    Assert.assertNull(selectedParameters.get(0).getParameter().getValue());

}
 
Example 13
Project: oscm   File: PricedParameterRowTest.java   Source Code and License 6 votes vote down vote up
@Test
public void createPricedParameterRowListForService()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow
            .createPricedParameterRowListForService(product);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());
    Assert.assertEquals("d1", selectedParameters.get(0).getParameter()
            .getValue());

}
 
Example 14
Project: myfaces-trinidad   File: SimpleSelectOneRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public Object getConvertedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue
  ) throws ConverterException
{
  boolean valuePassThru = getValuePassThru(component, getFacesBean(component));

  if (!valuePassThru)
  {
    return _convertIndexedSubmittedValue(context, component, submittedValue);
  }
  else
  {
    return super.getConvertedValue(context, component, submittedValue);
  }
}
 
Example 15
Project: myfaces-trinidad   File: EditableValueRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Converts a string value into the component's value
 * @param context the FacesContext
 * @param component the component
 * @param newValue the unconverted string value
 */
@Override
public Object getConvertedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue) throws ConverterException
{
  FacesBean bean = getFacesBean(component);
  Converter converter = getConverter(component, bean);
  if (converter == null)
    converter = getDefaultConverter(context, component, bean);

  if (converter != null)
  {
    return converter.getAsObject(context,
                                 component,
                                 // due to the new "JSF2 empty value" parameters it can be the
                                 // case the we actually have a NULL value here.
                                 (submittedValue != null) ? submittedValue.toString() : null);
  }

  return submittedValue;
}
 
Example 16
Project: oscm   File: BigDecimalConverter.java   Source Code and License 5 votes vote down vote up
private ConverterException createConverterException(FacesContext context,
        UIComponent component) {
    ValidationException e = new ValidationException(ReasonEnum.DECIMAL,
            null, null);
    return new ConverterException(JSFUtils.getFacesMessage(component,
            context, e.getMessageKey()));
}
 
Example 17
Project: ctsms   File: DateTimeConverter.java   Source Code and License 5 votes vote down vote up
public DateTimeConverter() {
	super();
	String converterDatetimePattern = Settings.getString(SettingCodes.CONVERTER_DATETIME_PATTERN, Bundle.SETTINGS, DefaultSettings.CONVERTER_DATETIME_PATTERN);
	if (converterDatetimePattern != null && converterDatetimePattern.length() > 0) {
		try {
			this.setPattern(converterDatetimePattern);
		} catch (ConverterException e) {
			setDateTimeStyleType();
		}
	} else {
		setDateTimeStyleType();
	}
}
 
Example 18
Project: oscm   File: PercentConverterTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = SaaSSystemException.class)
public void getAsObject_withSpecialCharacter() throws ConverterException {
    // given
    String str = "[email protected]";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "percent");

    // when
    converter.getAsObject(context, component, str);
}
 
Example 19
Project: oscm   File: PercentConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void getAsObject_Zero() throws ConverterException {
    // given
    String str = "0%";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "percent");

    // when
    Object actual = converter.getAsObject(context, component, str);

    // then
    assertEquals(new Long(0), actual);
}
 
Example 20
Project: aws-photosharing-example   File: UserConverter.java   Source Code and License 5 votes vote down vote up
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
    if(value != null && value.trim().length() > 0) {
        try {
        	return getFacade().findUser(Long.parseLong(value));                
        } catch(NumberFormatException e) {
            throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid user id."));
        }
    }
    else {
        return null;
    }
}
 
Example 21
Project: oscm   File: BigDecimalConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test(expected = ConverterException.class)
public void getAsObject_NotDigitsAfter() throws ConverterException {
    String str = "100abc";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "discount");

    converter.getAsObject(context, component, str);
}
 
Example 22
Project: oscm   File: BigDecimalConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test(expected = ConverterException.class)
public void getAsObject_NotDigits() throws ConverterException {
    String str = "abc";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "discount");

    converter.getAsObject(context, component, str);
}
 
Example 23
Project: oscm   File: BigDecimalConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void getAsObject_Zero() throws ConverterException {
    String str = "0";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "discount");

    BigDecimal expected = new BigDecimal(str);

    BigDecimal actual = (BigDecimal) converter.getAsObject(context,
            component, str);

    assertEquals(expected, actual);
}
 
Example 24
Project: myfaces-trinidad   File: IntegerConverter.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAsObject(
  FacesContext context, 
  UIComponent component,
  String value) 
{
  
  try
  {
    return super.getAsObject(context, component, value);
  }
  catch(ConverterException ce)
  {
    throw ConverterUtils.getIntegerConverterException(context, 
                                                      component, 
                                                      ce,
                                                      value,
                                                      CONVERT_MESSAGE_ID,
                                                      MAXIMUM_MESSAGE_ID,
                                                      _INT_MAX,
                                                      MINIMUM_MESSAGE_ID,
                                                      _INT_MIN);
                                                 
   
  }             
  
}
 
Example 25
Project: oscm   File: BigDecimalConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void getAsObject_4Decimals() throws ConverterException {
    String str = "0.0005";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "discount");
    BigDecimal expected = new BigDecimal(str);

    BigDecimal actual = (BigDecimal) converter.getAsObject(context,
            component, str);

    assertEquals(0, expected.compareTo(actual));
}
 
Example 26
Project: myfaces-trinidad   File: ConverterTestCase.java   Source Code and License 5 votes vote down vote up
/**
 * This test performs action on the method
 * javax.faces.convert.Converter.getAsObject(FacesContext, UIComponent, String)
 * and
 * javax.faces.convert.Converter.getAsString(FacesContext, UIComponent, Object)
 * for method getAsObject() should return a value of null while getAsString()
 * should return a empty string.
 * @throws ValidatorException  when test fails
 */
protected void doTestNull(
  MockFacesContext context,
  MockUIComponentWrapper wrapper,
  Converter converter
  ) throws ConverterException
{
  Object obj = converter.getAsObject(context, wrapper.getUIComponent(), null);
  assertEquals(null, obj);
  String str = converter.getAsString(context, wrapper.getUIComponent(), null);
  assertEquals("",str);
  wrapper.getMock().verify();
}
 
Example 27
Project: oscm   File: HtmlNewLineConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test without conversion.
 */
@Test
public void getAsObject_noLineBreak() throws ConverterException {

    String value = "abc";
    String expected = "abc";

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 28
Project: oscm   File: HtmlNewLineConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test no server conversion for new lines to HTML br tags.
 */
@Test
public void getAsObject_lineBreak() throws ConverterException {

    String value = "test\ntext2\ntext3";
    String expected = value;

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 29
Project: oscm   File: HtmlNewLineConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test back to client conversion without lines breaks.
 */
@Test
public void getAsString_noLineBreak() throws ConverterException {

    String value = "abc";
    String expected = "abc";

    String actual = converter.getAsString(context, component, value);

    Assert.assertEquals(expected, actual);
}
 
Example 30
Project: oscm   File: HtmlNewLineConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test back to client converting new lines to HTML br tags.
 */
@Test
public void getAsString_lineBreak() throws ConverterException {

    String value = "test\ntext2\ntext3";
    String expected = "test<br />text2<br />text3";

    String actual = converter.getAsString(context, component, value);

    Assert.assertEquals(expected, actual);
}
 
Example 31
Project: tap17-muggl-javaee   File: CreditCardConverter.java   Source Code and License 5 votes vote down vote up
/**
 * <p>Parses the CreditCardNumber and strips any blanks or
 * <code>"-"</code> characters from it.</p>
 */
@Override
public Object getAsObject(FacesContext context,
        UIComponent component, String newValue)
        throws ConverterException {

    logger.log(Level.INFO, "Entering CreditCardConverter.getAsObject");

    if (newValue.isEmpty()) {
        return null;
    }

    // Since this is only a String to String conversion,
    // this conversion does not throw ConverterException.

    String convertedValue = newValue.trim();
    if ((convertedValue.contains("-")) || (convertedValue.contains(" "))) {

        char[] input = convertedValue.toCharArray();
        StringBuilder builder = new StringBuilder(input.length);

        for (int i = 0; i < input.length; ++i) {
            if ((input[i] == '-') || (input[i] == ' ')) {
            } else {
                builder.append(input[i]);
            }
        }

        convertedValue = builder.toString();
    }
    logger.log(Level.INFO, "Converted value is {0}", convertedValue);
    return convertedValue;
}
 
Example 32
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void testGetStringWithLeadingBlanks() throws ConverterException {

    String value = "   abc";
    String expected = "abc";

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 33
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void testGetStringWithTrailingBlanks() throws ConverterException {

    String value = "abc   ";
    String expected = "abc";

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 34
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void testGetStringWithBlanks() throws ConverterException {

    String value = "   abc   ";
    String expected = "abc";

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 35
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Test for getting value.
 */
@Test
public void testGetStringWithBlanksInMiddle() throws ConverterException {

    String value = "   abc  abc   ";
    String expected = "abc  abc";

    String actual = (String) converter.getAsObject(context, component,
            value);

    Assert.assertEquals(expected, actual);
}
 
Example 36
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectSpaceAndThreeByteSpaceMixture()
        throws ConverterException {
    String in = " " + "\u3000" + " " + "\u3000" + " ";
    String out = (String) converter.getAsObject(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example 37
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectSpaceAndThreeByteSpaceMixtureMiddle()
        throws ConverterException {
    String in = "\u3000" + "  " + "\u3000\u3000\u3000" + "  " + "\u3000";
    String out = (String) converter.getAsObject(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example 38
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectSpaceAndThreeByteSpaceMixtureLeading()
        throws ConverterException {
    String in = " " + "\u3000" + "  " + "\u3000\u3000" + "  " + "\u3000";
    String out = (String) converter.getAsObject(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example 39
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectSpaceAndThreeByteSpaceMixtureTrailing()
        throws ConverterException {
    String in = "\u3000" + "  " + "\u3000\u3000" + "  " + "\u3000" + "  ";
    String out = (String) converter.getAsObject(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example 40
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectThreeByteSpaceLeading()
        throws ConverterException {
    String in = "\u3000" + "one";
    String out = (String) converter.getAsObject(context, component, in);
    Assert.assertEquals("one", out);
}
 
Example 41
Project: myfaces-trinidad   File: NumberConverterTestCase.java   Source Code and License 5 votes vote down vote up
/**
 * Tests that null returns immediately.
 *
 * @throws ConverterException  when test fails
 */
public void testNullInputValue() throws ConverterException
{
  Mock mock = mock(UIComponent.class);
  UIComponent component = (UIComponent) mock.proxy();
  //we do not care about getValueExpression() being called or not
  mock.stubs().method("getValueExpression");

  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  NumberConverter converter  = getNumberConverter();

  doTestNull(facesContext, wrapper, converter);
}
 
Example 42
Project: myfaces-trinidad   File: ColorConverterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Tests that null returns immediately.
 *
 * @throws ConverterException  when test fails
 */
public void testNull() throws ConverterException
{
  Mock mock = mock(UIComponent.class);
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);

  ColorConverter converter  = new ColorConverter();

  doTestNull(facesContext, wrapper, converter);
}
 
Example 43
Project: myfaces-trinidad   File: ConverterUtils.java   Source Code and License 5 votes vote down vote up
public static final ConverterException createConverterException(
  FacesContext context,
  UIComponent  component,
  String       messageId,
  String       value,
  String       param
)
{
   Object label = _getLabel(component);
   FacesMessage message = MessageFactory.getMessage(context,
                                       messageId,
                                       new Object[]{label, value, param},
                                       label);
   return new ConverterException(message);
}
 
Example 44
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsStringThreeByteSpaceLeading()
        throws ConverterException {
    String in = "\u3000" + "one";
    String out = converter.getAsString(context, component, in);
    Assert.assertEquals("one", out);
}
 
Example 45
Project: oscm   File: TrimConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsStringThreeByteSpaceTrailing()
        throws ConverterException {
    String in = "one" + "\u3000";
    String out = converter.getAsString(context, component, in);
    Assert.assertEquals("one", out);
}
 
Example 46
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObject() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Object result = converter.getAsObject(context, component, "1");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(DurationValidation.MILLISECONDS_PER_DAY), result);
}
 
Example 47
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectDecimalSeparator() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Object result = converter.getAsObject(context, component, "1,00");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(DurationValidation.MILLISECONDS_PER_DAY * 100),
            result);
}
 
Example 48
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectZero() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Object result = converter.getAsObject(context, component, "0");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals("0", result);
}
 
Example 49
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectNull() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Object result = converter.getAsObject(context, component, null);
    Assert.assertNull(result);
}
 
Example 50
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectEmpty() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Object result = converter.getAsObject(context, component, "");
    Assert.assertNull(result);
}
 
Example 51
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectLowerRange() throws ConverterException {
    UIComponent component = getComponent(false, L5, null);
    Object result = converter.getAsObject(context, component, "10");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(10 * DurationValidation.MILLISECONDS_PER_DAY),
            result);
}
 
Example 52
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectLowerRangeValue() throws ConverterException {
    UIComponent component = getComponent(false, L5, null);
    Object result = converter.getAsObject(context, component, "5");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(5 * DurationValidation.MILLISECONDS_PER_DAY),
            result);
}
 
Example 53
Project: ctsms   File: DateConverter.java   Source Code and License 5 votes vote down vote up
public DateConverter() {
	super();
	String converterDatePattern = Settings.getString(SettingCodes.CONVERTER_DATE_PATTERN, Bundle.SETTINGS, DefaultSettings.CONVERTER_DATE_PATTERN);
	if (converterDatePattern != null && converterDatePattern.length() > 0) {
		try {
			this.setPattern(converterDatePattern);
		} catch (ConverterException e) {
			setDateStyleType();
		}
	} else {
		setDateStyleType();
	}
}
 
Example 54
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectUpperRangeValue() throws ConverterException {
    UIComponent component = getComponent(false, null, L5);
    Object result = converter.getAsObject(context, component, "5");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(5 * DurationValidation.MILLISECONDS_PER_DAY),
            result);
}
 
Example 55
Project: myfaces-trinidad   File: DateTimeConverter.java   Source Code and License 5 votes vote down vote up
private String[] _getExpectedPatterns(FacesContext context)
{
  String pattern = getPattern();

  if ( pattern != null )
  {
    return _getAllowedPatterns(context, pattern, getSecondaryPattern());
  }
  else
  {
    String datePattern = null;

    try
    {
      DateFormat format  = getDateFormat(context, null,false, null);
      if ((format != null) && (format instanceof SimpleDateFormat))
      {
        datePattern = ((SimpleDateFormat)format).toPattern();
      }
    }
    catch (ConverterException ce)
    {
      // Do nothing here. Check to see if secondary pattern is available.
      ;
    }
    return _getAllowedPatterns(context, datePattern, getSecondaryPattern());
  }
}
 
Example 56
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = ConverterException.class)
public void testGetAsObjectLongMax() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    converter.getAsObject(context, component,
            String.valueOf(Long.MAX_VALUE));
}
 
Example 57
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test
public void testGetAsObjectGerman() throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    context.setLocale(Locale.GERMAN);
    Object result = converter.getAsObject(context, component, "1");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(DurationValidation.MILLISECONDS_PER_DAY), result);
}
 
Example 58
Project: ctsms   File: TimeConverter.java   Source Code and License 5 votes vote down vote up
public TimeConverter() {
	super();
	String converterTimePattern = Settings.getString(SettingCodes.CONVERTER_TIME_PATTERN, Bundle.SETTINGS, DefaultSettings.CONVERTER_TIME_PATTERN);
	if (converterTimePattern != null && converterTimePattern.length() > 0) {
		try {
			this.setPattern(converterTimePattern);
		} catch (ConverterException e) {
			setTimeStyleType();
		}
	} else {
		setTimeStyleType();
	}
}
 
Example 59
Project: oscm   File: DurationConverterTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = ConverterException.class)
public void testGetAsObjectTwoDecimalSeparatorsGerman()
        throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    context.setLocale(Locale.GERMAN);
    converter.getAsObject(context, component, "1,57,56");
}
 
Example 60
Project: oscm   File: RevenueShareValidatorTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = ValidatorException.class)
public void validate_WrongScale() throws ConverterException {
    // given
    BigDecimal value = new BigDecimal("1.0001");
    // when
    validator.validate(context, component, value);
    // then no ValidatorException happen
}