re base code
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / distribution / engine / NotificationExecutorServiceTest.java
1 package org.openecomp.sdc.be.components.distribution.engine;
2
3 import org.junit.Test;
4 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
5
6 import java.util.Collection;
7 import java.util.List;
8 import java.util.concurrent.*;
9
10 public class NotificationExecutorServiceTest {
11
12         private NotificationExecutorService createTestSubject() {
13                 return new NotificationExecutorService();
14         }
15
16         @Test
17         public void testCreateExcecutorService() throws Exception {
18                 NotificationExecutorService testSubject;
19                 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
20                 ExecutorService result;
21
22                 // default test
23                 testSubject = createTestSubject();
24                 result = testSubject.createExcecutorService(distributionNotificationTopic);
25                 distributionNotificationTopic.setMinThreadPoolSize(1);
26                 result = testSubject.createExcecutorService(distributionNotificationTopic);
27                 distributionNotificationTopic.setMaxThreadPoolSize(1);
28                 result = testSubject.createExcecutorService(distributionNotificationTopic);
29         }
30
31         @Test
32         public void testShutdownAndAwaitTermination() throws Exception {
33                 NotificationExecutorService testSubject;
34                 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
35                 long maxTimeToWait = 435435;
36
37                 // default test
38                 testSubject = createTestSubject();
39                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
40                 pool.awaitTermination = true;
41                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
42                 pool.awaitTermination = true;
43                 pool.isShutdownException = true;
44                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
45         }
46         
47         private class NotificationExecutorServiceMock implements ExecutorService {
48                 
49                 private boolean awaitTermination = false;
50                 private boolean isShutdownException = false;
51                 
52                 @Override
53                 public void execute(Runnable command) {
54                         // TODO Auto-generated method stub
55                         
56                 }
57
58                 @Override
59                 public void shutdown() {
60                         // TODO Auto-generated method stub
61                         
62                 }
63
64                 @Override
65                 public List<Runnable> shutdownNow() {
66                         // TODO Auto-generated method stub
67                         if (isShutdownException) {
68                                 try {
69                                         throw new InterruptedException();
70                                 } catch (InterruptedException e) {
71                                         // TODO Auto-generated catch block
72                                         e.printStackTrace();
73                                 }
74                         }
75                         return null;
76                 }
77
78                 @Override
79                 public boolean isShutdown() {
80                         // TODO Auto-generated method stub
81                         return false;
82                 }
83
84                 @Override
85                 public boolean isTerminated() {
86                         // TODO Auto-generated method stub
87                         return false;
88                 }
89
90                 @Override
91                 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
92                         // TODO Auto-generated method stub
93                         return awaitTermination;
94                 }
95
96                 @Override
97                 public <T> Future<T> submit(Callable<T> task) {
98                         // TODO Auto-generated method stub
99                         return null;
100                 }
101
102                 @Override
103                 public <T> Future<T> submit(Runnable task, T result) {
104                         // TODO Auto-generated method stub
105                         return null;
106                 }
107
108                 @Override
109                 public Future<?> submit(Runnable task) {
110                         // TODO Auto-generated method stub
111                         return null;
112                 }
113
114                 @Override
115                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
116                         // TODO Auto-generated method stub
117                         return null;
118                 }
119
120                 @Override
121                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
122                                 throws InterruptedException {
123                         // TODO Auto-generated method stub
124                         return null;
125                 }
126
127                 @Override
128                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
129                                 throws InterruptedException, ExecutionException {
130                         // TODO Auto-generated method stub
131                         return null;
132                 }
133
134                 @Override
135                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
136                                 throws InterruptedException, ExecutionException, TimeoutException {
137                         // TODO Auto-generated method stub
138                         return null;
139                 }
140                 
141         }
142 }