collectedFields = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(mainSchema, input.getSchema());
collectedFields = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(mainSchema, input.getSchema());
collectedFields = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(mainSchema, input.getSchema()); isFirst = false;
@Test public void testGetColumnsWhenSchemaHaveSameColumns() { Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("age") .requiredInt("year").endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("age") .requiredInt("year").endRecord(); List<Field> resultFieldList = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); Assert.assertEquals(remoteSchema.getFields().size(), resultFieldList.size()); Assert.assertEquals(inputSchema.getFields().size(), resultFieldList.size()); Assert.assertThat(resultFieldList, CoreMatchers.is(remoteSchema.getFields())); } }
@Test public void testGetColumnsWhenRemoteSchemaHasMoreColumns() { Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("age") .requiredInt("year").endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("year") .endRecord(); List<Field> resultFieldList = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); Assert.assertEquals(remoteSchema.getFields().size(), resultFieldList.size()); Set<String> exspectedFieldsNames = new HashSet<>(Arrays.asList(null, "name", "year")); for (Field field : resultFieldList) { if (field == null) { Assert.assertTrue(exspectedFieldsNames.contains(null)); continue; } Assert.assertTrue(exspectedFieldsNames.contains(field.name())); } }
@Test public void testGetColumnsWhenRemoteSchemaHasLessColumns() { Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("year") .endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredString("name").requiredInt("age") .requiredInt("year").endRecord(); List<Field> resultFieldList = DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); Assert.assertTrue(inputSchema.getFields().size() > resultFieldList.size()); Assert.assertThat(resultFieldList, CoreMatchers.is(remoteSchema.getFields())); }
@Test public void testGetCommonFieldsWithNotSetInputSchema() { exception.expect(ComponentException.class); exception.expectMessage(I18N_MESSAGES.getMessage("error.message.inputSchemaNotSet")); Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredInt("age").endRecord(); DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, null); }
@Test public void testGetCommonFieldsWithNotSetRemoteSchema() { exception.expect(ComponentException.class); exception.expectMessage(I18N_MESSAGES.getMessage("error.message.remoteSchemaNotSet")); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredInt("age").endRecord(); DynamicSchemaUtils.getCommonFieldsForDynamicSchema(null, inputSchema); }
@Test public void testGetCommonFieldsWithEmptyRemoteSchema() { exception.expect(ComponentException.class); exception.expectMessage(I18N_MESSAGES.getMessage("error.message.remoteSchemaNotSet")); Schema remoteSchema = SchemaBuilder.builder().record("record").fields().endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredInt("age").endRecord(); DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); }
@Test public void testGetCommonFieldsWithEmptyInputSchema() { exception.expect(ComponentException.class); exception.expectMessage(I18N_MESSAGES.getMessage("error.message.inputSchemaNotSet")); Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredInt("age").endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().endRecord(); DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); }
@Test public void testGetCommonFieldsWithCompletlyDifferentSchemas() { exception.expect(ComponentException.class); exception.expectMessage(I18N_MESSAGES.getMessage("error.message.differentSchema")); Schema remoteSchema = SchemaBuilder.builder().record("record").fields().requiredInt("age").endRecord(); Schema inputSchema = SchemaBuilder.builder().record("record").fields().requiredInt("year").endRecord(); DynamicSchemaUtils.getCommonFieldsForDynamicSchema(remoteSchema, inputSchema); }