0

I am trying to write the Junit test cases for the below hazelcast Jet Pipeline.

My component:

@Component
public class UserJetJob extends AbstarctJetJob {

    private static final String TABLE_NAME = "User";

    @Autowired
    private ClientConfig clientConfig;

    @Value("${jdbc.connection_url}")
    private String connectionUrl;

    @Override
    public Pipeline buildPipeline() {
        Pipeline p = Pipeline.create();
        p.readFrom(Sources.jdbc(connectionUrl,
                "SELECT * FROM " + TABLE_NAME,
                UserJetJob::buildUser))
            .map(a -> Util.entry(a.getId(), a))
            .writeTo(Sinks.remoteMap("userMap", clientConfig));
        return p;
    }

}

I am writing a JUnit test case for the method public Pipeline buildPipeline() but it's failing due to the resultset.

@ExtendWith(MockitoExtension.class)
public class UserJetJobTest extends JetTestSupport {

    @InjectMocks
    UserJetJob userJetJob;

    @Mock
    private JetInstance jet;

    @Mock
    private ClientConfig clientConfig;

    @Test
    public void buildPipelineUser() {
        Pipeline p = Mockito.mock(Pipeline.class);
        // Mockito.when(p.readFrom(Sources.jdbc(Mockito.anyString(), Mockito.anyString(), Mockito.eq(ResultSet.class))).then
        userJetJob.buildPipeline();
    }
}

Could you please help me with how to write JUnit test cases?

Vitor Cavalcanti
  • 311
  • 3
  • 13
Pandit Biradar
  • 1,777
  • 3
  • 20
  • 35
  • For testing a pipeline you can run it and assert the output written by sink. The test like the one you started would be aimed to test Jet internals, not to test your pipeline. – Oliv Apr 19 '21 at 07:05
  • Adding to the comment of @Oliv, consider using data generators and assertions as documented here: https://jet-start.sh/docs/api/testing#assertions – Vlado Schreiner Apr 20 '21 at 06:34

0 Answers0