Revision 1729

View differences:

org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/README.txt
1
====
2
    gvSIG. Desktop Geographic Information System.
3

  
4
    Copyright (C) 2007-2013 gvSIG Association.
5

  
6
    This program is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU General Public License
8
    as published by the Free Software Foundation; either version 2
9
    of the License, or (at your option) any later version.
10

  
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
15

  
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
    MA  02110-1301, USA.
20

  
21
    For any additional information, do not hesitate to contact us
22
    at info AT gvsig.com, or visit our website www.gvsig.com.
23
====
24

  
25
#set( $symbol_pound = '#' )
26
#set( $symbol_dollar = '$' )
27
#set( $symbol_escape = '\' )
28
Put into this folder the resources needed by your test classes.
29

  
30
This folder is added to the Tests classpath, so you can load any resources 
31
through the ClassLoader.
32

  
33
By default, in this folder you can find an example of log4j configuration,
34
prepared to log messages through the console, so logging works when you
35
run your tests classes.
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<!-- 
30
Log4J configuration file for unit tests execution.
31
 -->
32
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
33

  
34
	<!-- Appender configuration to show logging messages through the console -->
35
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
36
		<layout class="org.apache.log4j.PatternLayout">
37
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]  %m%n" />
38
		</layout>
39
	</appender>
40

  
41
	<!-- 
42
	Activate logging messages of DEBUG level of higher only for the
43
	org.gvsig.tools packages.
44
	You can put full classes names or packages instead, to configure
45
	logging for all the classes and subpackages of the package.
46
	-->
47
	<category name="org.gvsig.tools">
48
		<priority value="TRACE" />
49
	</category>
50

  
51
	<!-- 
52
	By default, show only logging messages of INFO level or higher, 
53
	through the previously configured CONSOLE appender. 
54
	-->
55
	<root>
56
		<priority value="TRACE" />
57
		<appender-ref ref="CONSOLE" />
58
	</root>
59
</log4j:configuration>
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/packageutils/package1.info
1
code=org.gvsig.myplugin
2
name=myplugin
3
description=Test
4
version=1.0.0
5
build=1
6
state=RC1
7
official=true
8
type=plugin
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/attrBasedImportDynClassTest.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectBasicTypes">
30
      <description>MyObjectBasicTypes test definition</description>
31
      <fields>
32
        <field	name="a" type="integer" mandatory="true" persistent="true" 
33
        		minValue="0x0" maxValue="100" defaultValue="1"
34
          		group="Numbers" order="12">
35
        </field>
36
        <field	name="b" type="long" mandatory="true" persistent="true" 
37
        		defaultValue="2"
38
          		group="Numbers"/>
39
        <field	name="c" type="double" mandatory="false" persistent="true" 
40
        		defaultValue="1.1" minValue="0.0" maxValue="100.0" 
41
          		group="Numbers"/>
42
        <field	name="d" type="float" mandatory="false" 
43
        		minValue="0.0" maxValue="100.0" 
44
          		group="Numbers">
45
          <persistent>true</persistent>
46
          <defaultValue>1.2</defaultValue>
47
        </field>
48

  
49
        <field	name="e" type="boolean" mandatory="true"> 
50
          <persistent>false</persistent>
51
          <defaultValue>true</defaultValue>
52
          <availableValues>
53
            <value label="True">true</value>
54
            <value label="False">false</value>
55
          </availableValues>
56
        </field>
57

  
58
        <field name="f" type="string" mandatory="true" persistent="true" defaultValue="red">
59
          <availableValues>
60
            <value label="Red">red</value>
61
            <value label="Green">green</value>
62
            <value label="Blue">blue</value>
63
          </availableValues>
64
        </field>
65
        <field name="g" type="date" mandatory="true" persistent="true"/>
66
      </fields>
67
    </class>
68

  
69
    <class name="MyObjectBasicTypes2" namespace="test1">
70
      <extends>
71
        <class name="MyObjectBasicTypes"/>
72
      </extends>
73
      <fields>
74
      </fields>
75
    </class>
76

  
77
    <class name="MyObjectBasicTypes3">
78
      <extends>
79
        <class name="MyObjectBasicTypes2" namespace="test1"/>
80
      </extends>
81
      <fields>
82
      </fields>
83
    </class>
84

  
85
    <class name="MyObjectBasicTypes4">
86
      <extends>
87
        <class name="MyObjectBasicTypes2" namespace="test1"/>
88
      </extends>
89
      <fields>
90
        <field	name="obj" type="Object" classOfValue="org.gvsig.tools.evaluator.Evaluator"/>
91
        <field	name="objs" type="List" classOfItems="org.gvsig.tools.visitor.Visitor"/>
92
      </fields>
93
    </class>
94

  
95
  </classes>
96
</definitions>  
0 97

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/tagBasedImportDynClassTest.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions>
28
  <version>1.0.0</version>
29
  <classes>
30
    <class>
31
      <name>MyObjectBasicTypes</name>
32
      <description>MyObjectBasicTypes test definition</description>
33
      <fields>
34
        <field>
35
          <name>a</name>
36
          <type>integer</type>
37
          <mandatory>true</mandatory>
38
          <persistent>true</persistent>
39
          <minValue>0</minValue>
40
          <maxValue>100</maxValue>
41
          <defaultValue>1</defaultValue>
42
          <group>Numbers</group>
43
          <order>12</order>
44
        </field>
45
        <field>
46
          <name>b</name>
47
          <type>long</type>
48
          <mandatory>true</mandatory>
49
          <persistent>true</persistent>
50
          <defaultValue>2</defaultValue>
51
          <group>Numbers</group>
52
        </field>
53
        <field>
54
          <name>c</name>
55
          <type>double</type>
56
          <mandatory>false</mandatory>
57
          <persistent>true</persistent>
58
          <minValue>0.0</minValue>
59
          <maxValue>100.0</maxValue>
60
          <defaultValue>1.1</defaultValue>
61
          <group>Numbers</group>
62
        </field>
63
        <field>
64
          <name>d</name>
65
          <type>float</type>
66
          <mandatory>false</mandatory>
67
          <persistent>true</persistent>
68
          <defaultValue>1.2</defaultValue>
69
          <group>Numbers</group>
70
        </field>
71
        <field>
72
          <name>e</name>
73
          <type>boolean</type>
74
          <mandatory>true</mandatory>
75
          <persistent>false</persistent>
76
          <defaultValue>true</defaultValue>
77
          <availableValues>
78
            <valueItem>
79
              <label>True</label>
80
              <value>true</value>
81
            </valueItem>
82
            <valueItem>
83
              <label>False</label>
84
              <value>false</value>
85
            </valueItem>
86
          </availableValues>
87
        </field>
88
        <field>
89
          <name>f</name>
90
          <type>string</type>
91
          <mandatory>true</mandatory>
92
          <persistent>true</persistent>
93
          <defaultValue>red</defaultValue>
94
          <availableValues>
95
            <valueItem>
96
              <label>Red</label>
97
              <value>red</value>
98
            </valueItem>
99
            <valueItem>
100
              <label>Green</label>
101
              <value>green</value>
102
            </valueItem>
103
            <valueItem>
104
              <label>Blue</label>
105
              <value>blue</value>
106
            </valueItem>
107
          </availableValues>
108
        </field>
109
        <field>
110
          <name>g</name>
111
          <type>date</type>
112
          <mandatory>true</mandatory>
113
          <persistent>true</persistent>
114
        </field>
115
      </fields>
116
    </class>
117

  
118

  
119
    <class name="MyObjectBasicTypes2" namespace="test1">
120
      <extends>
121
        <class>MyObjectBasicTypes</class>
122
      </extends>
123
      <fields>
124
      </fields>
125
    </class>
126

  
127
    <class name="MyObjectBasicTypes3">
128
      <extends>
129
        <class namespace="test1">MyObjectBasicTypes2</class> 
130
      </extends>
131
      <fields>
132
      </fields>
133
    </class>
134

  
135
    <class name="MyObjectBasicTypes4">
136
      <extends>
137
        <class name="MyObjectBasicTypes2" namespace="test1"/>
138
      </extends>
139
      <fields>
140
        <field>
141
          <name>obj</name>
142
          <type>Object</type>
143
          <classOfValue>org.gvsig.tools.evaluator.Evaluator</classOfValue>
144
        </field>
145
        <field>
146
          <name>objs</name>
147
          <type>List</type>
148
          <classOfItems>org.gvsig.tools.visitor.Visitor</classOfItems>
149
        </field>
150
      </fields>
151
    </class>
152

  
153

  
154
  </classes>
155
</definitions>
0 156

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/dynobject/DynClassTemplate.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions>
28
  <version>1.0.0</version>
29
  <classes>
30
    <class>
31
      <name></name>
32
      <namespace></namespace>
33
      <description></description>
34
      <superClassNames>
35
        <superClassName></superClassName>
36
        <superClassName></superClassName>
37
      </superClassNames>
38
      <fields>
39
        <field>
40
          <name></name>
41
          <type></type>
42
          <subtype></subtype>
43
          <description></description>
44
          <isMandatory></isMandatory>
45
          <isPersistent></isPersistent>
46
          <minValue></minValue>
47
          <maxValue></maxValue>
48
          <classOfValue></classOfValue>
49
          <defaultValue></defaultValue>
50
          <group></group>
51
          <availableValues>
52
            <valueItem>
53
              <label></label>
54
              <value></value>
55
            </valueItem>
56
            <valueItem>
57
              <label></label>
58
              <value></value>
59
            </valueItem>
60
          </availableValues>
61
        </field>
62
      </fields>
63
    </class>
64
  </classes>
65
</definitions>  
0 66

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/persistence/BasicTypes2Test.xml
1
<?xml version="1.0"?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectBasicTypes">
30
      <description>MyObjectBasicTypes Persistence definition</description>
31
      <fields>
32
        <field name="a" type="integer"/>
33
        <field name="b" type="long"/>
34
        <field name="c" type="double"/>
35
        <field name="d" type="float"/>
36
        <field name="e" type="boolean"/>
37
        <field name="f" type="string"/>
38
        <field name="g" type="date"/>
39
      </fields>
40
    </class>
41
    <class name="Extends1Test">
42
      <description>Test the extends with namespace</description>
43
      <extends>
44
      	<class name="MyObjectBasicTypes"/>
45
      </extends>
46
      <fields>
47
      </fields>
48
    </class>
49
    <class name="MyObjectComplexTypes">
50
      <description>Test the extends with namespace</description>
51
      <extends>
52
      	<class name="MyObjectBasicTypes"/>
53
      </extends>
54
      <fields>
55
      	<field name="child" type="dynObject" subtype="MyObjectBasicTypes"></field>
56
      </fields>
57
    </class>
58
  </classes>
59
</definitions>  
0 60

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/resources/org/gvsig/tools/persistence/DynTypesTest.xml
1
<?xml version= "1.0 "?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 2
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<definitions version="1.0.0">
28
  <classes>
29
    <class name="MyObjectDynTypes">
30
      <description>MyObjectMapType Persistence definition</description>
31
      <fields>
32
      	<field>
33
          <name>mapa</name>
34
          <type>Map</type>
35
          <mandatory>true</mandatory>
36
          <classOfItems>java.lang.String</classOfItems>
37
        </field>
38
      	<field>
39
          <name>conjunto</name>
40
          <type>Set</type>
41
          <mandatory>true</mandatory>
42
          <classOfItems>java.lang.String</classOfItems>
43
        </field>
44
      	<field>
45
          <name>lista</name>
46
          <type>List</type>
47
          <mandatory>true</mandatory>
48
          <classOfItems>java.lang.String</classOfItems>
49
        </field>
50
      	<field>
51
          <name>viewPort</name>
52
          <type>Object</type>
53
          <mandatory>true</mandatory>
54
          <classOfItems>org.gvsig.tools.persistence.case1.model.ViewPort</classOfItems>
55
        </field>
56
      </fields>
57
    </class>
58
  </classes>
59
</definitions>  
0 60

  
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/impl/DefaultDynFieldTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* gvSIG. Geographic Information System of the Valencian Government
25
*
26
* Copyright (C) 2007-2008 Infrastructures and Transports Department
27
* of the Valencian Government (CIT)
28
* 
29
* This program is free software; you can redistribute it and/or
30
* modify it under the terms of the GNU General Public License
31
* as published by the Free Software Foundation; either version 2
32
* of the License, or (at your option) any later version.
33
* 
34
* This program is distributed in the hope that it will be useful,
35
* but WITHOUT ANY WARRANTY; without even the implied warranty of
36
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
* GNU General Public License for more details.
38
* 
39
* You should have received a copy of the GNU General Public License
40
* along with this program; if not, write to the Free Software
41
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
42
* MA  02110-1301, USA.
43
* 
44
*/
45

  
46
/*
47
* AUTHORS (In addition to CIT):
48
* 2008 {DiSiD Technologies}  {{Task}}
49
*/
50
package org.gvsig.tools.dynobject.impl;
51

  
52
import junit.framework.TestCase;
53
import org.gvsig.tools.dataTypes.DataTypes;
54

  
55
/**
56
 * Unit tests for the class {@link DefaultDynField}.
57
 * 
58
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
59
 */
60
public class DefaultDynFieldTest extends TestCase {
61

  
62
    protected void setUp() throws Exception {
63
        super.setUp();
64
    }
65
    
66
    public void testEquals() {
67
        DefaultDynField field1 = new DefaultDynField("field1", DataTypes.STRING);
68
        DefaultDynField field2 = new DefaultDynField("field2", DataTypes.STRING);
69
        DefaultDynField field1b = new DefaultDynField("field1", DataTypes.STRING);
70

  
71
        assertTrue(field1.equals(field1b));
72
        assertFalse(field1.equals(field2));
73
        assertFalse(field1.equals(null));
74
    }
75

  
76
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/impl/DefaultDynClassTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2008 {DiSiD Technologies}  {{Task}}
27
 */
28
package org.gvsig.tools.dynobject.impl;
29

  
30
import java.util.ArrayList;
31
import java.util.Arrays;
32
import java.util.List;
33

  
34
import org.easymock.MockControl;
35

  
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.dataTypes.DataTypes;
38
import org.gvsig.tools.dynobject.DynClass;
39
import org.gvsig.tools.dynobject.DynField;
40
import org.gvsig.tools.dynobject.DynField_v2;
41
import org.gvsig.tools.dynobject.DynObject;
42
import org.gvsig.tools.dynobject.DynObjectManager;
43
import org.gvsig.tools.dynobject.DynObjectValueItem;
44
import org.gvsig.tools.dynobject.DynStruct;
45
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
46

  
47
/**
48
 * Unit tests for the class {@link DefaultDynClass}.
49
 * 
50
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
51
 */
52
public class DefaultDynClassTest extends AbstractLibraryAutoInitTestCase {
53

  
54
	private MockControl managerControl;
55
	private DynObjectManager manager;
56
	private DefaultDynClass dynClass;
57

  
58
	protected void doSetUp() throws Exception {
59
		managerControl = MockControl.createNiceControl(DynObjectManager.class);
60
		manager = (DynObjectManager) managerControl.getMock();
61
		dynClass = new DefaultDynClass(manager, new DefaultDynClassName(
62
				"dynclass"), "description");
63
	}
64

  
65
	/**
66
	 * Test method for
67
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#newInstance()}.
68
	 */
69
	// public void testNewInstance() {
70
	// TODO: solve
71
	// MockControl dynObjControl = MockControl
72
	// .createNiceControl(DynObject.class);
73
	// DynObject dynObj = (DynObject) dynObjControl.getMock();
74
	// dynObjControl.expectAndReturn(dynObj.getDynClass(), dynClass);
75
	// dynObjControl.replay();
76
	//
77
	// managerControl.expectAndReturn(manager.createDynObject(dynClass),
78
	// dynObj);
79
	// managerControl.replay();
80
	//
81
	// DynObject newDynObj = dynClass.newInstance();
82
	// assertTrue(dynClass.isInstance(newDynObj));
83
	// }
84

  
85
	/**
86
	 * Test method for
87
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#extend(org.gvsig.tools.dynobject.DynClass)}
88
	 * .
89
	 */
90
	public void testExtendDynClass() {
91
		final String parent = "parent";
92

  
93
		DefaultDynClassName name = new DefaultDynClassName(parent);
94

  
95
		DefaultDynClass parentDynClass = new DefaultDynClass(manager, name,
96
				"parent description");
97

  
98
		managerControl.expectAndReturn(manager.has(parent), true);
99
		managerControl.expectAndReturn(manager.get(parent), parentDynClass);
100
		managerControl.replay();
101

  
102
		dynClass.extend(parentDynClass);
103

  
104
		DynClass[] parents = dynClass.getSuperDynClasses();
105
		assertEquals(parentDynClass, parents[0]);
106
	}
107

  
108
	/**
109
	 * Test method for
110
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#extend(java.lang.String)}
111
	 * .
112
	 */
113
	public void testExtendString() {
114
		final String parent = "parent";
115

  
116
		DefaultDynClassName name = new DefaultDynClassName(parent);
117

  
118
		DefaultDynClass parentDynClass = new DefaultDynClass(manager, name,
119
				"parent description");
120

  
121
		managerControl.expectAndReturn(manager.has(parent), true);
122
		managerControl.expectAndReturn(manager.get(parent), parentDynClass);
123
		managerControl.replay();
124

  
125
		dynClass.extend(parent);
126

  
127
		DynClass[] parents = dynClass.getSuperDynClasses();
128
		assertEquals(parentDynClass, parents[0]);
129
	}
130

  
131
	/**
132
	 * Test method for
133
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#getDynField(java.lang.String)}
134
	 * ,
135
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#addDynField(java.lang.String)}
136
	 * ,
137
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#removeDynField(java.lang.String)}
138
	 * ,
139
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#getDeclaredDynFields()}
140
	 * .
141
	 */
142
	public void testDynFields() {
143
		final String field1 = "field1";
144
		final String field2 = "field2";
145

  
146
		DynField dynField1 = dynClass.addDynField(field1);
147
		assertEquals(dynField1, dynClass.getDynField(field1));
148

  
149
		DynField dynField2 = dynClass.addDynField(field2);
150
		assertEquals(dynField2, dynClass.getDynField(field2));
151

  
152
		DynField[] fields = dynClass.getDeclaredDynFields();
153
		assertEquals(2, fields.length);
154

  
155
		dynClass.removeDynField(field1);
156
		assertNull(dynClass.getDynField(field1));
157
	}
158

  
159
	/**
160
	 * Test method for
161
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynClass#equals(Object)}.
162
	 */
163
	public void testEquals() {
164
		DefaultDynClass dynClass2 = new DefaultDynClass(manager,
165
				new DefaultDynClassName("dynclass2"), "description2");
166
		DefaultDynClass dynClassB = new DefaultDynClass(manager,
167
				new DefaultDynClassName("dynclass"), "description");
168

  
169
		assertTrue(dynClass.equals(dynClassB));
170
		assertFalse(dynClass.equals(dynClass2));
171
		assertFalse(dynClass.equals(null));
172
	}
173

  
174
	/**
175
	 * Validation test: DynObjects as dynfields within a dynObject.
176
	 * 
177
	 * Metadata A will have metadata B as porperty. for each dynField, a
178
	 * validate function will be triggered with the current
179
	 * 
180
	 * @throws Exception
181
	 * 
182
	 */
183
	public void testValidate() throws Exception {
184

  
185
		/**
186
		 * Creating and registering both dynClasses
187
		 */
188
		DynObjectManager dynManager = ToolsLocator.getDynObjectManager();
189

  
190
		DynClass dynClassA = new DefaultDynClass(manager,
191
				new DefaultDynClassName("metadata", "DynclassA"),
192
				"descriptionA");
193
		dynManager.add(dynClassA);
194

  
195
		DynClass dynClassB = new DefaultDynClass(manager,
196
				new DefaultDynClassName("metadata", "DynclassB"),
197
				"descriptionB");
198
		dynManager.add(dynClassB);
199

  
200
		/**
201
		 * Filling dynClass B with "Name" and "Street"
202
		 */
203
		dynClassB.addDynFieldString("name");
204
		dynClassB.addDynFieldString("street");
205

  
206
		/**
207
		 * Filling dynClass A with "Name" and the dynClass B named "dynObjB"
208
		 */
209
		dynClassA.addDynFieldString("name");
210
		dynClassA.addDynField("dynObjB").setType(DataTypes.DYNOBJECT)
211
				.setSubtype(dynClassB.getFullName());
212

  
213
		/**
214
		 * Creating dynObjects for current dynClasses and applying dynObject B
215
		 * as a property of A
216
		 */
217
		DynObject dynObjA = new DefaultDynObject(dynClassA);
218
		DynObject dynObjB = new DefaultDynObject(dynClassB);
219

  
220
		// TODO: Note that even specified a subType, if we set a different
221
		// dynObject, it will not check if the subType is correct.
222
		dynObjA.setDynValue("dynObjB", dynObjB);
223

  
224
		/**
225
		 * Once the structure has been created, we will validate each field of
226
		 * dynObject A, which also contains B as a property.
227
		 */
228
		DynField[] fields = dynObjA.getDynClass().getDynFields();
229
		DynField field;
230
		Object value;
231
		for (int i = 0; i < fields.length; ++i) {
232
			field = fields[i];
233
			value = dynObjA.getDynValue(field.getName());
234

  
235
			// Checking that it actually contains the DynObject B as a
236
			// property
237
			if (field.getType() == DataTypes.DYNOBJECT) {
238
				assertTrue(dynClassB.equals(((DynObject) value).getDynClass()));
239
			}
240

  
241
			// Performing validation
242
			field.validate(value);
243
		}
244
	}
245

  
246
	/**
247
	 * 
248
	 * Duplicate test: checking if, given two dynClasses A and B, dynFields from
249
	 * class A can be duplicated into dynClass B by using setters in B with the
250
	 * returned values of getters of A as input.
251
	 * 
252
	 */
253
	public void testSetters() {
254
		/**
255
		 * Creating and registering both dynClasses
256
		 */
257
		DynObjectManager dynManager = ToolsLocator.getDynObjectManager();
258

  
259
		DynClass dynClassA = new DefaultDynClass(manager,
260
				new DefaultDynClassName("metadata", "DynclassA"),
261
				"descriptionA");
262

  
263
		DynClass dynClassB = new DefaultDynClass(manager,
264
				new DefaultDynClassName("metadata", "DynclassB"),
265
				"descriptionB");
266

  
267
		/**
268
		 * Filling dynClass B with "Name" and "Street"
269
		 */
270
		dynClassB.addDynFieldString("name");
271
		dynClassB.addDynFieldString("street");
272

  
273
		fillInitialDynfields(dynClassA, dynClassB.getFullName());
274

  
275
		// /**
276
		// * Creating dynObjects for current dynClasses and applying dynObject B
277
		// * as a property of A
278
		// */
279
		// DynObject dynObjA = new DefaultDynObject(dynClassA);
280
		// DynObject dynObjB = new DefaultDynObject(dynClassB);
281

  
282
		copyDefinitions(dynClassA, dynClassB);
283

  
284
		checkValues(dynClassA, dynClassB);
285
	}
286

  
287
	private List createList(Object[] values) {
288
		DynObjectValueItem[] valueItems = new DynObjectValueItem[values.length];
289
		for (int i = 0; i < values.length; i++) {
290
			valueItems[i] = new DynObjectValueItem(values[i]);
291
		}
292
		return Arrays.asList(valueItems);
293
	}
294

  
295
	/**
296
	 * Filling dynClass A with different parameters that will be duplicated into
297
	 * dynClass B afterwards.
298
	 */
299
	private void fillInitialDynfields(DynClass definition,
300
			String dynClassBFullName) {
301

  
302
		List items = new ArrayList();
303

  
304
		definition.addDynFieldString("name");
305
		definition.addDynField("dynObjB").setType(DataTypes.DYNOBJECT)
306
				.setSubtype(dynClassBFullName);
307

  
308
		definition.addDynFieldString("id").setReadOnly(true); // optional
309

  
310
		definition.addDynFieldString("language").setMandatory(true);
311

  
312
		definition.addDynFieldString("charachterset").setMandatory(true)
313
				.setAvailableValues(createList(new String[] { "a", "b", "c" }));
314

  
315
		definition
316
				.addDynFieldList("hierarchyLevels")
317
				.setElementsType(DataTypes.STRING)
318
				.setMandatory(true)
319
				.setAvailableValues(
320
						createList(new String[] { "hier1", "hier2", "hier3" }));
321

  
322
		definition.addDynFieldDate("date").setMandatory(true);
323

  
324
		definition.addDynFieldList("keywords")
325
				.setElementsType(DataTypes.STRING);
326

  
327
//		definition.addDynFieldList("dynObjects")
328
//				.setElementsType(DataTypes.DYNOBJECT).setMandatory(true)
329
//				.setSubtype(dynClassBFullName);
330

  
331
	}
332

  
333
	private void copyDefinitions(DynClass dynClassA, DynClass dynClassB) {
334
		DynField field;
335
		DynField fields[] = dynClassA.getDynFields();
336
		for (int i = 0; i < fields.length; i++) {
337
			field = fields[i];
338
			;
339
//			if (dynClassB.getDynField(field.getName()) == null) {
340
//				addDynField(dynClassB, field);
341
//			}
342
		}
343

  
344
		// dynFields must have the same number of items or more if some items
345
		// have been previously defined.
346
		assertTrue(dynClassB.getDynFields().length >= fields.length);
347
	}
348

  
349
	private void copyValues(DynObject oldDefinition, DynObject newDefinition) {
350
		Object value;
351
		DynField field;
352
		DynField fields[] = oldDefinition.getDynClass().getDynFields();
353
		for (int i = 0; i < fields.length; i++) {
354
			field = fields[i];
355
			value = oldDefinition.getDynValue(field.getName());
356
//			if (newDefinition.getDynClass().getDynField(field.getName()) == null) {
357
//				addDynField(newDefinition.getDynClass(), field);
358
//			}
359
			if (value == null) {
360
				continue;
361
			}
362
			if (value instanceof DynObject) {
363
				DynObject parent = (DynObject) value;
364
				DynStruct parentDefinition = parent.getDynClass();
365
				DynClass childDefinition = manager.get(
366
						parentDefinition.getName(),
367
						parentDefinition.getNamespace());
368
				DynObject child = manager.createDynObject(childDefinition);
369

  
370
				copyValues(child, parent);
371
				newDefinition.setDynValue(field.getName(), child);
372

  
373
			} else {
374
				newDefinition.setDynValue(field.getName(), value);
375
			}
376
		}
377
	}
378

  
379
	private void addDynField(DynStruct definition, DynField_v2 field) {
380
		DynField dynField = definition.addDynField(field.getName())
381
				.setType(field.getType()).setSubtype(field.getSubtype())
382
				.setAvailableValues(field.getAvailableValues())
383
				.setClassOfItems(field.getClassOfItems())
384
				.setClassOfValue(field.getClassOfValue())
385
				.setDefaultFieldValue(field.getDefaultValue())
386
				.setDescription(field.getDescription())
387
				.setGroup(field.getGroup()).setHidden(field.isHidden())
388
				.setMandatory(field.isMandatory())
389
				.setMaxValue(field.getMaxValue())
390
				.setMinValue(field.getMinValue()).setOrder(field.getOder())
391
				.setPersistent(field.isPersistent())
392
				.setReadOnly(field.isReadOnly());
393

  
394
		// PETO copyElementsType(dynField, XXXX);
395
	}
396

  
397
	private void copyElementsType(DynField dynField, DynField elementsType) {
398
		if (elementsType == null) {
399
			return;
400
		}
401
//
402
//		dynField.setElementsType(elementsType.getType());
403
//		dynField.getElementsType().setSubtype(elementsType.getSubtype())
404
//				.setAvailableValues(elementsType.getAvailableValues())
405
//				.setClassOfItems(elementsType.getClassOfItems())
406
//				.setClassOfValue(elementsType.getClassOfValue())
407
//				.setDefaultFieldValue(elementsType.getDefaultValue())
408
//				.setDescription(elementsType.getDescription())
409
//				.setGroup(elementsType.getGroup())
410
//				.setHidden(elementsType.isHidden())
411
//				.setMandatory(elementsType.isMandatory())
412
//				.setMaxValue(elementsType.getMaxValue())
413
//				.setMinValue(elementsType.getMinValue())
414
//				.setOrder(elementsType.getOder())
415
//				.setPersistent(elementsType.isPersistent())
416
//				.setReadOnly(elementsType.isReadOnly());
417
	}
418

  
419
	private void checkValues(DynClass dynObjA, DynClass dynObjB) {
420
		DynField[] dynFieldsA = dynObjA.getDynFields();
421
		DynField[] dynFieldsB = dynObjB.getDynFields();
422

  
423
		DynField field;
424
		boolean done = false;
425
		for (int i = 0; i < dynFieldsA.length; ++i) {
426
			field = dynFieldsA[i];
427
			for (int j = 0; j < dynFieldsB.length; ++j) {
428
				if (dynFieldsB[j].getName().equals(field.getName())) {
429
					checkDynField(field, dynFieldsB[j]);
430
					done = true;
431
				}
432
			}
433
			// dynField must be defined in both lists.
434
			assertTrue(done);
435

  
436
		}
437
	}
438

  
439
	private void checkDynField(DynField fieldA, DynField fieldB) {
440

  
441
		assertEquals(fieldA.getName(), fieldA.getName());
442
		assertEquals(fieldA.getType(), fieldB.getType());
443
		assertEquals(fieldA.getSubtype(), fieldB.getSubtype());
444
		assertEquals(fieldA.getAvailableValues(), fieldB.getAvailableValues());
445
		assertEquals(fieldA.getClassOfItems(), fieldB.getClassOfItems());
446
		assertEquals(fieldA.getClassOfValue(), fieldB.getClassOfValue());
447
		assertEquals(fieldA.getDefaultValue(), fieldB.getDefaultValue());
448
		assertEquals(fieldA.getDescription(), fieldB.getDescription());
449
		assertEquals(fieldA.getGroup(), fieldB.getGroup());
450
		assertEquals(fieldA.isHidden(), fieldB.isHidden());
451
		assertEquals(fieldA.isMandatory(), fieldB.isMandatory());
452
		assertEquals(fieldA.getMaxValue(), fieldB.getMaxValue());
453
		assertEquals(fieldA.getMinValue(), fieldB.getMinValue());
454
		assertEquals(fieldA.getOder(), fieldB.getOder());
455
		assertEquals(fieldA.isPersistent(), fieldB.isPersistent());
456
		assertEquals(fieldA.isReadOnly(), fieldB.isReadOnly());
457

  
458
	}
459

  
460
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/impl/DefaultDynObjectTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/**
25
 *
26
 */
27
package org.gvsig.tools.dynobject.impl;
28

  
29
import org.easymock.MockControl;
30

  
31
import org.gvsig.tools.dynobject.DynObjectManager;
32
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
33

  
34
/**
35
 * @author jmvivo
36
 *
37
 */
38
public class DefaultDynObjectTest extends AbstractLibraryAutoInitTestCase {
39

  
40
    private MockControl managerControl;
41
	private DynObjectManager manager;
42
	private DefaultDynClass dynClass;
43

  
44
	/* (non-Javadoc)
45
	 * @see junit.framework.TestCase#setUp()
46
	 */
47
	protected void doSetUp() throws Exception {
48
		managerControl = MockControl.createNiceControl(DynObjectManager.class);
49
		manager = (DynObjectManager) managerControl.getMock();
50
		dynClass = new DefaultDynClass(manager, new DefaultDynClassName(
51
				"dynclass"), "description");
52
	}
53

  
54

  
55
    /**
56
     * Test method for {@link org.gvsig.tools.dynobject.impl.DefaultDynObject#hasDynValue(String)}.
57
     */
58
    public void testHasDynValueStringTest() {
59
    	final String fieldName = "myField";
60
		dynClass.addDynField(fieldName);
61

  
62
		DefaultDynObject obj = new DefaultDynObject(dynClass);
63

  
64
		assertFalse(obj.hasDynValue(fieldName));
65

  
66
		obj.setDynValue(fieldName, "Value");
67

  
68
		assertTrue(obj.hasDynValue(fieldName));
69

  
70
    }
71

  
72
	/**
73
	 * Test method for
74
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynObject#hasDynValue(String)}
75
	 * from extended class.
76
	 */
77
	public void testHasDynValueStringExtendedTest() {
78

  
79
        final String parent = "parent";
80

  
81
		DefaultDynClassName name = new DefaultDynClassName(parent);
82

  
83
		DefaultDynClass parentDynClass = new DefaultDynClass(manager, name,
84
				"parent description");
85

  
86
		managerControl.expectAndReturn(manager.has(parent), true);
87
		managerControl.expectAndReturn(manager.get(parent), parentDynClass);
88
		managerControl.replay();
89

  
90
		final String fieldName = "myField";
91
		parentDynClass.addDynField(fieldName);
92

  
93
		dynClass.extend(parent);
94

  
95
		DefaultDynObject obj = new DefaultDynObject(dynClass);
96

  
97
		assertFalse(obj.hasDynValue(fieldName));
98

  
99
		obj.setDynValue(fieldName, "Value");
100

  
101
		assertTrue(obj.hasDynValue(fieldName));
102

  
103
    }
104

  
105

  
106

  
107
	/**
108
	 * Test method for
109
	 * {@link org.gvsig.tools.dynobject.impl.DefaultDynObject#hasDynValue(String)}
110
	 * from extended class.
111
	 */
112
	public void testHasDynValueStringDelegatedTest() {
113

  
114
		final String delegated = "delegated";
115

  
116

  
117
		DefaultDynClassName name = new DefaultDynClassName(delegated);
118

  
119
		DefaultDynClass delegatedDynClass = new DefaultDynClass(manager, name,
120
				"parent description");
121

  
122
		managerControl.expectAndReturn(manager.has(delegated), true);
123
		managerControl.expectAndReturn(manager.get(delegated),
124
				delegatedDynClass);
125
		managerControl.replay();
126

  
127
		final String fieldName = "myField";
128
		delegatedDynClass.addDynField(fieldName);
129

  
130
		dynClass.addDynField(fieldName);
131

  
132
		DefaultDynObject delegatedObj = new DefaultDynObject(delegatedDynClass);
133

  
134
		DefaultDynObject obj = new DefaultDynObject(dynClass);
135

  
136
		assertFalse(obj.hasDynValue(fieldName));
137

  
138
		delegatedObj.setDynValue(fieldName, "DelegatedValue");
139

  
140
		obj.delegate(delegatedObj);
141

  
142
		assertTrue(obj.hasDynValue(fieldName));
143

  
144
		Object v1 = delegatedObj.getDynValue(fieldName); 
145
		Object v2 = obj.getDynValue(fieldName);
146
		assertEquals(v1,v2);
147

  
148

  
149
		obj.setDynValue(fieldName, "Value");
150

  
151
		assertTrue(obj.hasDynValue(fieldName));
152
		assertEquals("Value", obj.getDynValue(fieldName));
153

  
154

  
155
	}
156
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/DynObjectPagingHelperTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * AUTHORS (In addition to CIT):
26
 * 2010 {}  {{Task}}
27
 */
28
package org.gvsig.tools.dynobject;
29

  
30
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
31

  
32
/**
33
 * Tests for the {@link DynObjectPagingHelper} interface.
34
 * 
35
 * @author 2010- C?sar Ordi?ana - gvSIG team
36
 */
37
public abstract class DynObjectPagingHelperTest extends
38
		AbstractLibraryAutoInitTestCase {
39

  
40
	private DynObjectPagingHelper helper;
41

  
42
	protected void doSetUp() throws Exception {
43
		helper = createDynObjectPagingHelper();
44
	}
45

  
46
	/**
47
	 * Test method for the max page size setting.
48
	 */
49
	public void testMaxPageSize() throws Exception {
50

  
51
		helper.setMaxPageSize(2);
52
		helper.setCurrentPage(0);
53

  
54
		long numPages = helper.getNumPages();
55
		if (numPages == 0) {
56
			fail("The provided helper can't have 0 pages, "
57
					+ "please provide one with some data for the test");
58
		}
59
		for (long i = numPages; i < numPages - 1; i++) {
60
			assertEquals("Number of elements of page " + i
61
					+ " is not the same as the maximum page size", numPages,
62
					helper.getCurrentPageDynObjects().length);
63
			helper.setCurrentPage(i + 1);
64
		}
65
		assertTrue(
66
				"Last page is not less than or equal to the maximum page size",
67
				numPages >= helper.getCurrentPageDynObjects().length);
68
	}
69

  
70
	/**
71
	 * Test method for
72
	 * {@link org.gvsig.tools.dynobject.DynObjectPagingHelper#getNumPages()}.
73
	 */
74
	public void testGetNumPages() throws Exception {
75
		double numDOs = helper.getTotalSize();
76
		double pageSize = helper.getMaxPageSize();
77

  
78
		long numPages = (long) Math.ceil(numDOs / pageSize);
79
		assertEquals(numPages, helper.getNumPages());
80

  
81
		pageSize = 2;
82
		helper.setMaxPageSize((int) pageSize);
83

  
84
		numPages = (long) Math.ceil(numDOs / pageSize);
85
		assertEquals(numPages, helper.getNumPages());
86
	}
87

  
88
	/**
89
	 * Test method for
90
	 * {@link org.gvsig.tools.dynobject.DynObjectPagingHelper#setCurrentPage(long)}
91
	 * .
92
	 */
93
	public void testSetCurrentPage() throws Exception {
94
		try {
95
			helper.setCurrentPage(helper.getNumPages() + 1);
96
			fail("Helper allows to set a page which does not exist");
97
		} catch (Exception e) {
98
			// Works as excepted
99
		}
100

  
101
		try {
102
			helper.setCurrentPage(-1);
103
			fail("Helper allows to set a negative page");
104
		} catch (Exception e) {
105
			// Works as excepted
106
		}
107
	}
108

  
109
	/**
110
	 * Test method for
111
	 * {@link org.gvsig.tools.dynobject.DynObjectPagingHelper#getCurrentPageDynObjects()}
112
	 * .
113
	 */
114
	public void testGetCurrentPageDynObjects() throws Exception {
115
		helper.setMaxPageSize(2);
116
		long numPages = helper.getNumPages();
117

  
118
		if (numPages < 2) {
119
			fail("The provided helper can't have 0 or 1 page, "
120
					+ "please provide one with some more data for the test");
121
		}
122

  
123
		helper.setCurrentPage(0);
124
		DynObject[] values = helper.getCurrentPageDynObjects();
125
		assertTrue(values != null && values.length == 2);
126
	}
127

  
128
	protected DynObjectPagingHelper getHelper() {
129
		return helper;
130
	}
131

  
132
	protected abstract DynObjectPagingHelper createDynObjectPagingHelper()
133
			throws Exception;
134
}
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.156/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/dynobject/ImportDynClassTest.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynobject;
25

  
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.util.Map;
29

  
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dataTypes.DataTypes;
32
import org.gvsig.tools.evaluator.Evaluator;
33
import org.gvsig.tools.exception.BaseRuntimeException;
34
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
35
import org.gvsig.tools.visitor.Visitor;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38
import org.xmlpull.v1.XmlPullParserException;
39

  
40
public class ImportDynClassTest extends AbstractLibraryAutoInitTestCase {
41

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff