Package org.constretto.model

Examples of org.constretto.model.CPrimitive


                        Configuration configurationAnnotation = (Configuration) parameterAnnotation;
                        expression = configurationAnnotation.value();
                        required = configurationAnnotation.required();
                        if (hasAnnotationDefaults(configurationAnnotation)) {
                            if (configurationAnnotation.defaultValueFactory().equals(Configuration.EmptyValueFactory.class)) {
                                defaultValue = ValueConverterRegistry.convert(parameterTargetClass, parameterTargetClass, new CPrimitive(configurationAnnotation.defaultValue()));
                            } else {
                                ConfigurationDefaultValueFactory valueFactory = configurationAnnotation.defaultValueFactory().newInstance();
                                defaultValue = valueFactory.getDefaultValue();
                            }
                        }
View Full Code Here


                                field.set(objectToConfigure, processAndConvert(fieldType, expression));
                            }
                        } else {
                            if (hasAnnotationDefaults(configurationAnnotation)) {
                                if (configurationAnnotation.defaultValueFactory().equals(Configuration.EmptyValueFactory.class)) {
                                    field.set(objectToConfigure, ValueConverterRegistry.convert(fieldType, fieldType, new CPrimitive(configurationAnnotation.defaultValue())));
                                } else {
                                    ConfigurationDefaultValueFactory valueFactory = configurationAnnotation.defaultValueFactory().newInstance();
                                    field.set(objectToConfigure, valueFactory.getDefaultValue());
                                }
                            } else if (configurationAnnotation.required()) {
View Full Code Here

*/
public class EnumValueConverterRegistryTest {

    @Test
    public void conversionOfKnownEnumValue() throws Exception {
        MockEnum value1 = (MockEnum) ValueConverterRegistry.convert(MockEnum.class, MockEnum.class, new CPrimitive("Value1"));
        assertEquals("Wrong value.", value1, MockEnum.Value1);
    }
View Full Code Here

        assertEquals("Wrong value.", value1, MockEnum.Value1);
    }

    @Test(expected = ConstrettoConversionException.class)
    public void conversionOfUnknownEnumValue() throws Exception {
        ValueConverterRegistry.convert(MockEnum.class, MockEnum.class,new CPrimitive("Unknown"));
    }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void simpleListConversion() {
    final List<CValue> list = new ArrayList<CValue>();
    list.add(new CPrimitive("hei"));
    final List<String> convertedList = (List<String>) ValueConverterRegistry.convert(String.class, String.class, new CArray(list));

    Assert.assertNotNull(convertedList);
    Assert.assertTrue(convertedList.size() == 1);
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void simpleMapConversion() {
    final Map<String, CValue> map = new HashMap<String, CValue>();
    map.put("hei", new CPrimitive("hallo"));
    final Map<String,String> convertedMap = (Map<String,String>) ValueConverterRegistry.convert(String.class, String.class, new CObject(map));

    Assert.assertNotNull(convertedMap);
    Assert.assertTrue(convertedMap.size() == 1);
  }
View Full Code Here

    @Test
  public void mapListConversion() {
    final List<CValue> list = new ArrayList<CValue>();
    final Map<String, CValue> data = new HashMap<String, CValue>();
    data.put("key", new CPrimitive("value"));
    list.add(new CObject(data));

    final List<Map<String, String>> convertedList = (List<Map<String, String>>) ValueConverterRegistry.convert(String.class,
        String.class, new CArray(list));
View Full Code Here

    }

    @Test(expected = ConstrettoException.class)
    public void testConvertUnsopportedClassConversion() {
    final Map<String, CValue> map = new HashMap<String, CValue>();
    map.put("hei", new CPrimitive("hallo"));
    ValueConverterRegistry.convert(getClass(), getClass(), new CObject(map));
    }
View Full Code Here

public class FileConverterTest {

    @Test
    public void simpleFileConversion() {
        File file = new File(".");
        File convertedFile = (File) convert(File.class, File.class, new CPrimitive("."));
        assertEquals(file, convertedFile);
        assertTrue(convertedFile.isDirectory());
        assertTrue(convertedFile.canRead());
    }
View Full Code Here

TOP

Related Classes of org.constretto.model.CPrimitive

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.