2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. 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.onap.pnfsimulator.integration.suites;
23 import com.palantir.docker.compose.DockerComposeRule;
24 import com.palantir.docker.compose.connection.waiting.HealthChecks;
25 import org.junit.BeforeClass;
26 import org.junit.ClassRule;
27 import org.junit.runner.RunWith;
28 import org.junit.runners.Suite;
29 import org.junit.runners.Suite.SuiteClasses;
30 import org.onap.pnfsimulator.integration.BasicAvailabilityTest;
31 import org.onap.pnfsimulator.integration.OptionalTemplatesTest;
32 import org.onap.pnfsimulator.integration.SearchInTemplatesTest;
33 import org.onap.pnfsimulator.integration.TemplatesManagementTest;
34 import org.onap.pnfsimulator.integration.VariablesReplacement;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.springframework.http.HttpStatus;
39 import static io.restassured.RestAssured.given;
42 @SuiteClasses({BasicAvailabilityTest.class, TemplatesManagementTest.class, OptionalTemplatesTest.class,
43 SearchInTemplatesTest.class, VariablesReplacement.class})
44 public class DockerBasedTestsSuite {
46 private static final Logger LOGGER = LoggerFactory.getLogger(DockerBasedTestsSuite.class);
48 private static final String HEALTH_CHECK_ADDRESS = "http://0.0.0.0:5000/health";
49 private static final int RETRY_COUNT = 10;
50 private static final int RETRY_INTERVAL = 1000;
53 public static DockerComposeRule docker = DockerComposeRule.builder()
54 .file("../docker-compose.yml")
55 .waitingForService("pnf-simulator", HealthChecks.toHaveAllPortsOpen())
56 .waitingForService("mongo", HealthChecks.toHaveAllPortsOpen())
60 public static void waitForPnfSimulatorToBeHealthy() throws InterruptedException {
61 boolean isHealthy = false;
63 while (!isHealthy && retry < RETRY_COUNT) {
65 LOGGER.info("Checking PNF health, try {} out of {}", retry, RETRY_COUNT);
66 isHealthy = performHealthCheck();
68 LOGGER.info("PNF is healthy");
70 LOGGER.info("PNF no healthy retrying in {}", RETRY_COUNT);
71 Thread.sleep(RETRY_INTERVAL);
76 private static boolean performHealthCheck() {
79 int statusCode = given().get(HEALTH_CHECK_ADDRESS).getStatusCode();
80 if (statusCode == HttpStatus.OK.value()) {
83 } catch (Exception e) {