1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.octo.captcha.component.image.wordtoimage;
20
21 import java.awt.Color;
22 import java.awt.image.ImageFilter;
23 import java.awt.image.ReplicateScaleFilter;
24
25 import junit.framework.TestCase;
26
27 import com.octo.captcha.CaptchaException;
28 import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
29 import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator;
30 import com.octo.captcha.component.image.deformation.ImageDeformation;
31 import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
32 import com.octo.captcha.component.image.fontgenerator.FontGenerator;
33 import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
34 import com.octo.captcha.component.image.textpaster.SimpleTextPaster;
35 import com.octo.captcha.component.image.textpaster.TextPaster;
36
37 /***
38 * <p>Description: </p>
39 *
40 * @author <a href="mailto:mga@octo.com">Mathieu Gandin</a>
41 * @version 1.0
42 */
43 public class DeformedComposedWordToImageTest extends TestCase {
44
45 private DeformedComposedWordToImage deformedComposedWordToImage;
46 private Integer minAcceptedWordLength = new Integer(1);
47 private Integer maxAcceptedWordLength = new Integer(10);
48 private Integer imageHeight = new Integer(100);
49 private Integer imageWidth = new Integer(100);
50 private Integer minFontSize = new Integer(10);
51 private Integer maxFontSize = new Integer(10);
52
53
54 public void setUp() {
55
56 BackgroundGenerator background = new GradientBackgroundGenerator(this.imageHeight, this.imageWidth, Color.black, Color.white);
57 FontGenerator fontGenerator = new RandomFontGenerator(this.minFontSize, this.maxFontSize);
58 TextPaster textPaster = new SimpleTextPaster(this.minAcceptedWordLength, this.maxAcceptedWordLength, Color.blue);
59
60 ImageFilter backFilter = new ReplicateScaleFilter(background.getImageWidth(),
61 background.getImageHeight());
62
63 ImageFilter textFilter = new ReplicateScaleFilter(background.getImageWidth(),
64 background.getImageHeight());
65
66 ImageFilter finalFilter = new ReplicateScaleFilter(background.getImageWidth(),
67 background.getImageHeight());
68
69 ImageFilter[] backFilters = {backFilter};
70
71 ImageFilter[] textFilters = {textFilter};
72
73 ImageFilter[] finalFilters = {finalFilter};
74
75 ImageDeformation back = new ImageDeformationByFilters(backFilters);
76 ImageDeformation text = new ImageDeformationByFilters(textFilters);
77 ImageDeformation finalD = new ImageDeformationByFilters(finalFilters);
78 this.deformedComposedWordToImage = new DeformedComposedWordToImage(fontGenerator,
79 background,
80 textPaster,
81 back,
82 text,
83 finalD);
84 }
85
86 public void testGetImage() throws CaptchaException {
87 String test = "test";
88 assertNotNull(this.deformedComposedWordToImage.getImage(test));
89 }
90
91 public void testGetImageNull() {
92 try {
93 this.deformedComposedWordToImage.getImage(null);
94 fail();
95 } catch (CaptchaException e) {
96 assertNotNull(e);
97 }
98 }
99
100 }