javax.faces.convert.ConverterException Java Examples

The following examples show how to use javax.faces.convert.ConverterException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: POServiceConverterTest.java    From development with Apache License 2.0 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 #2
Source File: PricedParameterRowTest.java    From development with Apache License 2.0 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 #3
Source File: PricedParameterRowTest.java    From development with Apache License 2.0 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 #4
Source File: BigDecimalConverterTest.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Test for getting value for German local.
 */
@Test
public void getAsObject_GermanLocale() throws ConverterException {
    context = new FacesContextStub(Locale.GERMAN);

    String str = "1,23";
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "discount");
    BigDecimal expected = new BigDecimal("1.23");

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

    assertEquals(expected, actual);
    context = new FacesContextStub(Locale.ENGLISH);
}
 
Example #5
Source File: CurrencyConverter.java    From development with Apache License 2.0 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 #6
Source File: PricedParameterRowTest.java    From development with Apache License 2.0 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 #7
Source File: DurationConverter.java    From development with Apache License 2.0 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 #8
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #9
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #10
Source File: DurationConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAsObjectUpperRange() throws ConverterException {
    UIComponent component = getComponent(false, null, L5);
    Object result = converter.getAsObject(context, component, "3");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(3 * DurationValidation.MILLISECONDS_PER_DAY),
            result);
}
 
Example #11
Source File: DurationConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test(expected = ConverterException.class)
public void testGetAsStringWithDoubleInput() {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    Double value = Double
            .valueOf(DurationValidation.MILLISECONDS_PER_DAY * 1.5);
    converter.getAsString(context, component, value);
}
 
Example #12
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #13
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #14
Source File: VOFinderTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindByKey() throws ConverterException {
    Assert.assertSame(
            parameterDefinition,
            VOFinder.findByKey(parameterDefinitionList,
                    parameterDefinition.getKey()));
}
 
Example #15
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #16
Source File: TrimConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAsStringSpaceAndThreeByteSpaceMixtureTrailing()
        throws ConverterException {
    String in = "\u3000" + "  " + "\u3000\u3000" + "  " + "\u3000" + "  ";
    String out = converter.getAsString(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example #17
Source File: TrimConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAsStringSpaceAndThreeByteSpaceMixtureMiddle()
        throws ConverterException {
    String in = "\u3000" + "  " + "\u3000\u3000\u3000" + "  " + "\u3000";
    String out = converter.getAsString(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example #18
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #19
Source File: TrimConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAsStringSpaceAndThreeByteSpaceMixture()
        throws ConverterException {
    String in = " " + "\u3000" + " " + "\u3000" + " ";
    String out = converter.getAsString(context, component, in);
    Assert.assertEquals(null, out);
}
 
Example #20
Source File: TrimConverterTest.java    From development with Apache License 2.0 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 #21
Source File: PaddingConverter.p.vm.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
public String getAsString(FacesContext context, UIComponent component, Object object) {
    if (context == null || component == null) {
        throw new NullPointerException();
    }
    if (object == null) {
        return "";
    }
    if (object instanceof String) {
        return ((String) object).trim();
    } else {
        throw new ConverterException(MessageFactory.getMessage(context, NOT_A_STRING_ID, object, MessageFactory.getLabel(context, component)));
    }
}
 
Example #22
Source File: TrimConverterTest.java    From development with Apache License 2.0 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 #23
Source File: DurationConverterTest.java    From development with Apache License 2.0 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 #24
Source File: TrimConverterTest.java    From development with Apache License 2.0 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 #25
Source File: POServiceConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Test for getting value.
 * 
 * @throws ParseException
 */
@Test
public void testGetAsObject() throws ConverterException, ParseException {
    UIComponent component = getComponent();
    POService actual = (POService) converter.getAsObject(context,
            component, poServiceAsString);
    Assert.assertEquals(actual.getKey(), 10001);
    Assert.assertEquals(actual.getPictureUrl(),
            "/image?type=SERVICE_IMAGE&amp;serviceKey=10001");
    Assert.assertEquals(actual.getProviderName(), "Fujitsu");
    Assert.assertEquals(actual.getServiceName(),
            "Hello Kitty November 6.66 1234:");
    Assert.assertEquals(actual.getStatusSymbol(), "status_NOT_ACTIVE");
    Assert.assertEquals(actual.getVersion(), 5);
}
 
Example #26
Source File: DurationConverterTest.java    From development with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAsObjectGermanDecimalSeparator()
        throws ConverterException {
    UIComponent component = ConverterTestHelper.getComponent(false, null,
            null, "duration");
    context.setLocale(Locale.GERMAN);
    Object result = converter.getAsObject(context, component, "1.00");
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals(
            String.valueOf(DurationValidation.MILLISECONDS_PER_DAY * 100),
            result);
}
 
Example #27
Source File: TrimConverterTest.java    From development with Apache License 2.0 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 #28
Source File: TrimConverterTest.java    From development with Apache License 2.0 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 #29
Source File: PaddingConverter.p.vm.java    From javaee-lab with Apache License 2.0 5 votes vote down vote up
private int getPadding(FacesContext context, UIComponent component) {
    if (component.getAttributes() != null && component.getAttributes().containsKey(PADDING_PARAMETER)) {
        return Integer.valueOf((String) component.getAttributes().get(PADDING_PARAMETER));
    } else {
        String message = messageSource.getMessage(PADDING_ID, null, context.getViewRoot().getLocale());
        throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, message, null));
    }
}
 
Example #30
Source File: SailfishUtilityURIConverter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public String getAsString(FacesContext paramFacesContext, UIComponent paramUIComponent, Object paramObject) {
    if(paramObject instanceof SailfishURI) {
        return ((SailfishURI)paramObject).toString();
    }

    throw new ConverterException("paramObject is not an instance of " + SailfishURI.class.getSimpleName());
}