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.components.distribution.engine.CambriaErrorResponse;
34 import org.openecomp.sdc.be.components.distribution.engine.CambriaHandler;
35 import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth;
36 import org.openecomp.sdc.be.components.distribution.engine.UebHealthCheckCall;
37 import org.openecomp.sdc.be.config.ConfigurationManager;
38 import org.openecomp.sdc.be.distribution.api.client.CambriaOperationStatus;
40 import com.google.gson.Gson;
41 import com.google.gson.GsonBuilder;
43 public class DistributionEngineHealthCheckTest extends BaseConfDependentTest {
46 private CambriaHandler cambriaHandler = Mockito.mock(CambriaHandler.class);
48 DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
50 Gson gson = new Gson();
52 Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
56 // public void validateDownWhenEnvAreDown() {
58 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
59 // envNamePerStatus.put("PROD1", new AtomicBoolean(false));
60 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
62 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
64 // HealthCheckInfo healthCheckInfo =
65 // distributionEngineClusterHealth.getHealthCheckInfo();
66 // assertEquals("verify down", HealthCheckStatus.DOWN,
67 // healthCheckInfo.getHealthCheckStatus());
68 // assertEquals("verify DE component", HealthCheckComponent.DE,
69 // healthCheckInfo.getHealthCheckComponent());
74 public void validateUpWhenQuerySucceed() {
76 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
77 // envNamePerStatus.put("PROD1", new AtomicBoolean(true));
78 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
80 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus,
83 CambriaErrorResponse cambriaOkResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
84 CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
85 CambriaErrorResponse cambriaNotErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, 403);
87 List<String> uebServers = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getUebServers();
88 if (uebServers.size() >= 2) {
89 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
90 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
93 UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
94 healthCheckCall1.setCambriaHandler(cambriaHandler);
95 Boolean call1 = healthCheckCall1.call();
96 assertTrue("check response okay", call1);
98 UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
99 healthCheckCall2.setCambriaHandler(cambriaHandler);
101 Boolean call2 = healthCheckCall2.call();
102 assertTrue("check response okay", call2);
104 if (uebServers.size() >= 2) {
105 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
106 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
108 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
109 healthCheckCall1.setCambriaHandler(cambriaHandler);
111 call1 = healthCheckCall1.call();
112 assertFalse("check response okay", call1);
114 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
115 healthCheckCall2.setCambriaHandler(cambriaHandler);
117 call2 = healthCheckCall2.call();
118 assertTrue("check response okay", call2);
120 if (uebServers.size() >= 2) {
121 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
122 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaNotErrorResponse);
124 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
125 healthCheckCall1.setCambriaHandler(cambriaHandler);
127 call1 = healthCheckCall1.call();
128 assertFalse("check response okay", call1);
130 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
131 healthCheckCall2.setCambriaHandler(cambriaHandler);
133 call2 = healthCheckCall2.call();
134 assertTrue("check response okay", call2);