Package org.eclipse.sapphire

Examples of org.eclipse.sapphire.MasterConversionService


   
    @Test
   
    public void testXmlResourceToXmlElement() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        final XmlResourceStore xmlResourceStore = new XmlResourceStore();
        final RootXmlResource xmlResource = new RootXmlResource( xmlResourceStore );
        final XmlConversionTestElement elementOnXml = XmlConversionTestElement.TYPE.instantiate( xmlResource );
       
        xmlResource.save();

        final XmlElement xmlElement = service.convert( xmlResource, XmlElement.class );
       
        assertNotNull( xmlElement );
        assertSame( xmlElement, xmlResource.getXmlElement() );
        assertSame( xmlElement, xmlResource.adapt( XmlElement.class ) );
       
        final XmlConversionTestElement.ListEntry childElement = elementOnXml.getList().insert();
        final XmlElement childXmlElement = service.convert( childElement.resource(), XmlElement.class );
        final XmlResource childXmlResource = (XmlResource) childElement.resource();
       
        assertNotNull( childXmlElement );
        assertSame( childXmlElement, childXmlResource.getXmlElement() );
        assertSame( childXmlElement, childXmlResource.adapt( XmlElement.class ) );
View Full Code Here


   
    @Test

    public void testStringToJavaIdentifier() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( new JavaIdentifier( "_" ), service.convert( "_", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "$" ), service.convert( "$", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "a" ), service.convert( "a", JavaIdentifier.class ) );

        assertEquals( new JavaIdentifier( "_abc" ), service.convert( "_abc", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "$abc" ), service.convert( "$abc", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "aabc" ), service.convert( "aabc", JavaIdentifier.class ) );

        assertEquals( new JavaIdentifier( "AbC_" ), service.convert( "AbC_", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "AbC$" ), service.convert( "AbC$", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "AbCa" ), service.convert( "AbCa", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "AbC1" ), service.convert( "AbC1", JavaIdentifier.class ) );
       
        assertEquals( new JavaIdentifier( "abc123" ), service.convert( "abc123", JavaIdentifier.class ) );
        assertEquals( new JavaIdentifier( "abc$_123" ), service.convert( "abc$_123", JavaIdentifier.class ) );

        assertNull( service.convert( "1", JavaIdentifier.class ) );
        assertNull( service.convert( "1abc", JavaIdentifier.class ) );
        assertNull( service.convert( "ab#c", JavaIdentifier.class ) );
        assertNull( service.convert( "ab.c", JavaIdentifier.class ) );
    }
View Full Code Here

   
    @Test
   
    public void testStringToDouble() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( Double.valueOf( -15.773523D ), service.convert( "-15.773523", Double.class ) );
        assertEquals( Double.valueOf( 0.0D ), service.convert( "0.0", Double.class ) );
        assertEquals( Double.valueOf( 15.773523D ), service.convert( "15.773523", Double.class ) );
    }
View Full Code Here

   
    @Test

    public void testDoubleToString() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( "-15.773523", service.convert( Double.valueOf( -15.773523D ), String.class ) );
        assertEquals( "0.0", service.convert( Double.valueOf( 0.0D ), String.class ) );
        assertEquals( "15.773523", service.convert( Double.valueOf( 15.773523D ), String.class ) );
    }
View Full Code Here

   
    @Test
   
    public void testStringToBigInteger() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( new BigInteger( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808" ), service.convert( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808", BigInteger.class ) );
        assertEquals( new BigInteger( "-9223372036854775808" ), service.convert( "-9223372036854775808", BigInteger.class ) );
        assertEquals( new BigInteger( "-2147483648" ), service.convert( "-2147483648", BigInteger.class ) );
        assertEquals( new BigInteger( "-32768" ), service.convert( "-32768", BigInteger.class ) );
        assertEquals( new BigInteger( "-128" ), service.convert( "-128", BigInteger.class ) );
        assertEquals( new BigInteger( "-48" ), service.convert( "-48", BigInteger.class ) );
        assertEquals( new BigInteger( "0" ), service.convert( "0", BigInteger.class ) );
        assertEquals( new BigInteger( "47" ), service.convert( "47", BigInteger.class ) );
        assertEquals( new BigInteger( "127" ), service.convert( "127", BigInteger.class ) );
        assertEquals( new BigInteger( "32767" ), service.convert( "32767", BigInteger.class ) );
        assertEquals( new BigInteger( "2147483647" ), service.convert( "2147483647", BigInteger.class ) );
        assertEquals( new BigInteger( "9223372036854775807" ), service.convert( "9223372036854775807", BigInteger.class ) );
        assertEquals( new BigInteger( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807" ), service.convert( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807", BigInteger.class ) );
    }
View Full Code Here

   
    @Test

    public void testBigIntegerToString() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808", service.convert( new BigInteger( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808" ), String.class ) );
        assertEquals( "-9223372036854775808", service.convert( new BigInteger( "-9223372036854775808" ), String.class ) );
        assertEquals( "-2147483648", service.convert( new BigInteger( "-2147483648" ), String.class ) );
        assertEquals( "-32768", service.convert( new BigInteger( "-32768" ), String.class ) );
        assertEquals( "-128", service.convert( new BigInteger( "-128" ), String.class ) );
        assertEquals( "-48", service.convert( new BigInteger( "-48" ), String.class ) );
        assertEquals( "0", service.convert( new BigInteger( "0" ), String.class ) );
        assertEquals( "47", service.convert( new BigInteger( "47" ), String.class ) );
        assertEquals( "127", service.convert( new BigInteger( "127" ), String.class ) );
        assertEquals( "32767", service.convert( new BigInteger( "32767" ), String.class ) );
        assertEquals( "2147483647", service.convert( new BigInteger( "2147483647" ), String.class ) );
        assertEquals( "9223372036854775807", service.convert( new BigInteger( "9223372036854775807" ), String.class ) );
        assertEquals( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807", service.convert( new BigInteger( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807" ), String.class ) );
    }
View Full Code Here

   
    @Test
   
    public void testStringToBigDecimal() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( new BigDecimal( "-922337203685477580892233720368547758089223372036854775808.92233720368547758089223372036854775808" ), service.convert( "-922337203685477580892233720368547758089223372036854775808.92233720368547758089223372036854775808", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808" ), service.convert( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-9223372036854775808" ), service.convert( "-9223372036854775808", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-2147483648" ), service.convert( "-2147483648", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-32768" ), service.convert( "-32768", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-128" ), service.convert( "-128", BigDecimal.class ) );
        assertEquals( new BigDecimal( "-48" ), service.convert( "-48", BigDecimal.class ) );
        assertEquals( new BigDecimal( "0" ), service.convert( "0", BigDecimal.class ) );
        assertEquals( new BigDecimal( "47" ), service.convert( "47", BigDecimal.class ) );
        assertEquals( new BigDecimal( "127" ), service.convert( "127", BigDecimal.class ) );
        assertEquals( new BigDecimal( "32767" ), service.convert( "32767", BigDecimal.class ) );
        assertEquals( new BigDecimal( "2147483647" ), service.convert( "2147483647", BigDecimal.class ) );
        assertEquals( new BigDecimal( "9223372036854775807" ), service.convert( "9223372036854775807", BigDecimal.class ) );
        assertEquals( new BigDecimal( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807" ), service.convert( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807", BigDecimal.class ) );
        assertEquals( new BigDecimal( "922337203685477580792233720368547758079223372036854775807.92233720368547758079223372036854775807" ), service.convert( "922337203685477580792233720368547758079223372036854775807.92233720368547758079223372036854775807", BigDecimal.class ) );
    }
View Full Code Here

   
    @Test

    public void testBigDecimalToString() throws Exception
    {
        final MasterConversionService service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( "-922337203685477580892233720368547758089223372036854775808.92233720368547758089223372036854775808", service.convert( new BigDecimal( "-922337203685477580892233720368547758089223372036854775808.92233720368547758089223372036854775808" ), String.class ) );
        assertEquals( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808", service.convert( new BigDecimal( "-92233720368547758089223372036854775808922337203685477580892233720368547758089223372036854775808" ), String.class ) );
        assertEquals( "-9223372036854775808", service.convert( new BigDecimal( "-9223372036854775808" ), String.class ) );
        assertEquals( "-2147483648", service.convert( new BigDecimal( "-2147483648" ), String.class ) );
        assertEquals( "-32768", service.convert( new BigDecimal( "-32768" ), String.class ) );
        assertEquals( "-128", service.convert( new BigDecimal( "-128" ), String.class ) );
        assertEquals( "-48", service.convert( new BigDecimal( "-48" ), String.class ) );
        assertEquals( "0", service.convert( new BigDecimal( "0" ), String.class ) );
        assertEquals( "47", service.convert( new BigDecimal( "47" ), String.class ) );
        assertEquals( "127", service.convert( new BigDecimal( "127" ), String.class ) );
        assertEquals( "32767", service.convert( new BigDecimal( "32767" ), String.class ) );
        assertEquals( "2147483647", service.convert( new BigDecimal( "2147483647" ), String.class ) );
        assertEquals( "9223372036854775807", service.convert( new BigDecimal( "9223372036854775807" ), String.class ) );
        assertEquals( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807", service.convert( new BigDecimal( "92233720368547758079223372036854775807922337203685477580792233720368547758079223372036854775807" ), String.class ) );
        assertEquals( "922337203685477580792233720368547758079223372036854775807.92233720368547758079223372036854775807", service.convert( new BigDecimal( "922337203685477580792233720368547758079223372036854775807.92233720368547758079223372036854775807" ), String.class ) );
    }
View Full Code Here

   
    @Test

    public void testStringToDate() throws Exception
    {
        MasterConversionService service;
       
        service = Sapphire.service( MasterConversionService.class );
       
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd" ).parse( "2013-01-15" ), service.convert( "2013-01-15", Date.class ) );
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ).parse( "2013-01-15T18:38:24" ), service.convert( "2013-01-15T18:38:24", Date.class ) );
        assertNull( service.convert( "2013.01.15", Date.class ) );
       
        DateConversionTestElement element = DateConversionTestElement.TYPE.instantiate();
       
        service = element.property( DateConversionTestElement.PROP_DATE_1 ).service( MasterConversionService.class );
       
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd" ).parse( "2013-01-15" ), service.convert( "2013-01-15", Date.class ) );
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ).parse( "2013-01-15T18:38:24" ), service.convert( "2013-01-15T18:38:24", Date.class ) );
        assertNull( service.convert( "2013.01.15", Date.class ) );
       
        service = element.property( DateConversionTestElement.PROP_DATE_2 ).service( MasterConversionService.class );
       
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd" ).parse( "2013-01-15" ), service.convert( "2013.01.15", Date.class ) );
        assertEquals( new SimpleDateFormat( "yyyy-MM-dd" ).parse( "2013-01-15" ), service.convert( "01/15/2013", Date.class ) );
        assertNull( service.convert( "2013-01-15", Date.class ) );
    }
View Full Code Here

    {
        final SimpleDateFormat fullDateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss'.'SSSZ" );
        final Date date = fullDateFormat.parse( "2013-01-15T18:38:24.000-0800" );
        final DateConversionTestElement element = DateConversionTestElement.TYPE.instantiate();
       
        MasterConversionService service;
       
        service = Sapphire.service( MasterConversionService.class );
        assertEquals( fullDateFormat.format( date ), service.convert( date, String.class ) );

        service = element.property( DateConversionTestElement.PROP_DATE_1 ).service( MasterConversionService.class );
        assertEquals( fullDateFormat.format( date ), service.convert( date, String.class ) );
       
        service = element.property( DateConversionTestElement.PROP_DATE_2 ).service( MasterConversionService.class );
        assertEquals( "2013.01.15", service.convert( date, String.class ) );
    }
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.MasterConversionService

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.