/*
 * European Variation Archive (EVA) - Open-access database of all types of genetic
 * variation data from all species
 *
 * Copyright 2016 EMBL - European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ebi.eva.server.ws;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.response.Response;
import org.junit.BeforeClass;
import org.junit.Test;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;

import static com.jayway.restassured.RestAssured.given;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class RegionWSServerTest {

    @BeforeClass
    public static void startJetty() throws Exception {
        RestAssured.port = 8080;
        RestAssured.baseURI = "http://localhost:8080/eva/webservices/rest";
    }

    // 2:48000000-49000000

    @Test
    public void testGetVariantById() throws URISyntaxException {
        testGetVariantsByRegionHelper("20:60000-62000", 40);
    }

    private void testGetVariantsByRegionHelper(String testString, int expectedSize) throws URISyntaxException {
        Response response = given().param("species", "mmusculus_grcm38").get(new URI("/v1/segments/" + testString + "/variants"));
        response.then().statusCode(200);

        List queryResponse = JsonPath.from(response.asString()).getList("response");

        List<Map> result = JsonPath.from(response.asString()).getJsonObject("response[0].result");

        assertEquals(expectedSize, result.size());

        for (Map m : result) {
            String missingField = String.format("%s required field missing", m.get("name"));

            assertTrue(missingField, m.containsKey("id"));
            assertTrue(missingField, m.containsKey("chromosome"));
            assertTrue(missingField, m.containsKey("start"));
            assertTrue(missingField, m.containsKey("end"));
        }
    }



}

@@ -1445,30 +1445,150 @@
     
-// 2:48000000-49000000
+@Test%0A    public void testGetVariantsByRegion() throws URISyntaxException %7B%0A        testGetVariantsByRegionHelper(%2220:60000-62000%22, 40);%0A    %7D
 %0A%0A  
@@ -1629,12 +1629,18 @@
 iant
+s
 By
-Id
+Regions
 () t
@@ -1711,33 +1711,48 @@
 (%2220:60000-6
-20
+1000,20:61500-625
 00%22, 
-40
+17
 );%0A    %7D%0A%0A  
@@ -2662,12 +2662,10 @@
 %0A    %7D%0A%0A
-%0A%0A
 %7D%0A

Test ws for multiple regions