package org.dataportabilityproject.spi.cloud.types;

import static com.google.common.truth.Truth.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import org.dataportabilityproject.spi.cloud.types.PortabilityJob.State;
import org.dataportabilityproject.test.types.ObjectMapperFactory;
import org.junit.Test;

/**
 * Tests serialization and deserialization of a {@link PortabilityJob}.
 */
public class PortabilityJobTest {

    @Test
    public void verifySerializeDeserialize() throws Exception {
        ObjectMapper objectMapper = ObjectMapperFactory.createObjectMapper();
        LocalDateTime date = LocalDateTime.of(2018, 2, 20, 12, 0);

        JobAuthorization jobAuthorization = JobAuthorization.builder()
            .setState(JobAuthorization.State.INITIAL).setEncryptedSessionKey("foo").build();

        PortabilityJob job = PortabilityJob.builder()
            .setState(State.NEW)
            .setExportService("fooService")
            .setImportService("barService")
            .setTransferDataType("photos")
            .setCreatedTimestamp(date)
            .setLastUpdateTimestamp(date.plusMinutes(2))
            .setJobAuthorization(jobAuthorization).build();

        String serializedJobAuthorization = objectMapper.writeValueAsString(jobAuthorization);
        JobAuthorization deserializedJobAuthorization =
            objectMapper.readValue(serializedJobAuthorization, JobAuthorization.class);
        assertThat(deserializedJobAuthorization).isEqualTo(jobAuthorization);

        String serializedJob = objectMapper.writeValueAsString(job);
        PortabilityJob deserializedJob =
            objectMapper.readValue(serializedJob, PortabilityJob.class);
        assertThat(deserializedJob).isEqualTo(job);
    }
}
@@ -1,8 +1,627 @@
+/*%0A * Copyright 2018 The Data-Portability Project Authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * https://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A
 package 
@@ -2403,8 +2403,9 @@
 %0A    %7D%0A%7D
+%0A

Add license header and EOF