<commit_before>/*
 * Copyright 2008-2013 Microarray Informatics Team, 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.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code, * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.web.controllers.page;

import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.ui.Model;
import org.springframework.validation.support.BindingAwareModelMap;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.is;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class ExperimentDesignPageControllerIT {

    @Value("#{configuration['experiment.experiment-design.path.template']}")
    private String experimentDesignTemplate;

    private static final String EXPERIMENT_ACCESSION = "E-GEOD-38400";
    private static final Set<String> LIBRARIES = Sets.newHashSet("SRR504179", "SRR504180", "SRR504181", "SRR504182", "SRR504183", "SRR504184", "SRR504185", "SRR504186", "SRR504187", "SRR576327", "SRR576328", "SRR576329");

    private ExperimentDesignPageController subject;

    Model model = new BindingAwareModelMap();

    @Before
    public void setUp() throws Exception {
        subject = new ExperimentDesignPageController(experimentDesignTemplate);
    }

    @Test
    public void testExtractExperimentDesign() {

        // given
        subject.extractExperimentDesign(model, EXPERIMENT_ACCESSION, LIBRARIES);

        Gson gson = new Gson();

        // then
        Map<String, Object> map = model.asMap();
        assertThat(((String) map.get("assayHeader")), is("Run"));

        // and
        Type stringIntegerMapType = new TypeToken<Map<String, Integer>>() {
        }.getType();
        Map<String, Integer> samples = gson.fromJson((String) map.get("samples"), stringIntegerMapType);
        assertThat(samples.get("Organism"), is(1));
        Map<String, Integer> factors = gson.fromJson((String) map.get("factors"), stringIntegerMapType);
        assertThat(factors.get("strain or line"), is(2));

        // and<commit_msg>fix for new data E-GEOD-38400<commit_after>/*
 * Copyright 2008-2013 Microarray Informatics Team, 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.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code, * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.web.controllers.page;

import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.ui.Model;
import org.springframework.validation.support.BindingAwareModelMap;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItemInArray;
import static org.hamcrest.Matchers.is;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class ExperimentDesignPageControllerIT {

    @Value("#{configuration['experiment.experiment-design.path.template']}")
    private String experimentDesignTemplate;

    private static final String EXPERIMENT_ACCESSION = "E-GEOD-38400";
    private static final Set<String> LIBRARIES = Sets.newHashSet("SRR504179", "SRR504180", "SRR504181", "SRR504182", "SRR504183", "SRR504184", "SRR504185", "SRR504186", "SRR504187", "SRR576327", "SRR576328", "SRR576329");

    private ExperimentDesignPageController subject;

    Model model = new BindingAwareModelMap();

    @Before
    public void setUp() throws Exception {
        subject = new ExperimentDesignPageController(experimentDesignTemplate);
    }

    @Test
    public void testExtractExperimentDesign() {

        // given
        subject.extractExperimentDesign(model, EXPERIMENT_ACCESSION, LIBRARIES);

        Gson gson = new Gson();

        // then
        Map<String, Object> map = model.asMap();
        assertThat(((String) map.get("assayHeader")), is("Run"));

        // and
        Type stringIntegerMapType = new TypeToken<Map<String, Integer>>() {
        }.getType();
        Map<String, Integer> samples = gson.fromJson((String) map.get("samples"), stringIntegerMapType);
        assertThat(samples.get("ecotype"), is(1));
        assertThat(samples.get("Organism"), is(2));
        Map<String, Integer> factors = gson.fromJson((String) map.get("factors"), stringIntegerMapType);
        assertThat(factors.get("genotype"), is(3));

        // and
{'fraction_non_alphanumeric': 0.10971034068737806, 'fraction_numerical': 0.029116013807594175, 'mean_word_length': 4.507438016528925, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5836469', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1865, 'n_words': 491}