use of org.talend.sdk.component.runtime.manager.extension.ComponentContextImpl in project component-runtime by Talend.
the class BeamComponentExtensionTest method toMapper.
@Test
public void toMapper() throws IOException, ClassNotFoundException {
final ComponentContextImpl context = new ComponentContextImpl(BeamSource.class);
context.setCurrentExtension(extension);
extension.onComponent(context);
context.setCurrentExtension(null);
assertTrue(context.isNoValidation());
assertEquals(extension, context.getOwningExtension());
final Mapper mapper = extension.convert(new ComponentExtension.ComponentInstance() {
@Override
public Object instance() {
return new BeamSource(asList("a", "b"));
}
@Override
public String plugin() {
// path as id
return jarLocation(BeamComponentExtensionTest.class).getAbsolutePath();
}
@Override
public String family() {
return "test";
}
@Override
public String name() {
return "extension";
}
}, Mapper.class);
assertMapper(mapper);
// ensure the mapper is serializable even if not intended to be used this way
final byte[] bytes = Serializer.toBytes(mapper);
try (final ObjectInputStream ois = new EnhancedObjectInputStream(new ByteArrayInputStream(bytes), Thread.currentThread().getContextClassLoader())) {
final Serializable deserialized = Serializable.class.cast(ois.readObject());
assertMapper(Mapper.class.cast(deserialized));
}
}
Aggregations