3c88ce96aebe82270953a689fd0a524314b9383e
[sdc.git] /
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.be.components.distribution.engine;
22
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
25 import org.junit.Test;
26 import org.mockito.Mock;
27 import org.mockito.Mockito;
28 import org.openecomp.sdc.be.components.BeConfDependentTest;
29 import org.openecomp.sdc.be.config.ConfigurationManager;
30 import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
31
32 import java.util.List;
33
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertTrue;
36 import static org.mockito.Mockito.when;
37
38 public class DistributionEngineHealthCheckTest extends BeConfDependentTest {
39
40     @Mock
41     private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
42
43     @Test
44     public void validateUpWhenQuerySucceed() {
45
46         CambriaErrorResponse cambriaOkResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
47         CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
48         CambriaErrorResponse cambriaNotErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, 403);
49
50         List<String> uebServers = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getUebServers();
51         if (uebServers.size() >= 2) {
52             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
53             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
54         }
55
56         UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
57         healthCheckCall1.setCambriaHandler(cambriaHandler);
58         Boolean call1 = healthCheckCall1.call();
59         assertTrue("check response okay", call1);
60
61         UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
62         healthCheckCall2.setCambriaHandler(cambriaHandler);
63
64         Boolean call2 = healthCheckCall2.call();
65         assertTrue("check response okay", call2);
66
67         if (uebServers.size() >= 2) {
68             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
69             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
70         }
71         healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
72         healthCheckCall1.setCambriaHandler(cambriaHandler);
73
74         call1 = healthCheckCall1.call();
75         assertFalse("check response okay", call1);
76
77         healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
78         healthCheckCall2.setCambriaHandler(cambriaHandler);
79
80         call2 = healthCheckCall2.call();
81         assertTrue("check response okay", call2);
82
83         if (uebServers.size() >= 2) {
84             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
85             when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaNotErrorResponse);
86         }
87         healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
88         healthCheckCall1.setCambriaHandler(cambriaHandler);
89
90         call1 = healthCheckCall1.call();
91         assertFalse("check response okay", call1);
92
93         healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
94         healthCheckCall2.setCambriaHandler(cambriaHandler);
95
96         call2 = healthCheckCall2.call();
97         assertTrue("check response okay", call2);
98
99     }
100
101 }