Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / distribution / engine / NotificationExecutorServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.distribution.engine;
22
23 import org.junit.Test;
24 import org.openecomp.sdc.be.config.DistributionEngineConfiguration.DistributionNotificationTopicConfig;
25
26 import java.util.Collection;
27 import java.util.List;
28 import java.util.concurrent.*;
29
30 public class NotificationExecutorServiceTest {
31
32         private NotificationExecutorService createTestSubject() {
33                 return new NotificationExecutorService();
34         }
35
36         @Test
37         public void testCreateExcecutorService() throws Exception {
38                 NotificationExecutorService testSubject;
39                 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
40                 ExecutorService result;
41
42                 // default test
43                 testSubject = createTestSubject();
44                 result = testSubject.createExcecutorService(distributionNotificationTopic);
45                 distributionNotificationTopic.setMinThreadPoolSize(1);
46                 result = testSubject.createExcecutorService(distributionNotificationTopic);
47                 distributionNotificationTopic.setMaxThreadPoolSize(1);
48                 result = testSubject.createExcecutorService(distributionNotificationTopic);
49         }
50
51         @Test
52         public void testShutdownAndAwaitTermination() throws Exception {
53                 NotificationExecutorService testSubject;
54                 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
55                 long maxTimeToWait = 435435;
56
57                 // default test
58                 testSubject = createTestSubject();
59                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
60                 pool.awaitTermination = true;
61                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
62                 pool.awaitTermination = true;
63                 pool.isShutdownException = true;
64                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
65         }
66         
67         private class NotificationExecutorServiceMock implements ExecutorService {
68                 
69                 private boolean awaitTermination = false;
70                 private boolean isShutdownException = false;
71                 
72                 @Override
73                 public void execute(Runnable command) {
74                         // TODO Auto-generated method stub
75                         
76                 }
77
78                 @Override
79                 public void shutdown() {
80                         // TODO Auto-generated method stub
81                         
82                 }
83
84                 @Override
85                 public List<Runnable> shutdownNow() {
86                         // TODO Auto-generated method stub
87                         if (isShutdownException) {
88                                 try {
89                                         throw new InterruptedException();
90                                 } catch (InterruptedException e) {
91                                         // TODO Auto-generated catch block
92                                         e.printStackTrace();
93                                 }
94                         }
95                         return null;
96                 }
97
98                 @Override
99                 public boolean isShutdown() {
100                         // TODO Auto-generated method stub
101                         return false;
102                 }
103
104                 @Override
105                 public boolean isTerminated() {
106                         // TODO Auto-generated method stub
107                         return false;
108                 }
109
110                 @Override
111                 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
112                         // TODO Auto-generated method stub
113                         return awaitTermination;
114                 }
115
116                 @Override
117                 public <T> Future<T> submit(Callable<T> task) {
118                         // TODO Auto-generated method stub
119                         return null;
120                 }
121
122                 @Override
123                 public <T> Future<T> submit(Runnable task, T result) {
124                         // TODO Auto-generated method stub
125                         return null;
126                 }
127
128                 @Override
129                 public Future<?> submit(Runnable task) {
130                         // TODO Auto-generated method stub
131                         return null;
132                 }
133
134                 @Override
135                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
136                         // TODO Auto-generated method stub
137                         return null;
138                 }
139
140                 @Override
141                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
142                                 throws InterruptedException {
143                         // TODO Auto-generated method stub
144                         return null;
145                 }
146
147                 @Override
148                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
149                                 throws InterruptedException, ExecutionException {
150                         // TODO Auto-generated method stub
151                         return null;
152                 }
153
154                 @Override
155                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
156                                 throws InterruptedException, ExecutionException, TimeoutException {
157                         // TODO Auto-generated method stub
158                         return null;
159                 }
160                 
161         }
162 }