/*
 * Copyright 2022 The Data Transfer Project Authors.
 *
 * 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
 *
 * https://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.datatransferproject.types.common.models.blob;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth;
import org.datatransferproject.types.common.models.ContainerResource;
import org.junit.jupiter.api.Test;

class BlobbyStorageContainerResourceTest {

  @Test
  public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerSubtypes(BlobbyStorageContainerResource.class);

    DigitalDocumentWrapper documentWrapper = new DigitalDocumentWrapper(
        new DtpDigitalDocument("doc-name", "2020-02-02", "UTF-8"), "UTF-8", "123456");
    BlobbyStorageContainerResource containerResource = new BlobbyStorageContainerResource("name",
        "id", ImmutableList.of(documentWrapper), ImmutableList.of());
    String serialized = objectMapper.writeValueAsString(containerResource);

    ContainerResource deserializedModel = objectMapper.readValue(serialized,
        ContainerResource.class);

    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(BlobbyStorageContainerResource.class);
    BlobbyStorageContainerResource deserialized = (BlobbyStorageContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getFiles()).hasSize(1);
    Truth.assertThat(deserialized.getFolders()).isEmpty();
  }
}