2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.mso.rest;
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;
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;
34 public class TaskTest {
36 private final ObjectMapper mapper = new ObjectMapper();
38 private String templateTaskJson(String insertion) {
41 + " \"taskId\": \"taskId\", "
42 + " \"type\": \"type\", "
43 + " \"nfRole\": \"nfRole\", "
44 + " \"subscriptionServiceType\": \"subscriptionServiceType\", "
45 + " \"originalRequestId\": \"originalRequestId\", "
46 + " \"originalRequestorId\": \"originalRequestorId\", "
47 + " \"buildingBlockName\": \"buildingBlockName\", "
48 + " \"buildingBlockStep\": \"buildingBlockStep\", "
49 + " \"errorSource\": \"errorSource\", "
50 + " \"errorCode\": \"errorCode\", "
51 + " \"errorMessage\": \"errorMessage\", "
53 + " \"validResponses\": [ "
61 private final String TASK_JSON = templateTaskJson(""
62 + " \"description\": \"description\", "
63 + " \"timeout\": \"timeout\", "
66 private final String TASK_JSON_WITHOUT_TIMEOUT = templateTaskJson("");
68 private Task newTaskWithPopulatedFields() {
69 Task task = TestUtils.setStringsInStringProperties(new Task());
70 task.setValidResponses(ImmutableList.of("a", "b", "c"));
75 public void shouldHaveProperSettersAndGetters() {
76 assertThat(Task.class, hasValidGettersAndSetters());
80 public void serializeTask() throws IOException {
82 mapper.writeValueAsString(newTaskWithPopulatedFields()),
88 public void deserializeTask() throws IOException {
90 mapper.readValue(TASK_JSON, Task.class),
91 is(newTaskWithPopulatedFields())
96 public void deserializeTaskWithoutTimeout() throws IOException {
98 SO may return no timeout, and therefore no description as well
100 final Task taskWithoutTimeout = newTaskWithPopulatedFields();
101 taskWithoutTimeout.setDescription(null);
102 taskWithoutTimeout.setTimeout(null);
105 mapper.readValue(TASK_JSON_WITHOUT_TIMEOUT, Task.class),
106 is(taskWithoutTimeout)