1+ /*
2+ * Copyright 2022 The Data Transfer Project Authors.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org .datatransferproject .types .common .models .blob ;
18+
19+ import com .fasterxml .jackson .databind .ObjectMapper ;
20+ import com .google .common .collect .ImmutableList ;
21+ import com .google .common .truth .Truth ;
22+ import org .datatransferproject .types .common .models .ContainerResource ;
23+ import org .junit .jupiter .api .Test ;
24+
25+ class BlobbyStorageContainerResourceTest {
26+
27+ @ Test
28+ public void verifySerializeDeserialize () throws Exception {
29+ ObjectMapper objectMapper = new ObjectMapper ();
30+ objectMapper .registerSubtypes (BlobbyStorageContainerResource .class );
31+
32+ DigitalDocumentWrapper documentWrapper = new DigitalDocumentWrapper (
33+ new DtpDigitalDocument ("doc-name" , "2020-02-02" , "UTF-8" ), "UTF-8" , "123456" );
34+ BlobbyStorageContainerResource containerResource = new BlobbyStorageContainerResource ("name" ,
35+ "id" , ImmutableList .of (documentWrapper ), ImmutableList .of ());
36+ String serialized = objectMapper .writeValueAsString (containerResource );
37+
38+ ContainerResource deserializedModel = objectMapper .readValue (serialized ,
39+ ContainerResource .class );
40+
41+ Truth .assertThat (deserializedModel ).isNotNull ();
42+ Truth .assertThat (deserializedModel ).isInstanceOf (BlobbyStorageContainerResource .class );
43+ BlobbyStorageContainerResource deserialized = (BlobbyStorageContainerResource ) deserializedModel ;
44+ Truth .assertThat (deserialized .getFiles ()).hasSize (1 );
45+ Truth .assertThat (deserialized .getFolders ()).isEmpty ();
46+ }
47+ }
0 commit comments