@Test public void testFieldIndex() throws Exception { DefaultMetadata metadata = new DefaultMetadata(); metadata.addField("name", Type.STRING); metadata.addField("surname", Type.STRING); metadata.addField("location", Type.STRING); // field index should be 0-based assertEquals(metadata.getFieldIndex("surname"), 1); }
@Test(expected = DriverException.class) public void testAddFieldExistsMetadata() throws Exception { DefaultMetadata metadata = new DefaultMetadata(); // Add a String field metadata.addField("name", Type.STRING); // Add a second string field metadata.addField("surname", Type.STRING); // Add an existing field name metadata.addField("name", Type.STRING); }
@Test public void testCreationFileAlreadyExists() throws Exception { DefaultMetadata metadata = new DefaultMetadata(); metadata.addField("mystr", TypeFactory.createType(Type.STRING)); File file = File.createTempFile("temp", ".gdms", currentWorkspace); file.delete(); FileSourceCreation sc = new FileSourceCreation(file, metadata); dsf.createDataSource(sc); try { dsf.createDataSource(sc); fail(); } catch (DriverException e) { } }
@Test public void testEqualsMetadata() throws Exception { DefaultMetadata metadata1 = new DefaultMetadata(); metadata1.addField("name", Type.STRING); metadata1.addField("surname", Type.STRING); metadata1.addField("location", Type.STRING); DefaultMetadata metadata2 = new DefaultMetadata(); metadata2.addField("name", Type.STRING); metadata2.addField("gid", Type.INT); assertEquals(metadata1, metadata1); assertEquals(metadata2, metadata2); assertFalse(metadata1.equals(metadata2)); }
@Test public void testMetadataAddAndRename() throws Exception { DefaultMetadata metadata1 = new DefaultMetadata(); metadata1.addField("name", Type.STRING); metadata1.addField("surname", Type.STRING); metadata1.addField("location", Type.STRING); DefaultMetadata metadata2 = new DefaultMetadata(); metadata2.addField("name", Type.STRING); metadata2.addField("gid", Type.INT); metadata1.addAndRenameAll(metadata2); assertEquals(metadata1.getFieldIndex("name"), 0); assertEquals(metadata1.getFieldIndex("surname"), 1); assertEquals(metadata1.getFieldIndex("location"), 2); assertEquals(metadata1.getFieldIndex("name_0"), 3); assertEquals(metadata1.getFieldIndex("gid"), 4); }