gt:             if (series.getName().equals("series2")) {
context: /**
   * Copyright (c) 2010-present Abixen Systems. All rights reserved.
   *
   * This library is free software; you can redistribute it and/or modify it under
   * the terms of the GNU Lesser General Public License as published by the Free
   * Software Foundation; either version 2.1 of the License, or (at your option)
   * any later version.
   *
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   * details.
   */
  
  package com.abixen.platform.module.chart.service.impl;
  
  import com.abixen.platform.core.util.ModelKeys;
  import com.abixen.platform.module.chart.dto.DataSourceCsvParametersDTO;
  import com.abixen.platform.module.chart.model.enumtype.ColumnType;
  import com.abixen.platform.module.chart.model.enumtype.DataOrientation;
  import com.abixen.platform.module.chart.model.enumtype.DataSourceFileType;
  import com.abixen.platform.module.chart.model.enumtype.DataValueType;
  import com.abixen.platform.module.chart.model.impl.*;
  import com.abixen.platform.module.chart.repository.DataSetRepository;
  import com.abixen.platform.module.chart.repository.FileDataSourceRepository;
  import com.abixen.platform.module.chart.service.DataSourceImportDataService;
  import com.abixen.platform.module.chart.service.DomainBuilderService;
  import com.abixen.platform.module.chart.util.*;
  import com.abixen.platform.module.configuration.PlatformModuleConfiguration;
  import lombok.extern.slf4j.Slf4j;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import org.junit.runner.RunWith;
  import org.mockito.MockitoAnnotations;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.test.context.ContextConfiguration;
  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
  import org.springframework.transaction.annotation.Transactional;
  
  import javax.annotation.Resource;
  import javax.validation.ConstraintViolation;
  import javax.validation.Validation;
  import javax.validation.Validator;
  import javax.validation.ValidatorFactory;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.util.*;
  import java.util.stream.Stream;
  
  import static org.junit.Assert.*;
  import static org.junit.Assert.assertNotNull;
  
  
  @Slf4j
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = PlatformModuleConfiguration.class)
  public class DataSourceImportDataServiceCsvImplTest {
  
  
      public DomainBuilderService domainBuilderService = new DomainBuilderServiceImpl();
  
  
      @Resource
      public FileDataSourceRepository fileDataSourceRepository;
  
      @Resource
      public DataSetRepository dataSetRepository;
  
      private DataSourceCsvParametersDTO dataSourceCsvParametersDto;
  
      //TODO - missing generic type
      @Autowired
      public DataSourceImportDataService dataSourceImportDataServiceCsv;
  
      private static Validator validator;
  
  
      @BeforeClass
      public static void setUp() {
          ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
          validator = factory.getValidator();
      }
  
  
      @Before
      @SuppressWarnings("unchecked")
      public void setup() throws IOException {
  
          fileDataSourceRepository.deleteAllInBatch();
          MockitoAnnotations.initMocks(this);
          File dataFile = File.createTempFile("tst", "temp0");
          FileWriter fileWriter = new FileWriter(dataFile);
          fileWriter.write("0,1,2,3,4,5,6\n");
          fileWriter.write("0,10,20,30,40,50,60\n");
          fileWriter.write("0,100,200,300,400,500,600\n");
          fileWriter.flush();
  
          FileDataSource ds = domainBuilderService.newFileDataSourceBuilderInstance().base("testCSV", "testCSV", DataSourceFileType.CSV).build();
  
          fileDataSourceRepository.save(ds);
  
          dataSourceCsvParametersDto = new DataSourceCsvParametersDTO();
          dataSourceCsvParametersDto.setName("testName");
          dataSourceCsvParametersDto.setSeparator(ModelKeys.COMMA);
          dataSourceCsvParametersDto.setOrientation(DataOrientation.Rows);
  
          List<DataValueType> dataValueTypes = new ArrayList<>(7);
  
          dataValueTypes.add(0, DataValueType.DOUBLE);
          dataValueTypes.add(1, DataValueType.DOUBLE);
          dataValueTypes.add(2, DataValueType.DOUBLE);
          dataValueTypes.add(3, DataValueType.DOUBLE);
          dataValueTypes.add(4, DataValueType.DOUBLE);
          dataValueTypes.add(5, DataValueType.DOUBLE);
          dataValueTypes.add(6, DataValueType.DOUBLE);
  
          dataSourceCsvParametersDto.setValueTypes(dataValueTypes);
          Map<String, Integer> columns = new HashMap<>(6);
          columns.put("column1", 0);
          columns.put("column2", 1);
          columns.put("column3", 2);
          columns.put("column4", 3);
          columns.put("column5", 4);
          columns.put("column6", 5);
          columns.put("column7", 6);
          dataSourceCsvParametersDto.setColumns(columns);
          dataSourceCsvParametersDto.setFileDataSource(ds);
          dataSourceCsvParametersDto.setCsvFile(dataFile);
  
          log.debug("dataSourceCsvParametersDTO:" + dataSourceCsvParametersDto.toString());
      }
  
  
      @Test
      @Transactional
      public void testValidationDataSource() throws Exception {
          DataSourceCsvParametersDTO dataSourceCsvParametersDTOfail = new DataSourceCsvParametersDTO();
          Set<ConstraintViolation<DataSourceCsvParametersDTO>> constraintViolations = validator.validate(dataSourceCsvParametersDTOfail);
          assertNotEquals(0, constraintViolations.size());
      }
  
      @Test
      @Transactional
      public void testInitSeries() {
          log.debug("Start test initialization of series.");
          dataSourceImportDataServiceCsv.init(dataSourceCsvParametersDto);
          Boolean testVerify = dataSourceImportDataServiceCsv.verify();
          assertTrue(testVerify);
          FileDataSource fileDataSource = dataSourceImportDataServiceCsv.saveData();
          Set<DataSourceColumn> dataSourceColumns = fileDataSource.getColumns();
          assertNotNull(fileDataSource);
          assertEquals(dataSourceColumns.size(), 7);
  
          log.debug("Finish test initialization of series.");
      }
  
      @Test
      @Transactional
      public void testDataSet() throws IOException, IllegalAccessException, InstantiationException {
  
          fillDataSource("datasource_test");
  
          DataSourceColumn dataSourceColumnX = null;
          List<DataSourceColumn> dataSourceColumnsY = new ArrayList<DataSourceColumn>();
  
          //get existed data source
          FileDataSource fileDataSource = fileDataSourceRepository.findByName("datasource_test");
  
          Set<DataSourceColumn> dataSourceColumns = fileDataSource.getColumns();
          for (DataSourceColumn dataSourceColumn : dataSourceColumns) {
              if (dataSourceColumn.getName().equalsIgnoreCase("column1")) {
                  dataSourceColumnX = dataSourceColumn;
              } else {
                  dataSourceColumnsY.add(dataSourceColumn);
              }
          }
  
          //create data set
          DataSetBuilder dataSetBuilder = domainBuilderService.newDataSetBuilderInstance();
          DataSet dataSet = dataSetBuilder.create().build();
  
          //Attach data source to data set
          //dataSet.setDataSource(fileDataSource);
  
          //Create  DataSetSeries 1
          DataSetSeriesBuilder dataSetSeriesBuilder = domainBuilderService.newDataSetSeriesBuilderInstance();
          DataSetSeries dataSetSeries1 = dataSetSeriesBuilder.name("series1").dataSet(dataSet).create().build();
  
          dataSetSeriesBuilder = domainBuilderService.newDataSetSeriesBuilderInstance();
          DataSetSeries dataSetSeries2 = dataSetSeriesBuilder.name("series2").dataSet(dataSet).create().build();
  
          //DataSetSeriesColumn
          DataSetSeriesColumnBuilder dataSetSeriesColumnBuilder = domainBuilderService.newDataSetSeriesColumnBuilderInstance();
          dataSetSeriesColumnBuilder.columnType(ColumnType.X);
          dataSetSeriesColumnBuilder.dataSourceColumn(dataSourceColumnX);
          dataSetSeriesColumnBuilder.name("ColumnX");
          DataSetSeriesColumn dataColumnX = dataSetSeriesColumnBuilder.build();
  
          dataSetSeriesColumnBuilder = domainBuilderService.newDataSetSeriesColumnBuilderInstance();
          dataSetSeriesColumnBuilder.columnType(ColumnType.Z);
          dataSetSeriesColumnBuilder.dataSourceColumn(dataSourceColumnX);
          dataSetSeriesColumnBuilder.name("ColumnZ");
          DataSetSeriesColumn dataColumnZ = dataSetSeriesColumnBuilder.build();
  
          dataSetSeriesColumnBuilder = domainBuilderService.newDataSetSeriesColumnBuilderInstance();
          dataSetSeriesColumnBuilder.columnType(ColumnType.Y);
          dataSetSeriesColumnBuilder.name("series1ColumnY1");
          dataSetSeriesColumnBuilder.dataSourceColumn(dataSourceColumnsY.get(0));
          DataSetSeriesColumn dataSetSeries1ColumnY1 = dataSetSeriesColumnBuilder.build();
  
  
          dataSetSeriesColumnBuilder = domainBuilderService.newDataSetSeriesColumnBuilderInstance();
          dataSetSeriesColumnBuilder.columnType(ColumnType.Y);
          dataSetSeriesColumnBuilder.name("series1ColumnY2");
          dataSetSeriesColumnBuilder.dataSourceColumn(dataSourceColumnsY.get(1));
          DataSetSeriesColumn dataSetSeries1ColumnY2 = dataSetSeriesColumnBuilder.build();
  
          //Attach series columns to data set series1
          dataSetSeries1.setValueSeriesColumn(dataSetSeries1ColumnY1);
  
          //Attach series columns to data set series2
          dataSetSeries2.setValueSeriesColumn(dataSetSeries1ColumnY2);
  
          //Attach data set series to data set
          Set<DataSetSeries> dataSetSeries = new HashSet<>();
  
          dataSetSeries.add(dataSetSeries1);
          dataSetSeries.add(dataSetSeries2);
  
          dataSet.setDomainXSeriesColumn(dataColumnX);
          dataSet.setDomainZSeriesColumn(dataColumnZ);
          dataSet.setDataSetSeries(dataSetSeries);
  
          dataSet = dataSetRepository.saveAndFlush(dataSet);
  
          assertNotNull(dataSet);
          assertEquals(dataSet.getDataSetSeries().size(), 2);
  
          assertNotNull(dataSet.getDomainXSeriesColumn());
          assertNotNull(dataSet.getDomainXSeriesColumn());
  
          for (DataSetSeries series : dataSet.getDataSetSeries()) {
              if (series.getName().equals("series1")) {
                  DataSetSeriesColumn dataSetSeriesColumnY = series.getValueSeriesColumn();
                  assertNotNull(dataSetSeriesColumnY);
              }
  