⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templatefactorytest.java

📁 openwave公司的用于彩信开发的MM7协议实现java原代码,决对超值.
💻 JAVA
字号:
package com.openwave.mms.content.test;import java.util.Properties;import com.openwave.mms.content.*;import junit.framework.TestCase;public class TemplateFactoryTest extends TestCase {    public TemplateFactoryTest( String name ) {        super(name);    }    protected void setUp() {    }    protected void tearDown() {    }    public void testInitialize() {        assertTrue( "default template before initializing with props",                    TemplateFactory.getInstance().getTemplate( null ) instanceof DefaultTemplate );        Properties p = new Properties();        p.setProperty( "content.template.1.name", "textontop" );        p.setProperty( "content.template.1.text.top", "10" );        p.setProperty( "content.template.1.text.left", "20" );        p.setProperty( "content.template.1.text.width", "30%" );        p.setProperty( "content.template.1.text.height", "40%" );        p.setProperty( "content.template.1.text.fit", "hidden" );        p.setProperty( "content.template.1.image.top", "50%" );        p.setProperty( "content.template.1.image.left", "60" );        p.setProperty( "content.template.1.image.width", "70%" );        p.setProperty( "content.template.1.image.height", "80%" );        p.setProperty( "content.template.1.image.fit", "hidden" );        p.setProperty( "content.template.2.name", "sidebyside" );        p.setProperty( "content.template.2.image.top", "15" );        p.setProperty( "content.template.2.image.left", "25" );        p.setProperty( "content.template.2.image.width", "35%" );        p.setProperty( "content.template.2.image.height", "45%" );        p.setProperty( "content.template.2.image.fit", "hidden" );        p.setProperty( "content.template.2.text.top", "55" );        p.setProperty( "content.template.2.text.left", "65%" );        p.setProperty( "content.template.2.text.width", "75%" );        p.setProperty( "content.template.2.text.height", "85%" );        p.setProperty( "content.template.2.text.fit", "hidden" );        TemplateFactory.getInstance().initialize( p );        Template dflt = TemplateFactory.getInstance().getTemplate( null );        assertNotNull( "default template", dflt );        assertTrue( "default template", ! ( dflt instanceof DefaultTemplate ) );        Template first = TemplateFactory.getInstance().getTemplate( "TextOnTop" );        assertNull( "name case check", first );        first = TemplateFactory.getInstance().getTemplate( "textontop" );        assertNotNull( "first template", first );        RegionAttributes textAttr = first.getTextAttributes();        assertNotNull( "first text attributes", textAttr );        IntOrPercent textTop = textAttr.getTop();        assertNotNull( "text attributes top", textTop );        assertEquals( "text attributes top", textTop.getValue(), 10 );        assertEquals( "text attributes top", textTop.getType(), IntOrPercent.INT );        IntOrPercent textLeft = textAttr.getLeft();        assertNotNull( "text attributes left", textLeft );        assertEquals( "text attributes left", textLeft.getValue(), 20 );        assertEquals( "text attributes left", textLeft.getType(), IntOrPercent.INT );        IntOrPercent textWidth = textAttr.getWidth();        assertNotNull( "text attributes width", textWidth );        assertEquals( "text attributes width", textWidth.getValue(), 30 );        assertEquals( "text attributes width", textWidth.getType(), IntOrPercent.PERCENT );        IntOrPercent textHeight = textAttr.getHeight();        assertNotNull( "text attributes height", textHeight );        assertEquals( "text attributes height", textHeight.getValue(), 40 );        assertEquals( "text attributes height", textHeight.getType(), IntOrPercent.PERCENT );        Fit textFit = textAttr.getFit();        assertNotNull( "text attributes fit", textFit );        assertEquals( "text attributes fit", textFit, Fit.HIDDEN );        RegionAttributes imageAttr = first.getImageAttributes();        assertNotNull( "first image attributes", imageAttr );        IntOrPercent imageTop = imageAttr.getTop();        assertNotNull( "image attributes top", imageTop );        assertEquals( "image attributes top", imageTop.getValue(), 50 );        assertEquals( "image attributes top", imageTop.getType(), IntOrPercent.PERCENT );        IntOrPercent imageLeft = imageAttr.getLeft();        assertNotNull( "image attributes left", imageLeft );        assertEquals( "image attributes left", imageLeft.getValue(), 60 );        assertEquals( "image attributes left", imageLeft.getType(), IntOrPercent.INT );        IntOrPercent imageWidth = imageAttr.getWidth();        assertNotNull( "image attributes width", imageWidth );        assertEquals( "image attributes width", imageWidth.getValue(), 70 );        assertEquals( "image attributes width", imageWidth.getType(), IntOrPercent.PERCENT );        IntOrPercent imageHeight = imageAttr.getHeight();        assertNotNull( "image attributes height", imageHeight );        assertEquals( "image attributes height", imageHeight.getValue(), 80 );        assertEquals( "image attributes height", imageHeight.getType(), IntOrPercent.PERCENT );        Fit imageFit = imageAttr.getFit();        assertNotNull( "image attributes fit", imageFit );        assertEquals( "image attributes fit", imageFit, Fit.HIDDEN );        Template second = TemplateFactory.getInstance().getTemplate( "sidebyside" );        assertNotNull( "second template", second );        RegionAttributes secondTextAttr = second.getTextAttributes();        RegionAttributes secondImageAttr = second.getImageAttributes();        assertNotNull( "second image attributes", secondImageAttr );        assertNotNull( "second text attributes", secondTextAttr );        IntOrPercent secondTextTop = secondTextAttr.getTop();        assertNotNull( "secondText attributes top", secondTextTop );        assertEquals( "secondText attributes top", secondTextTop.getValue(), 55 );        assertEquals( "secondText attributes top", secondTextTop.getType(), IntOrPercent.INT );        IntOrPercent secondTextLeft = secondTextAttr.getLeft();        assertNotNull( "secondText attributes left", secondTextLeft );        assertEquals( "secondText attributes left", secondTextLeft.getValue(), 65 );        assertEquals( "secondText attributes left", secondTextLeft.getType(), IntOrPercent.PERCENT );        IntOrPercent secondTextWidth = secondTextAttr.getWidth();        assertNotNull( "secondText attributes width", secondTextWidth );        assertEquals( "secondText attributes width", secondTextWidth.getValue(), 75 );        assertEquals( "secondText attributes width", secondTextWidth.getType(), IntOrPercent.PERCENT );        IntOrPercent secondTextHeight = secondTextAttr.getHeight();        assertNotNull( "secondText attributes height", secondTextHeight );        assertEquals( "secondText attributes height", secondTextHeight.getValue(), 85 );        assertEquals( "secondText attributes height", secondTextHeight.getType(), IntOrPercent.PERCENT );        Fit secondTextFit = secondTextAttr.getFit();        assertNotNull( "secondText attributes fit", secondTextFit );        assertEquals( "secondText attributes fit", secondTextFit, Fit.HIDDEN );        IntOrPercent secondImageTop = secondImageAttr.getTop();        assertNotNull( "secondImage attributes top", secondImageTop );        assertEquals( "secondImage attributes top", secondImageTop.getValue(), 15 );        assertEquals( "secondImage attributes top", secondImageTop.getType(), IntOrPercent.INT );        IntOrPercent secondImageLeft = secondImageAttr.getLeft();        assertNotNull( "secondImage attributes left", secondImageLeft );        assertEquals( "secondImage attributes left", secondImageLeft.getValue(), 25 );        assertEquals( "secondImage attributes left", secondImageLeft.getType(), IntOrPercent.INT );        IntOrPercent secondImageWidth = secondImageAttr.getWidth();        assertNotNull( "secondImage attributes width", secondImageWidth );        assertEquals( "secondImage attributes width", secondImageWidth.getValue(), 35 );        assertEquals( "secondImage attributes width", secondImageWidth.getType(), IntOrPercent.PERCENT );        IntOrPercent secondImageHeight = secondImageAttr.getHeight();        assertNotNull( "secondImage attributes height", secondImageHeight );        assertEquals( "secondImage attributes height", secondImageHeight.getValue(), 45 );        assertEquals( "secondImage attributes height", secondImageHeight.getType(), IntOrPercent.PERCENT );        Fit secondImageFit = secondImageAttr.getFit();        assertNotNull( "secondImage attributes fit", secondImageFit );        assertEquals( "secondImage attributes fit", secondImageFit, Fit.HIDDEN );        // test case: where .1 props are not defined, API default template        // should be used for default.        Properties p1 = new Properties();        p1.setProperty( "content.template.2.name", "sidebyside" );        p1.setProperty( "content.template.2.image.top", "0" );        p1.setProperty( "content.template.2.image.left", "0" );        p1.setProperty( "content.template.2.image.width", "50%" );        p1.setProperty( "content.template.2.image.height", "100%" );        p1.setProperty( "content.template.2.image.fit", "hidden" );        p1.setProperty( "content.template.2.text.top", "0" );        p1.setProperty( "content.template.2.text.left", "50%" );        p1.setProperty( "content.template.2.text.width", "50%" );        p1.setProperty( "content.template.2.text.height", "100%" );        p1.setProperty( "content.template.2.text.fit", "hidden" );        TemplateFactory.getInstance().initialize( p1 );        Template newDefault = TemplateFactory.getInstance().getTemplate( null );        assertNotNull( "new default template", newDefault );        assertTrue( "default template after initializing with props not having .1s",                    newDefault instanceof DefaultTemplate );        Template second1 = TemplateFactory.getInstance().getTemplate( "sidebyside" );        assertNotNull( "second template", second1 );        RegionAttributes second1TextAttr = second1.getTextAttributes();        RegionAttributes second1ImageAttr = second1.getImageAttributes();        assertNotNull( "second1 image attributes", second1ImageAttr );        assertNotNull( "second1 text attributes", second1TextAttr );        TemplateFactory.getInstance().newTemplate( "templateName",                                                   textAttr,                                                   imageAttr );        assertNotNull( "newTemplate test",                       TemplateFactory.getInstance().getTemplate( "templateName" ) );        Template noNameTempl = TemplateFactory.getInstance().newTemplate( null,                                                                          textAttr,                                                                          imageAttr );        assertNotNull( "newTemplate test", noNameTempl );        Template noNameTempl1 = TemplateFactory.getInstance().newTemplate( "",                                                                           textAttr,                                                                           imageAttr );        assertNotNull( "newTemplate test", noNameTempl1 );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -