/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.beam.runners.spark.structuredstreaming.translation.batch;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.apache.beam.runners.spark.structuredstreaming.SparkPipelineOptions;
import org.apache.beam.runners.spark.structuredstreaming.SparkRunner;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.options.PipelineOptionsFactory;
import org.apache.beam.sdk.transforms.Create;
import org.apache.beam.sdk.transforms.GroupByKey;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Test class for beam to spark {@link ParDo} translation. */
@RunWith(JUnit4.class)
public class GroupByKeyTest implements Serializable {
  private static Pipeline pipeline;

  @BeforeClass
  public static void beforeClass() {
    PipelineOptions options = PipelineOptionsFactory.create().as(SparkPipelineOptions.class);
    options.setRunner(SparkRunner.class);
    pipeline = Pipeline.create(options);
  }

  @Test
  public void testGroupByKey() {
    Map<Integer, Integer> elems = new HashMap<>();
    elems.put(1, 1);
    elems.put(1, 3);
    elems.put(1, 5);
    elems.put(2, 2);
    elems.put(2, 4);
    elems.put(2, 6);
    PCollection<KV<Integer, Integer>> input = pipeline.apply(Create.of(elems));
    input.apply(GroupByKey.create());
    pipeline.run();
  }
}

@@ -923,23 +923,25 @@
 va.util.
-HashMap
+ArrayList
 ;%0Aimport
@@ -951,19 +951,20 @@
 va.util.
-Map
+List
 ;%0Aimport
@@ -1514,33 +1514,8 @@
 ss;%0A
-import org.junit.Ignore;%0A
 impo
@@ -2056,19 +2056,23 @@
 ) %7B%0A    
-Map
+List%3CKV
 %3CInteger
@@ -2081,16 +2081,17 @@
 Integer%3E
+%3E
  elems =
@@ -2099,15 +2099,17 @@
 new 
-HashMap
+ArrayList
 %3C%3E()
@@ -2124,17 +2124,24 @@
 ems.
-put
+add(KV.of
 (1, 1)
+)
 ;%0A  
@@ -2152,17 +2152,24 @@
 ems.
-put
+add(KV.of
 (1, 3)
+)
 ;%0A  
@@ -2180,17 +2180,24 @@
 ems.
-put
+add(KV.of
 (1, 5)
+)
 ;%0A  
@@ -2208,17 +2208,24 @@
 ems.
-put
+add(KV.of
 (2, 2)
+)
 ;%0A  
@@ -2236,17 +2236,24 @@
 ems.
-put
+add(KV.of
 (2, 4)
+)
 ;%0A  
@@ -2264,18 +2264,26 @@
 ems.
-put
+add(KV.of
 (2, 6)
-;
+);%0A
 %0A   

Fix for test elements container in GroupByKeyTest