### Question:
AvroSerDePartitionTransformation extends AbstractAvroSerDeTransformation implements PartitionTransformation { @Override public Partition transform(Partition partition) { if (avroTransformationSpecified()) { partition = apply(partition, avroDestination(getAvroSchemaDestinationFolder(), getEventId(), getTableLocation())); } return partition; } @Autowired  AvroSerDePartitionTransformation(TransformOptions transformOptions, SchemaCopier copier); @Override Partition transform(Partition partition);  }### Answer:
@Test public void transformOverride() throws Exception { Map<String, Object> avroOverrideOptions = new HashMap<>(); avroOverrideOptions.put(AvroSerDeConfig.BASE_URL, "schemaOverride"); Map<String, Object> transformOptions = new HashMap<>(); transformOptions.put(AvroSerDeConfig.AVRO_SERDE_OPTIONS, avroOverrideOptions); when(tableReplicationEvent.getTransformOptions()).thenReturn(transformOptions); EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location"); when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable); transformation.tableReplicationStart(tableReplicationEvent, "eventId"); HiveObjectUtils.updateSerDeUrl(partition, AVRO_SCHEMA_URL_PARAMETER, "avroSourceUrl"); when(schemaCopier.copy("avroSourceUrl", "schemaOverride/eventId/", tableReplicationEvent, "eventId")) .thenReturn(destinationPath); Partition result = transformation.transform(partition); assertThat(result.getParameters().get(AVRO_SCHEMA_URL_PARAMETER), is(destinationPathString)); }
@Test public void transformNoAvro() { transformation.transform(partition); verifyZeroInteractions(schemaCopier); assertThat(partition, is(newPartition())); }
@Test public void missingEventId() { transformation.transform(partition); verifyZeroInteractions(schemaCopier); assertThat(partition, is(newPartition())); }
@Test public void missingAvroDestinationFolder() { EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location"); when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable); transformation.tableReplicationStart(tableReplicationEvent, "eventId"); transformation.transform(partition); verifyZeroInteractions(schemaCopier); assertThat(partition, is(newPartition())); }
@Test public void transformNoSourceUrl() throws Exception { EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location"); when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable); transformation.tableReplicationStart(tableReplicationEvent, "eventId"); Partition result = transformation.transform(partition); verifyZeroInteractions(schemaCopier); assertThat(result, is(newPartition())); }
@Test public void transform() throws Exception { EventReplicaTable eventReplicaTable = new EventReplicaTable("db", "table", "location"); when(tableReplicationEvent.getReplicaTable()).thenReturn(eventReplicaTable); transformation.tableReplicationStart(tableReplicationEvent, "eventId"); HiveObjectUtils.updateSerDeUrl(partition, AVRO_SCHEMA_URL_PARAMETER, "avroSourceUrl"); when(schemaCopier.copy("avroSourceUrl", "schema/eventId/", tableReplicationEvent, "eventId")) .thenReturn(destinationPath); Partition result = transformation.transform(partition); assertThat(result.getParameters().get(AVRO_SCHEMA_URL_PARAMETER), is(destinationPathString)); }