private void testAddField(String dsName, Type type) throws Exception { DataSource d = dsf.getDataSource(dsName, DataSourceFactory.EDITABLE); d.open(); Metadata m = d.getMetadata(); int fc = m.getFieldCount(); String name = "toto"; int i = 0; while (m.getFieldIndex(name + "_" + i) != -1) { i++; } // System.out.println(fc + " fields"); // System.out.println("adding " + name + "_" + i); d.addField(name + "_" + i, type); d.commit(); d.close(); d.open(); assertEquals(fc + 1, d.getMetadata().getFieldCount()); // System.out.println(d.getMetadata().getFieldCount() + " fields"); // for (int j = 0; j < d.getFieldCount(); j++) { // System.out.println(j + " field " + d.getFieldName(j)); // } // System.out.println(d.getFieldName(fc)); assertEquals(d.getFieldName(fc), name + "_" + i); assertEquals(d.getFieldType(fc).getTypeCode(), Type.STRING); assertNull(d.getFieldType(fc).getConstraintValue(Constraint.PK)); assertNull(d.getFieldType(fc).getConstraintValue(Constraint.READONLY)); d.close(); }
@Test public void testFieldIndexDataSource() throws Exception { DataSource ds = dsf.getDataSource(super.getAnyNonSpatialResource()); ds.open(); assertEquals( ds.getMetadata().getFieldIndex(ds.getMetadata().getFieldName(1)), ds.getFieldIndexByName(ds.getFieldName(1))); ds.close(); }
@Test public void testEditionWithFieldRemoved() throws Exception { sm.register("ile", getTempCopyOf(super.getAnyNonSpatialResource())); DataSource d = dsf.getDataSource("ile", DataSourceFactory.EDITABLE); d.open(); String fieldName = d.getFieldName(1); Value testValue = d.getFieldValue(0, 2); d.removeField(1); assertTrue(equals(testValue, d.getFieldValue(0, 1))); new UndoRedoTest().testAlphanumericEditionUndoRedo(d); d.commit(); d.close(); d.open(); assertEquals(d.getFieldIndexByName(fieldName), -1); d.close(); }