/*
 * Copyright © 2015 Cask Data, Inc.
 *
 * 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 co.cask.cdap.internal.app;

import co.cask.cdap.api.schedule.DataSchedule;
import co.cask.cdap.api.schedule.SchedulableProgramType;
import co.cask.cdap.api.schedule.ScheduleSpecification;
import co.cask.cdap.api.schedule.TimeSchedule;
import co.cask.cdap.api.workflow.ScheduleProgramInfo;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.junit.Assert;
import org.junit.Test;

/**
 *
 */
public class ScheduleSpecificationCodecTest {
  private static final Gson GSON = new GsonBuilder()
    .registerTypeAdapter(ScheduleSpecification.class, new ScheduleSpecificationCodec())
    .create();

  @Test
  public void testTimeSchedule() throws Exception {
    TimeSchedule timeSchedule = new TimeSchedule("foo", "bar", "cronEntry");
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "testWorkflow");
    ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d");
    ScheduleSpecification specification = new ScheduleSpecification(timeSchedule, programInfo, properties);

    String jsonStr = GSON.toJson(specification);
    ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);

    Assert.assertEquals(specification, deserialized);
  }

  @Test
  public void testDataSchedule() throws Exception {
    DataSchedule dataSchedule = new DataSchedule("foo", "bar", DataSchedule.SourceType.STREAM,
                                                 "namespace", "stream", 10);
    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, "testWorkflow");
    ImmutableMap<String, String> properties = ImmutableMap.of("a", "b", "c", "d");
    ScheduleSpecification specification = new ScheduleSpecification(dataSchedule, programInfo, properties);

    String jsonStr = GSON.toJson(specification);
    ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);

    Assert.assertEquals(specification, deserialized);
  }
}

@@ -2579,32 +2579,1003 @@
 cation.class);%0A%0A
+    Assert.assertEquals(specification, deserialized);%0A  %7D%0A%0A  @Test%0A  public void testBackwardsCompatibility() throws Exception %7B%0A    // Before 2.8, the ScheduleSpecificationCodec used to have the same behavior as what Gson would do by%0A    // default, and only TimeSchedules existed. We make sure that ScheduleSpecification persisted before%0A    // 2.8 can still be deserialized using the new codec.%0A    TimeSchedule timeSchedule = new TimeSchedule(%22foo%22, %22bar%22, %22cronEntry%22);%0A    ScheduleProgramInfo programInfo = new ScheduleProgramInfo(SchedulableProgramType.WORKFLOW, %22testWorkflow%22);%0A    ImmutableMap%3CString, String%3E properties = ImmutableMap.of(%22a%22, %22b%22, %22c%22, %22d%22);%0A    ScheduleSpecification specification = new ScheduleSpecification(timeSchedule, programInfo, properties);%0A%0A    // Use default Gson to serialize%0A    String jsonStr = new Gson().toJson(specification);%0A    %0A    ScheduleSpecification deserialized = GSON.fromJson(jsonStr, ScheduleSpecification.class);%0A%0A
     Assert.asser

Test backwards compatibility