2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.distribution.engine;
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;
32 import java.util.List;
34 import static org.junit.Assert.assertFalse;
35 import static org.junit.Assert.assertTrue;
36 import static org.mockito.Mockito.when;
38 public class DistributionEngineHealthCheckTest extends BeConfDependentTest {
41 private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
44 public void validateUpWhenQuerySucceed() {
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);
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);
56 UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
57 healthCheckCall1.setCambriaHandler(cambriaHandler);
58 Boolean call1 = healthCheckCall1.call();
59 assertTrue("check response okay", call1);
61 UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
62 healthCheckCall2.setCambriaHandler(cambriaHandler);
64 Boolean call2 = healthCheckCall2.call();
65 assertTrue("check response okay", call2);
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);
71 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
72 healthCheckCall1.setCambriaHandler(cambriaHandler);
74 call1 = healthCheckCall1.call();
75 assertFalse("check response okay", call1);
77 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
78 healthCheckCall2.setCambriaHandler(cambriaHandler);
80 call2 = healthCheckCall2.call();
81 assertTrue("check response okay", call2);
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);
87 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
88 healthCheckCall1.setCambriaHandler(cambriaHandler);
90 call1 = healthCheckCall1.call();
91 assertFalse("check response okay", call1);
93 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
94 healthCheckCall2.setCambriaHandler(cambriaHandler);
96 call2 = healthCheckCall2.call();
97 assertTrue("check response okay", call2);