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);
43 DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
45 Gson gson = new Gson();
47 Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
51 // public void validateDownWhenEnvAreDown() {
53 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
54 // envNamePerStatus.put("PROD1", new AtomicBoolean(false));
55 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
57 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
59 // HealthCheckInfo healthCheckInfo =
60 // distributionEngineClusterHealth.getHealthCheckInfo();
61 // assertEquals("verify down", HealthCheckStatus.DOWN,
62 // healthCheckInfo.getHealthCheckStatus());
63 // assertEquals("verify DE component", HealthCheckComponent.DE,
64 // healthCheckInfo.getHealthCheckComponent());
69 public void validateUpWhenQuerySucceed() {
71 // Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
72 // envNamePerStatus.put("PROD1", new AtomicBoolean(true));
73 // envNamePerStatus.put("PROD2", new AtomicBoolean(false));
75 // distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus,
78 CambriaErrorResponse cambriaOkResponse = new CambriaErrorResponse(CambriaOperationStatus.OK, 200);
79 CambriaErrorResponse cambriaErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.INTERNAL_SERVER_ERROR, 500);
80 CambriaErrorResponse cambriaNotErrorResponse = new CambriaErrorResponse(CambriaOperationStatus.AUTHENTICATION_ERROR, 403);
82 List<String> uebServers = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration().getUebServers();
83 if (uebServers.size() >= 2) {
84 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
85 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
88 UebHealthCheckCall healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
89 healthCheckCall1.setCambriaHandler(cambriaHandler);
90 Boolean call1 = healthCheckCall1.call();
91 assertTrue("check response okay", call1);
93 UebHealthCheckCall healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
94 healthCheckCall2.setCambriaHandler(cambriaHandler);
96 Boolean call2 = healthCheckCall2.call();
97 assertTrue("check response okay", call2);
99 if (uebServers.size() >= 2) {
100 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
101 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaOkResponse);
103 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
104 healthCheckCall1.setCambriaHandler(cambriaHandler);
106 call1 = healthCheckCall1.call();
107 assertFalse("check response okay", call1);
109 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
110 healthCheckCall2.setCambriaHandler(cambriaHandler);
112 call2 = healthCheckCall2.call();
113 assertTrue("check response okay", call2);
115 if (uebServers.size() >= 2) {
116 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(0)), Mockito.any(String.class))).thenReturn(cambriaErrorResponse);
117 when(cambriaHandler.getApiKey(Mockito.eq(uebServers.get(1)), Mockito.any(String.class))).thenReturn(cambriaNotErrorResponse);
119 healthCheckCall1 = new UebHealthCheckCall(uebServers.get(0), "publicKey");
120 healthCheckCall1.setCambriaHandler(cambriaHandler);
122 call1 = healthCheckCall1.call();
123 assertFalse("check response okay", call1);
125 healthCheckCall2 = new UebHealthCheckCall(uebServers.get(1), "publicKey");
126 healthCheckCall2.setCambriaHandler(cambriaHandler);
128 call2 = healthCheckCall2.call();
129 assertTrue("check response okay", call2);