Fix for radio buttons
[sdc.git] / asdc-tests / src / main / java / org / openecomp / sdc / ci / tests / execute / resource / SimultaneousApiTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.ci.tests.execute.resource;
22
23 import java.util.concurrent.CountDownLatch;
24 import java.util.concurrent.ExecutorService;
25 import java.util.concurrent.Executors;
26
27 import org.junit.Rule;
28 import org.junit.rules.TestName;
29 import org.openecomp.sdc.ci.tests.api.ComponentBaseTest;
30 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
31 import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
33 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
34 import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils;
35 import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser;
36 import org.testng.annotations.Test;
37
38 public class SimultaneousApiTest extends ComponentBaseTest {
39
40         protected static ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource();
41
42         @Rule
43         public static TestName name = new TestName();
44
45         static String httpCspUserId = "km2000";
46         static String userFirstName = "Kot";
47         static String userLastName = "Matroskin";
48         static String email = "km2000@intl.sdc.com";
49         static String role = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN).getRole();
50
51         public SimultaneousApiTest() {
52                 super(name, SimultaneousApiTest.class.getName());
53
54         }
55
56         public static class WorkerThread implements Runnable {
57                 CountDownLatch countDownLatch;
58                 int threadIndex;
59
60                 public WorkerThread(int threadIndex, CountDownLatch countDownLatch) {
61                         this.threadIndex = threadIndex;
62                         this.countDownLatch = countDownLatch;
63                 }
64
65                 @Override
66                 public void run() {
67                         System.out.println("**** Thread started " + threadIndex);
68                         try {
69                                 RestResponse createResource = ResourceRestUtils.createResource(resourceDetails,
70                                                 ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER));
71                                 String id = ResponseParser.getUniqueIdFromResponse(createResource);
72                                 // System.out.println("**** Thread " + threadIndex + " create
73                                 // resource status " + createResource.getErrorCode() + " id = "
74                                 // + id + " error " + createResource.getResponse());
75                                 // assertEquals("**** create resource: " +
76                                 // createResource.getErrorCode() + " thread " + threadIndex,
77                                 // 201, status);
78                         } catch (Exception e) {
79                                 // System.out.println("**** Thread " + threadIndex + " exception
80                                 // " + e);
81                         }
82                         countDownLatch.countDown();
83                         // System.out.println("**** Thread finished " + threadIndex);
84
85                 }
86
87                 // public void run_() {
88                 // System.out.println("**** Thread started " + threadIndex);
89                 // try {
90                 // UserUtils userUtils = new UserUtils();
91                 // User userDetails = new User(userFirstName, userLastName,
92                 // httpCspUserId, email, role , 0L);
93                 // RestResponse response =
94                 // userUtils.createUserTowardsCatalogBe(userDetails,
95                 // userUtils.getUserDetailesAdmin());
96                 // System.out.println("**** Thread " + threadIndex + " create resource
97                 // status " + response.getErrorCode() + " response " +
98                 // response.getResponse());
99                 //// assertEquals("**** create resource: " +
100                 // createResource.getErrorCode() + " thread " + threadIndex, 201,
101                 // status);
102                 // } catch (Exception e) {
103                 // System.out.println("**** Thread " + threadIndex + " exception " + e);
104                 // }
105                 // countDownLatch.countDown();
106                 // System.out.println("**** Thread finished " + threadIndex);
107                 //
108                 // }
109         }
110
111         @Test
112         public void create2Resources() throws InterruptedException {
113                 int threadCount = 5;
114                 CountDownLatch countDownLatch = new CountDownLatch(threadCount);
115                 ExecutorService executor = Executors.newFixedThreadPool(threadCount);
116                 for (int i = 0; i < threadCount; i++) {
117                         Runnable worker = new WorkerThread(i + 1, countDownLatch);
118                         executor.execute(worker);
119                 }
120                 countDownLatch.await();
121                 // System.out.println(" finished ");
122
123         }
124 }