Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extMetadata / src-test / org / gvsig / metadata / extended / manager / ExtendedMetadataImplTest.java @ 23727

History | View | Annotate | Download (5.19 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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
*/
22

    
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 Geographic Information research group: http://www.geoinfo.uji.es
26
* Departamento de Lenguajes y Sistemas Inform?ticos (LSI)
27
* Universitat Jaume I   
28
* {{Task}}
29
*/
30
 
31
package org.gvsig.metadata.extended.manager;
32

    
33
import java.util.Date;
34

    
35
import junit.framework.TestCase;
36

    
37
import org.gvsig.metadata.exceptions.NamedMetadataNotFoundException;
38
import org.gvsig.metadata.extended.ExtendedMetadata;
39
import org.gvsig.metadata.extended.MDElement;
40
import org.gvsig.metadata.extended.manager.ExtendedMetadataImpl;
41
import org.gvsig.metadata.extended.manager.MDElementImpl;
42
import org.gvsig.metadata.extended.registry.objects.MDDefinition;
43
import org.gvsig.metadata.extended.registry.objects.MDElementDefinition;
44

    
45

    
46
public class ExtendedMetadataImplTest extends TestCase {
47

    
48
        //@BeforeClass
49
        public static void setUpBeforeClass() throws Exception {
50
        }
51

    
52
        //@AfterClass
53
        public static void tearDownAfterClass() throws Exception {
54
        }
55

    
56
        //@Before
57
        public void setUp() throws Exception {
58
        }
59

    
60
        //@After
61
        public void tearDown() throws Exception {
62
        }
63

    
64
        public void testGet() throws NamedMetadataNotFoundException {
65
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
66
                md.set("Author", "Alejandro Llaves");
67
                assertEquals("Alejandro Llaves", md.get("Author"));
68
        }
69
        
70
        public void testNamedMetadataNotFoundException() {
71
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
72
                try {
73
                        md.get("Topic");
74
                        fail("get() should have thrown a NamedMetadataNotFoundException!");
75
                }
76
                catch (NamedMetadataNotFoundException ex) {
77
                }
78
        }
79
        
80
        public void testGetBoolean() throws ClassCastException, NamedMetadataNotFoundException {
81
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
82
                md.setBoolean("Available", true);
83
                assertEquals(true, md.getBoolean("Available"));
84
        }
85
        
86
        public void testGetDouble() throws ClassCastException, NamedMetadataNotFoundException {
87
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
88
                md.setDouble("Area", (double) 500);
89
                assertEquals((double) 500, md.getDouble("Area"), 0);
90
        }
91
        
92
        public void testGetInt() throws ClassCastException, NamedMetadataNotFoundException {
93
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
94
                md.setInt("Number", 5);
95
                assertEquals(5, md.getInt("Number"));
96
        }
97
        
98
        public void testGetString() throws ClassCastException, NamedMetadataNotFoundException {
99
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
100
                md.setString("Author", "Alejandro Llaves");
101
                assertEquals("Alejandro Llaves", md.getString("Author"));
102
        }
103
        
104
        public void testGetDate() throws ClassCastException, NamedMetadataNotFoundException {
105
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
106
                md.setDate("Date", new Date(0L));
107
                assertEquals(new Date(0l), md.getDate("Date"));
108
        }
109

    
110
        public void testHasValue() {
111
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
112
                assertEquals(md.hasValue("Author"), false);
113
                md.set("Author", "Alejandro Llaves");
114
                assertEquals(md.hasValue("Author"), true);
115
        }
116

    
117
        public void testIsEmpty() {
118
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
119
                assertEquals(md.isEmpty(), true);
120
                md.set("Author", "Alejandro Llaves");
121
                assertEquals(md.isEmpty(), false);
122
        }
123
        
124
        public void testGetElement() throws ClassCastException, NamedMetadataNotFoundException {
125
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
126
                MDElementDefinition mded = new MDElementDefinition("elemento de prueba", null, null, null, null);
127
                MDElement mde = new MDElementImpl("elem", mded, null);
128
                md.setElement(mde);
129
                assertEquals(mde, md.getElement("elemento de prueba"));
130
        }
131
        
132
        public void testGetName() {
133
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
134
                assertEquals("prueba", md.getName());
135
                ((ExtendedMetadataImpl) md).setName("2a_prueba");
136
                assertEquals("2a_prueba", md.getName());
137
        }
138
        
139
        public void testGetDescription() {
140
                ExtendedMetadata md = new ExtendedMetadataImpl("prueba");
141
                ((ExtendedMetadataImpl) md).setDescription("Objeto Metadata de prueba");
142
                assertEquals("Objeto Metadata de prueba", md.getDescription());
143
        }
144
        
145
        public void testGetType() {
146
                MDDefinition mdd = new MDDefinition("prueba", "Objeto Metadata de prueba");
147
                ExtendedMetadata md = new ExtendedMetadataImpl(mdd, null);
148
                assertEquals(mdd, md.getType());
149
        }
150
}