Task.java to Task.kt, and test it
[vid.git] / vid-app-common / src / test / java / org / onap / vid / mso / rest / TaskTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.mso.rest;
22
23 import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
24 import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.MatcherAssert.assertThat;
27
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.google.common.collect.ImmutableList;
30 import java.io.IOException;
31 import org.onap.vid.testUtils.TestUtils;
32 import org.testng.annotations.Test;
33
34 public class TaskTest {
35
36     private final ObjectMapper mapper = new ObjectMapper();
37     private final String TASK_JSON = ""
38         + "{ "
39         + "  \"taskId\": \"taskId\", "
40         + "  \"type\": \"type\", "
41         + "  \"nfRole\": \"nfRole\", "
42         + "  \"subscriptionServiceType\": \"subscriptionServiceType\", "
43         + "  \"originalRequestId\": \"originalRequestId\", "
44         + "  \"originalRequestorId\": \"originalRequestorId\", "
45         + "  \"buildingBlockName\": \"buildingBlockName\", "
46         + "  \"buildingBlockStep\": \"buildingBlockStep\", "
47         + "  \"errorSource\": \"errorSource\", "
48         + "  \"errorCode\": \"errorCode\", "
49         + "  \"errorMessage\": \"errorMessage\", "
50         + "  \"validResponses\": [ "
51         + "    \"a\", "
52         + "    \"b\", "
53         + "    \"c\" "
54         + "  ] "
55         + "} ";
56
57     private Task newTaskWithPopulatedFields() {
58         Task task = TestUtils.setStringsInStringProperties(new Task());
59         task.setValidResponses(ImmutableList.of("a", "b", "c"));
60         return task;
61     }
62
63     @Test
64     public void shouldHaveProperSettersAndGetters() {
65         assertThat(Task.class, hasValidGettersAndSetters());
66     }
67
68     @Test
69     public void serializeTask() throws IOException {
70         assertThat(
71             mapper.writeValueAsString(newTaskWithPopulatedFields()),
72             jsonEquals(TASK_JSON)
73         );
74     }
75
76     @Test
77     public void deserializeTask() throws IOException {
78         assertThat(
79             mapper.readValue(TASK_JSON, Task.class),
80             is(newTaskWithPopulatedFields())
81         );
82     }
83 }