diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..6cdc7d7d --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/java +{ + "name": "Java", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/java:0-17", + + "features": { + "ghcr.io/devcontainers/features/java:1": { + "version": "none", + "installMaven": "true", + "installGradle": "false" + } + } + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "java -version", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 00000000..90bc65af --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,50 @@ +name: Java CI G7 + +on: + push: + branches: [ main ] + +jobs: + build: + environment: env + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'temurin' + cache: maven + - name: Deploy + run: mvn -B package --file pom.xml + - name: Upload application + uses: appleboy/scp-action@master + with: + host: drobles.cl + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + source: "/home/runner/work/ms-iclab/ms-iclab/build/DevOpsUsach2020-0.0.1.jar" + target: "/home/ec2-user/" + - name: Start Service DevOpsUsach2020 + uses: appleboy/ssh-action@master + with: + host: drobles.cl + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + port: ${{ secrets.PORT }} + script: | + mv /home/ec2-user/devops.jar /home/ec2-user/devops-old.jar || true + mv /home/ec2-user/github/workspace/build/DevOpsUsach2020-0.0.1.jar /home/ec2-user/devops.jar + killall java + java -jar /home/ec2-user/devops.jar >> /dev/null & + - name: Sleep for 10 seconds + uses: jakejarvis/wait-action@master + with: + time: '10s' + - name: Test url using Curl + run: curl -X GET 'http://grupo7.drobles.cl/rest/mscovid/estadoPais?pais=chile' + shell: bash + diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..7b016a89 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..6b5b321a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,298 @@ +import groovy.json.JsonSlurperClassic +import hudson.Util; +def jsonParse(def json) { + new groovy.json.JsonSlurperClassic().parseText(json) +} +def current_stage +def build_duration_msg = "\n *Detail by Stage* \n" +pipeline { + agent any + environment { + GITHUB_EMAIL = credentials('GITHUB_EMAIL') + GITHUB_USERNAME = credentials('GITHUB_USERNAME') + GRUPO_CHANNEL = 'D045253KTEZ' + NOMBRE_GRUPO = 'Grupo 7' + } + stages { + stage("Paso 1: Compilar"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 1: Compiling code!'" + sh "./mvnw clean compile -e" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 2: Testear"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 2: Testing code!'" + sh "./mvnw clean test -e" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 3: Build .Jar"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 3: Building .Jar file!'" + sh "./mvnw clean package -e" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 4: Run .Jar"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 4: Running .Jar file!'" + sh "nohup bash ./mvnw spring-boot:run & >/dev/null" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 5: Testing deploy"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 5: Testing deploy!'" + sh "sleep 20" + sh "curl -X GET 'http://localhost:8081/rest/mscovid/estadoPais?pais=Chile'" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 6: Running postman tests"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 6: Testing deploy!'" + sh "newman run test_api_covid.postman_collection.json" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 7: stop Testing deploy"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 7: Stopping jar running'" + sh "sleep 10" + sh '''kill -9 $(pidof java | awk '{print $1}')''' + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 8: Analizar en Sonar"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + withSonarQubeEnv('sonarqube') { + sh "echo 'Stage 8: Static code analysis in Sonar'" + sh 'sh mvnw clean verify sonar:sonar -Dsonar.projectKey=com.devopsusach2020:DevOpsUsach2020' + } + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage("Paso 9: Release Subir Artefacto a Nexus"){ + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 9:Uploading artifact to Nexus'" + MY_VERSION = env.BRANCH_NAME.substring(8) + nexusPublisher nexusInstanceId: 'maven-ceres-repository', + nexusRepositoryId: 'maven-usach-ceres', + packages: [ + [$class: 'MavenPackage', + mavenAssetList: [ + [classifier: '', + extension: 'jar', + filePath: 'build/DevOpsUsach2020-0.0.1.jar' + ] + ], + mavenCoordinate: [ + artifactId: 'DevOpsUsach2020', + groupId: 'com.devopsusach2020', + packaging: 'jar', + version: MY_VERSION + ] + ] + ] + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage('Paso 10: Descargar ultima version jar de Nexus') { + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 10:Downloading artifact from Nexus'" + MY_VERSION = env.BRANCH_NAME.substring(8) + MY_EXTENSION = ".jar" + sh "curl -X GET 'http://nexus:8081/repository/maven-usach-ceres/com/devopsusach2020/DevOpsUsach2020/$MY_VERSION/DevOpsUsach2020-$MY_VERSION$MY_EXTENSION' -O" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage('Paso 11: Levantar y testear Artefacto Jar obtenido de nexus') { + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 11:Testing artifact downloaded from Nexus'" + sh "nohup java -jar DevOpsUsach2020-$MY_VERSION$MY_EXTENSION & >/dev/null" + sh "sleep 20 && curl -X GET 'http://jenkins:8081/rest/mscovid/estadoPais?pais=ecuador'" + sh "sleep 20 && curl -X GET 'http://jenkins:8081/rest/mscovid/estadoMundial'" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage('Paso 12:Detener Atefacto jar en Jenkins server') { + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 12: Stopping artifact'" + sh "sleep 10" + sh '''kill -9 $(pidof java | awk '{print $1}')''' + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage('Paso 13: Desplegar en Produccion') { + when { anyOf { branch 'release/*' } } + steps { + script { + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 13: Deploying on production'" + sh "echo 'enviado a produccion $MY_VERSION'" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + } + } + stage('Paso 14: Merge y Tag en Github') { + when { anyOf { branch 'release/*' } } + steps { + withCredentials([ + gitUsernamePassword(credentialsId: 'github-jenkins', gitToolName: 'Default') + ]) { + script{ + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 14: Merging branch release on main and develop and create tag'" + //Release branch has been merged into '$GITHUB_EMAIL' + sh "git config --global user.email '$GITHUB_EMAIL'" + sh "git config --global user.name '$GITHUB_USERNAME'" + sh "git checkout ${env.BRANCH_NAME}" + sh "git pull origin" + + sh "git checkout main" + sh "git fetch origin" + sh "git pull origin main" + sh "git merge ${env.BRANCH_NAME}" + sh "git push origin main" + + //traer el ultimo tag del origin + MY_VERSION_TAG = sh(returnStdout: true, script: 'git tag --sort=-creatordate | head -n 1').trim() + if (MY_VERSION_TAG == MY_VERSION) { + sh "git tag -d ${MY_VERSION}" + sh "git push --delete origin ${MY_VERSION}" + sh "git tag -a $MY_VERSION -m 'update release from Jenkins'" + sh "git push origin $MY_VERSION" + } else { + sh "git tag -a $MY_VERSION -m 'update release from Jenkins'" + sh "git push origin $MY_VERSION" + } + + //Release tag has been back-merged into 'develop' + sh "git checkout develop" + sh "git pull origin develop" + sh "git merge ${env.BRANCH_NAME}" + sh "git push origin develop" + + //Release branch has been remotely deleted from 'origin' + sh "git push origin --delete ${env.BRANCH_NAME}" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + + } + } + } + stage('Paso 15: Merge con develop en Github') { + when { branch 'feature/*' } + steps { + withCredentials([ + gitUsernamePassword(credentialsId: 'github-jenkins', gitToolName: 'Default') + ]) { + script{ + start = System.currentTimeMillis() + current_stage =env.STAGE_NAME + sh "echo 'Stage 15: Merging branch feature on develop'" + //Release branch has been merged into '$GITHUB_EMAIL' + sh "git config --global user.email '$GITHUB_EMAIL'" + sh "git config --global user.name '$GITHUB_USERNAME'" + sh "git checkout ${env.BRANCH_NAME}" + sh "git pull origin" + + //merge into develop + sh "git checkout develop" + sh "git pull origin develop" + sh "git merge ${env.BRANCH_NAME}" + sh "git push origin develop" + + //Release branch has been remotely deleted from 'origin' + sh "git push origin --delete ${env.BRANCH_NAME}" + end = System.currentTimeMillis() + build_duration_msg = build_duration_msg + "*" + current_stage + "*" + " : " + Util.getTimeSpanString(end - start) +"\n" + } + + } + } + } + } + post{ + always{ + script{ + build_duration_msg = build_duration_msg + "\n *Total build time:* " + "${currentBuild.durationString}".replaceAll(' and counting', "") + } + } + success{ + script{ + current_stage = "Post Build" + slackSend color: 'good', message: "[${NOMBRE_GRUPO}] [${env.JOB_NAME}][Rama : ${env.BRANCH_NAME}] [Stage :${current_stage}][Resultado: ${currentBuild.result}](<${env.BUILD_URL}|Detalle>)${build_duration_msg}", tokenCredentialId: 'id-token-slack' + } + } + failure{ + slackSend color: 'danger', message: "[${NOMBRE_GRUPO}] [${env.JOB_NAME}][Rama : ${env.BRANCH_NAME}] [Stage :${current_stage}][Resultado:${currentBuild.result}](<${env.BUILD_URL}|Detalle>)${build_duration_msg}", tokenCredentialId: 'id-token-slack' + } + } +} diff --git a/README.md b/README.md index 9b67037b..5482b6d7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Getting Started +======= ## Windows - +V1.0.9 test postman +======= ### Compile Code * ./mvnw.cmd clean compile -e @@ -44,3 +46,7 @@ - Agregar archivo **_Jenkinsfile_** en la raíz de la rama del proyecto a procesar (sólo como pivote al código del pipeline). - Registrar Pipeline en **_Jenkins -> Administrar Jenkins -> Configuración Global -> Global Pipeline Libraries_** bajo el nombre **_pipeline_** - Configurar _Multibranch Pipeline Job_ o _Pipeline Job_ en Jenkins con el repositorio del proyecto a procesar. + + +# Integrantes +- Diego Bustamante diff --git a/src/main/java/com/devopsusach2020/model/Valida.java b/src/main/java/com/devopsusach2020/model/Valida.java new file mode 100644 index 00000000..bd0afb80 --- /dev/null +++ b/src/main/java/com/devopsusach2020/model/Valida.java @@ -0,0 +1,14 @@ +package com.devopsusach2020.model; + +public class Valida { + boolean statusAPI; + + public void setStatusAPI(boolean statusAPI){ + this.statusAPI = statusAPI; + } + + public boolean getStatusAPI() + { + return this.statusAPI; + } +} diff --git a/src/main/java/com/devopsusach2020/rest/RestData.java b/src/main/java/com/devopsusach2020/rest/RestData.java index e06ca00f..b2e44753 100644 --- a/src/main/java/com/devopsusach2020/rest/RestData.java +++ b/src/main/java/com/devopsusach2020/rest/RestData.java @@ -3,6 +3,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -14,6 +15,7 @@ import com.devopsusach2020.model.Pais; import com.devopsusach2020.model.Mundial; +import com.devopsusach2020.model.Valida; import com.google.gson.Gson; @RestController @@ -23,13 +25,69 @@ public class RestData { private final static Logger LOGGER = Logger.getLogger("devops.subnivel.Control"); - @GetMapping(path = "/test", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody Pais getData(@RequestParam(name = "msg") String message){ - - LOGGER.log(Level.INFO, "Proceso exitoso de prueba"); + @GetMapping(path = "/estadoPais", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Pais getTotalPais(@RequestParam(name = "pais") String message){ + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity call = restTemplate.getForEntity("https://api.covid19api.com/live/country/" + message, String.class); + LOGGER.log(Level.INFO, "Consulta por pais "); Pais response = new Pais(); - response.setMensaje("Mensaje Recibido: " + message); + int confirmed = 0; + int death = 0; + int recovered = 0; + Gson gson = new Gson(); + Pais[] estados = gson.fromJson(call.getBody().toLowerCase(), Pais[].class); + for(Pais estado : estados){ + response.setDate(estado.getDate()); + response.setActive(estado.getActive()); + confirmed += estado.getConfirmed(); + death += estado.getDeaths(); + recovered += estado.getRecovered(); + } + response.setConfirmed(confirmed); + response.setDeaths(death); + response.setRecovered(recovered); + response.setCountry(message); + response.setMensaje("ok"); + return response; + } + +@GetMapping(path = "/estadoMundial", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Mundial getTotalMundial(){ + + LOGGER.log(Level.INFO, "Consulta mundial"); + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity call = restTemplate.getForEntity("https://api.covid19api.com/world/total", String.class); + Mundial response = new Mundial(); + Gson gson = new Gson(); + Mundial estado = gson.fromJson(call.getBody().toLowerCase(), Mundial.class); + response.setTotalConfirmed(estado.getTotalConfirmed()); + response.setTotalDeaths(estado.getTotalDeaths()); + response.setTotalRecovered(estado.getTotalRecovered()); return response; } -} + @GetMapping(path = "/checkAPI", produces = MediaType.APPLICATION_JSON_VALUE) + public @ResponseBody Valida ValidaApiCovid(){ + + LOGGER.log(Level.INFO, "Validación API COVID"); + RestTemplate restTemplate = new RestTemplate(); + Valida valida = new Valida(); + + try{ + ResponseEntity call = restTemplate.getForEntity("https://api.covid19api.com/", String.class); + HttpStatus responseCode = call.getStatusCode(); + if(responseCode.value() == 200) + { + valida.setStatusAPI(true); + } + else{ + valida.setStatusAPI(false); + } + } + catch(Exception ex){ + valida.setStatusAPI(false); + } + + return valida; + } +} \ No newline at end of file diff --git a/src/test/java/com/devopsusach2020/DevOpsUsach2020ApplicationTests.java b/src/test/java/com/devopsusach2020/DevOpsUsach2020ApplicationTests.java index 0849fbe9..d1820099 100644 --- a/src/test/java/com/devopsusach2020/DevOpsUsach2020ApplicationTests.java +++ b/src/test/java/com/devopsusach2020/DevOpsUsach2020ApplicationTests.java @@ -1,10 +1,12 @@ package com.devopsusach2020; + + import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class DevOpsUsach2020ApplicationTests { +class DevOpsUsach2020ApplicationTests { @Test void contextLoads() { diff --git a/src/test/java/com/devopsusach2020/EstadoMundialTest.java b/src/test/java/com/devopsusach2020/EstadoMundialTest.java new file mode 100644 index 00000000..6cbf6a9d --- /dev/null +++ b/src/test/java/com/devopsusach2020/EstadoMundialTest.java @@ -0,0 +1,33 @@ +package com.devopsusach2020; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import com.devopsusach2020.rest.RestData; + +@SpringBootTest +public class EstadoMundialTest { + RestData rest = new RestData(); + + @Test + void estadoMundialTotalconfirmed() { + assertEquals(true,rest.ValidaApiCovid().getStatusAPI()); + assertTrue(rest.getTotalMundial().getTotalConfirmed() >= 0); + } + + @Test + void estadoMundialTotalDeath() { + assertEquals(true,rest.ValidaApiCovid().getStatusAPI()); + assertTrue(rest.getTotalMundial().getTotalDeaths() >= 0); + } + + @Test + void estadoMundialTotalRecovered() { + + assertTrue(rest.getTotalMundial().getTotalRecovered() >= 0); + } + +} \ No newline at end of file diff --git a/src/test/java/com/devopsusach2020/EstadoPais.java b/src/test/java/com/devopsusach2020/EstadoPais.java new file mode 100644 index 00000000..67eb9539 --- /dev/null +++ b/src/test/java/com/devopsusach2020/EstadoPais.java @@ -0,0 +1,34 @@ + +package com.devopsusach2020; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import com.devopsusach2020.rest.RestData; + +@SpringBootTest +public class EstadoPais { + RestData rest = new RestData(); + + @Test + void estadoMuertesPais() throws Exception { + + assertEquals(true,rest.ValidaApiCovid().getStatusAPI()); + assertTrue(rest.getTotalPais("Chile").getDeaths() >= 0); + } + @Test + void estadoConfirmadoPais() throws Exception { + + assertEquals(true,rest.ValidaApiCovid().getStatusAPI()); + assertTrue(rest.getTotalPais("Chile").getConfirmed() >= 0); + } + @Test + void estadoMensajePais() throws Exception { + + assertEquals(true,rest.ValidaApiCovid().getStatusAPI()); + assertEquals("ok", rest.getTotalPais("Chile").getMensaje()); + } +} \ No newline at end of file diff --git a/test_api_covid.postman_collection.json b/test_api_covid.postman_collection.json new file mode 100644 index 00000000..f5ad0879 --- /dev/null +++ b/test_api_covid.postman_collection.json @@ -0,0 +1,149 @@ +{ + "info": { + "_postman_id": "cdbb70f8-a9c2-4355-a643-38947c95c602", + "name": "Test API Covid", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "estadoPais", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "const schema = {\r", + " \"type\": \"object\",\r", + " \"properties\":{\r", + " \"deaths\":{\r", + " \"type\" : \"number\"\r", + " },\r", + " \"confirmed\":{\r", + " \"type\": \"number\"\r", + " },\r", + " \"date\":{\r", + " \"type\": \"string\"\r", + " },\r", + " \"mensaje\":{\r", + " \"type\": \"string\"\r", + " },\r", + " \"country\":{\r", + " \"type\": \"string\"\r", + " },\r", + " \"recovered\":{\r", + " \"type\": \"number\"\r", + " },\r", + " \"active\":{\r", + " \"type\": \"number\"\r", + " }\r", + " }, \r", + " \"required\": [\r", + " \"deaths\",\r", + " \"confirmed\",\r", + " \"date\",\r", + " \"mensaje\",\r", + " \"country\",\r", + " \"recovered\",\r", + " \"active\"\r", + " ]\r", + "};\r", + "pm.test(\"Status code is 200\", function () {\r", + " pm.expect(pm.response).to.have.status(200);\r", + "});\r", + "pm.test(\"Mensaje == ok\", function () {\r", + " pm.expect(pm.response.responseTime).to.be.below(15000);\r", + "});\r", + "pm.test('Schema is valid', function() {\r", + " pm.response.to.have.jsonSchema(schema);\r", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8081/rest/mscovid/estadoPais?pais=ecuador", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8081", + "path": [ + "rest", + "mscovid", + "estadoPais" + ], + "query": [ + { + "key": "pais", + "value": "ecuador" + } + ] + } + }, + "response": [] + }, + { + "name": "estadoMundialRespuesta", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "const schema = {\r", + " \"type\": \"object\",\r", + " \"properties\":{\r", + " \"totalRecovered\":{\r", + " \"type\" : \"number\"\r", + " },\r", + " \"totalConfirmed\":{\r", + " \"type\": \"number\"\r", + " },\r", + " \"totalDeaths\":{\r", + " \"type\": \"number\"\r", + " }\r", + " },\r", + " \"required\": [\r", + " \"totalRecovered\",\r", + " \"totalConfirmed\",\r", + " \"totalDeaths\"\r", + " ] \r", + "};\r", + "pm.test(\"Status code is 200\", function () {\r", + " pm.expect(pm.response).to.have.status(200);\r", + "});\r", + "pm.test(\"Mensaje == ok\", function () {\r", + " pm.expect(pm.response.responseTime).to.be.below(3000);\r", + "});\r", + "pm.test('Schema is valid', function() {\r", + " pm.response.to.have.jsonSchema(schema);\r", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8081/rest/mscovid/estadoMundial", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8081", + "path": [ + "rest", + "mscovid", + "estadoMundial" + ] + } + }, + "response": [] + } + ] +}