diff options
Diffstat (limited to 'components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java')
-rw-r--r-- | components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java index 5e7d83b3..d6298b87 100644 --- a/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java +++ b/components/datalake-handler/feeder/src/test/java/org/onap/datalake/feeder/service/PullServiceTest.java @@ -28,8 +28,10 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.datalake.feeder.config.ApplicationConfiguration; import org.springframework.context.ApplicationContext; +import java.lang.reflect.Field; import java.util.List; import java.util.concurrent.ExecutorService; +import java.util.concurrent.locks.ReentrantReadWriteLock; import static org.junit.Assert.*; import static org.mockito.Mockito.when; @@ -37,36 +39,62 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class PullServiceTest { - @InjectMocks - private PullService pullService; + @InjectMocks + private PullService pullService; - @Mock - private ApplicationContext context; + @Mock + private ApplicationContext context; - @Mock - private ApplicationConfiguration config; + @Mock + private ApplicationConfiguration config; - @Mock - private ExecutorService executorService; + @Mock + private ExecutorService executorService; - @Mock - private List<Puller> consumers; + @Mock + private List<Puller> consumers; - @Test - public void isRunning() { - assertEquals(pullService.isRunning(), false); - } + @Test + public void isRunning() { + assertFalse(pullService.isRunning()); + } - @Test(expected = NullPointerException.class) - public void start() { + @Test(expected = NullPointerException.class) + public void start() { + setRunning(false); + pullService.start(); + setRunning(true); + pullService.start(); + } - when(config.getKafkaConsumerCount()).thenReturn(1); + @Test + public void shutdown() { + when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock()); + setRunning(false); + pullService.shutdown(); + setRunning(true); + pullService.shutdown(); + } - pullService.start(); - } + private void setRunning(boolean running) { + Field configField; + try { + configField = PullService.class.getDeclaredField("isRunning"); + configField.setAccessible(true); + configField.set(pullService, running); + } catch (IllegalArgumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + e.printStackTrace(); - @Test - public void shutdown() { - pullService.shutdown(); - } + } catch (NoSuchFieldException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (SecurityException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } }
\ No newline at end of file |