Revision 259

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/test/java/org/gvsig/tools/persistence/case1/ComplexTest.java
8 8

  
9 9
import org.gvsig.tools.ToolsLocator;
10 10
import org.gvsig.tools.dynobject.DynStruct;
11
import org.gvsig.tools.exception.BaseException;
11 12
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
12 13
import org.gvsig.tools.persistence.PersistenceManager;
13 14
import org.gvsig.tools.persistence.PersistentState;
......
18 19
import org.gvsig.tools.persistence.exception.PersistenceException;
19 20
import org.gvsig.tools.persistence.exception.PersistenceTypeNotSupportedException;
20 21
import org.gvsig.tools.persistence.exception.PersistenceValidateExceptions;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
21 24

  
22 25
public class ComplexTest extends AbstractLibraryAutoInitTestCase {
23 26

  
27
	private static Logger LOG = LoggerFactory.getLogger(ComplexTest.class);
28

  
24 29
	PersistenceManager manager;
25 30
	ModelManager modelmgr;
26
	
31

  
27 32
	protected void doSetUp() throws Exception {
28 33
		this.manager = ToolsLocator.getPersistenceManager();
29 34
		manager.setAutoValidation(PersistenceManager.MANDATORY);
......
35 40
		super.tearDown();
36 41
		modelmgr.unregisterPersistence();
37 42
	}
38
	
43

  
39 44
	public void compareMapContext(MapContext obj1, MapContext obj2) {
40
		assertEquals("MapContext aren't equals, code mismatch", obj1.getCode(), obj2.getCode());
41
		assertEquals("MapContext aren't equals, projection mismatch", obj1.getProjection().getFullCode(), obj2.getProjection().getFullCode());
42
		assertEquals("MapContext aren't equals, viewport mismatch", obj1.getViewPort().getCode(), obj2.getViewPort().getCode());		
45
		assertEquals("MapContext aren't equals, code mismatch", obj1.getCode(),
46
				obj2.getCode());
47
		assertEquals("MapContext aren't equals, projection mismatch", obj1
48
				.getProjection().getFullCode(), obj2.getProjection()
49
				.getFullCode());
50
		assertEquals("MapContext aren't equals, viewport mismatch", obj1
51
				.getViewPort().getCode(), obj2.getViewPort().getCode());
43 52
	}
44
	
53

  
45 54
	public void testRegister() {
46 55
		DynStruct definition = manager.getDefinition(MapContext.class);
47 56
		assertNotNull("Can't register class", definition);
48
		assertEquals(
49
				"Registration don't work, name incorrect", 
50
				"MapContext", 
51
				definition.getName()
52
		);
57
		assertEquals("Registration don't work, name incorrect", "MapContext",
58
				definition.getName());
53 59
	}
54
	
55
	public void testGetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions {
56
		MapContext obj = new MapContext( new Projection() );
57
		PersistentState state = manager.getState(obj);
58
		assertNotNull("Can't retrieve state", state);
59
		assertNotNull("Can't retrieve layers", state.get("layers"));
60
		assertNotNull("Can't retrieve viewPort", state.get("viewPort"));
60

  
61
	public void testGetState() throws PersistenceTypeNotSupportedException,
62
			PersistenceClassNotRegistered, PersistenceException,
63
			PersistenceValidateExceptions {
64
		try {
65
			MapContext obj = new MapContext(new Projection());
66
			PersistentState state = manager.getState(obj);
67
			assertNotNull("Can't retrieve state", state);
68
			assertNotNull("Can't retrieve layers", state.get("layers"));
69
			assertNotNull("Can't retrieve viewPort", state.get("viewPort"));
70
		} catch (BaseException ex) {
71
			LOG.error(ex.getMessageStack());
72
		} catch (Exception ex) {
73
			LOG.error(ex.getMessage());
74
		}
75

  
61 76
	}
62 77

  
63
	public void testSetState() throws PersistenceTypeNotSupportedException, PersistenceClassNotRegistered, PersistenceException, PersistenceValidateExceptions {
64
		MapContext obj1 = new MapContext( new Projection() );
78
	public void testSetState() throws PersistenceTypeNotSupportedException,
79
			PersistenceClassNotRegistered, PersistenceException,
80
			PersistenceValidateExceptions {
81
		MapContext obj1 = new MapContext(new Projection());
65 82
		PersistentState state = manager.getState(obj1);
66 83
		assertNotNull("Can't retrieve state", state);
67
		
84

  
68 85
		MapContext obj2 = (MapContext) manager.create(state);
69 86
		this.compareMapContext(obj1, obj2);
70 87
	}
71 88

  
72 89
	public void testSaveState() throws Exception {
73
		MapContext obj = new MapContext( new Projection() );
90
		MapContext obj = new MapContext(new Projection());
74 91
		PersistentState state = manager.getState(obj);
75 92

  
76 93
		File f = File.createTempFile("gvsig-test-pers-complex", "A.zip");
......
81 98
	}
82 99

  
83 100
	public void testLoadState() throws Exception {
84
		MapContext obj1 = new MapContext( new Projection() );
101
		MapContext obj1 = new MapContext(new Projection());
85 102
		PersistentState state1 = manager.getState(obj1);
86 103

  
87 104
		File f = File.createTempFile("gvsig-test-pers-complex", "B.zip");
88 105
		OutputStream out = new FileOutputStream(f);
89 106
		manager.saveState(state1, out);
90 107
		out.close();
91
		
108

  
92 109
		InputStream in = new FileInputStream(f);
93 110
		PersistentState state2 = manager.loadState(in);
94 111
		MapContext obj2 = (MapContext) manager.create(state2);
95
		
96
		this.compareMapContext(obj1, obj2);		
97 112

  
113
		this.compareMapContext(obj1, obj2);
114

  
98 115
	}
99 116

  
100

  
101 117
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynField.java
403 403
				}
404 404
			}
405 405
			break;
406

  
406 407
		case DataTypes.MAP:
407 408
			if (!(value instanceof Map)) {
408 409
				throw new DynFieldValidateException(value, this);
......
434 435
			}
435 436
			break;
436 437

  
437
		case DataTypes.OBJECT:
438
			if (this.theClass != null) {
439
				if (!this.theClass.isInstance(value)) {
440
					throw new DynFieldValidateException(value, this);
441
				}
442
			}
443
			break;
444

  
445 438
		case DataTypes.DYNOBJECT:
446 439
			if (!(value instanceof DynObject)) {
447 440
				throw new DynFieldValidateException(value, this);
......
463 456
			break;
464 457

  
465 458
		default:
466
			throw new DynFieldValidateException(value, this);
459
			if( this.dataType.isObject() ) {
460
				if (this.theClass != null) {
461
					if (!this.theClass.isInstance(value)) {
462
						throw new DynFieldValidateException(value, this);
463
					}
464
				}
465
			} else {
466
				throw new DynFieldValidateException(value, this);
467
			}
467 468
		}
468 469

  
469
//		if (this.mandatory && value == null) {
470
//			throw new DynFieldValidateException(value, this);
471
//		}
472

  
473 470
		if (this.getAvailableValues() != null) {
474 471
			if (!(value instanceof Comparable)) {
475 472
				throw new DynFieldValidateException(value, this);
......
495 492
				throw new DynFieldValidateException(value, this);
496 493
			}
497 494
		}
495
//
496
//      Esto no deberia hacer falta ya que cualquier asignacion pasa
497
//      Por el coerce.
498
//
499
//		//if all the above is correct, then we should check that coercing is possible
500
//		try {
501
//			coerce(value);
502
//		} catch (CoercionException e) {
503
//			throw new DynFieldValidateException(value, this);
504
//		}
498 505
		
499
		//if all the above is correct, then we should check that coercing is possible
500
		try {
501
			coerce(value);
502
		} catch (CoercionException e) {
503
			throw new DynFieldValidateException(value, this);
504
		}
505 506
	}
506 507

  
507 508
	public Object coerce(Object value) throws CoercionException {

Also available in: Unified diff