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 static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
27 import java.util.List;
29 import org.junit.Test;
30 import org.mockito.Mock;
31 import org.mockito.Mockito;
32 import org.openecomp.sdc.be.components.BaseConfDependentTest;
33 import org.openecomp.sdc.be.config.ConfigurationManager;
34 import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
36 import com.google.gson.Gson;
37 import com.google.gson.GsonBuilder;
39 public class DistributionEngineHealthCheckTest extends BaseConfDependentTest {
42 private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
44 DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
46 Gson gson = new Gson();
48 Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
52 // public void validateDownWhenEnvAreDown() {
54 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
55 // envNamePerStatus.put("PROD1", new AtomicBoolean(false));
56 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
58 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
60 // HealthCheckInfo healthCheckInfo =
61 // distributionEngineClusterHealth.getHealthCheckInfo();
62 // assertEquals("verify down", HealthCheckStatus.DOWN,
63 // healthCheckInfo.getHealthCheckStatus());
64 // assertEquals("verify DE component", HealthCheckComponent.DE,
65 // healthCheckInfo.getHealthCheckComponent());
70 public void validateUpWhenQuerySucceed() {
72 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
73 // envNamePerStatus.put("PROD1", new AtomicBoolean(true));
74 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
76 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus,
79 CambriaErrorResponse cambriaOkResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
80 CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
81 CambriaErrorResponse cambriaNotErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, 403);
83 List<String> uebServers = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getUebServers();
84 if (uebServers.size() >= 2) {
85 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
86 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
89 UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
90 healthCheckCall1.setCambriaHandler(cambriaHandler);
91 Boolean call1 = healthCheckCall1.call();
92 assertTrue("check response okay", call1);
94 UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
95 healthCheckCall2.setCambriaHandler(cambriaHandler);
97 Boolean call2 = healthCheckCall2.call();
98 assertTrue("check response okay", call2);
100 if (uebServers.size() >= 2) {
101 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
102 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
104 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
105 healthCheckCall1.setCambriaHandler(cambriaHandler);
107 call1 = healthCheckCall1.call();
108 assertFalse("check response okay", call1);
110 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
111 healthCheckCall2.setCambriaHandler(cambriaHandler);
113 call2 = healthCheckCall2.call();
114 assertTrue("check response okay", call2);
116 if (uebServers.size() >= 2) {
117 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
118 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaNotErrorResponse);
120 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
121 healthCheckCall1.setCambriaHandler(cambriaHandler);
123 call1 = healthCheckCall1.call();
124 assertFalse("check response okay", call1);
126 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
127 healthCheckCall2.setCambriaHandler(cambriaHandler);
129 call2 = healthCheckCall2.call();
130 assertTrue("check response okay", call2);