Catalog alignment
[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.Callable;
29 import java.util.concurrent.ExecutionException;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.Future;
32 import java.util.concurrent.TimeUnit;
33 import java.util.concurrent.TimeoutException;
34
35 public class NotificationExecutorServiceTest {
36
37         private NotificationExecutorService createTestSubject() {
38                 return new NotificationExecutorService();
39         }
40
41         @Test
42         public void testCreateExcecutorService() throws Exception {
43                 NotificationExecutorService testSubject;
44                 DistributionNotificationTopicConfig distributionNotificationTopic = new DistributionNotificationTopicConfig();
45                 ExecutorService result;
46
47                 // default test
48                 testSubject = createTestSubject();
49                 result = testSubject.createExcecutorService(distributionNotificationTopic);
50                 distributionNotificationTopic.setMinThreadPoolSize(1);
51                 result = testSubject.createExcecutorService(distributionNotificationTopic);
52                 distributionNotificationTopic.setMaxThreadPoolSize(1);
53                 result = testSubject.createExcecutorService(distributionNotificationTopic);
54         }
55
56         @Test
57         public void testShutdownAndAwaitTermination() throws Exception {
58                 NotificationExecutorService testSubject;
59                 NotificationExecutorServiceMock pool = new NotificationExecutorServiceMock();
60                 long maxTimeToWait = 435435;
61
62                 // default test
63                 testSubject = createTestSubject();
64                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
65                 pool.awaitTermination = true;
66                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
67                 pool.awaitTermination = true;
68                 pool.isShutdownException = true;
69                 testSubject.shutdownAndAwaitTermination(pool, maxTimeToWait);
70         }
71         
72         private class NotificationExecutorServiceMock implements ExecutorService {
73                 
74                 private boolean awaitTermination = false;
75                 private boolean isShutdownException = false;
76                 
77                 @Override
78                 public void execute(Runnable command) {
79                         // TODO Auto-generated method stub
80                         
81                 }
82
83                 @Override
84                 public void shutdown() {
85                         // TODO Auto-generated method stub
86                         
87                 }
88
89                 @Override
90                 public List<Runnable> shutdownNow() {
91                         // TODO Auto-generated method stub
92                         if (isShutdownException) {
93                                 try {
94                                         throw new InterruptedException();
95                                 } catch (InterruptedException e) {
96                                         // TODO Auto-generated catch block
97                                         e.printStackTrace();
98                                 }
99                         }
100                         return null;
101                 }
102
103                 @Override
104                 public boolean isShutdown() {
105                         // TODO Auto-generated method stub
106                         return false;
107                 }
108
109                 @Override
110                 public boolean isTerminated() {
111                         // TODO Auto-generated method stub
112                         return false;
113                 }
114
115                 @Override
116                 public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
117                         // TODO Auto-generated method stub
118                         return awaitTermination;
119                 }
120
121                 @Override
122                 public <T> Future<T> submit(Callable<T> task) {
123                         // TODO Auto-generated method stub
124                         return null;
125                 }
126
127                 @Override
128                 public <T> Future<T> submit(Runnable task, T result) {
129                         // TODO Auto-generated method stub
130                         return null;
131                 }
132
133                 @Override
134                 public Future<?> submit(Runnable task) {
135                         // TODO Auto-generated method stub
136                         return null;
137                 }
138
139                 @Override
140                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
141                         // TODO Auto-generated method stub
142                         return null;
143                 }
144
145                 @Override
146                 public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
147                                 throws InterruptedException {
148                         // TODO Auto-generated method stub
149                         return null;
150                 }
151
152                 @Override
153                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
154                                 throws InterruptedException, ExecutionException {
155                         // TODO Auto-generated method stub
156                         return null;
157                 }
158
159                 @Override
160                 public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
161                                 throws InterruptedException, ExecutionException, TimeoutException {
162                         // TODO Auto-generated method stub
163                         return null;
164                 }
165                 
166         }
167 }