2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
19 import com.nokia.cbam.lcm.v32.model.*;
20 import org.junit.Test;
21 import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
22 import org.springframework.http.HttpInputMessage;
23 import org.springframework.http.MediaType;
24 import org.springframework.http.converter.json.GsonHttpMessageConverter;
25 import org.springframework.mock.http.MockHttpInputMessage;
26 import org.springframework.mock.http.MockHttpOutputMessage;
27 import org.threeten.bp.OffsetDateTime;
29 import static com.google.common.collect.Iterables.filter;
30 import static junit.framework.TestCase.assertEquals;
32 public class TestRealConfig {
35 * test that the converter can transform the inherited classes
38 public void test() throws Exception {
39 HttpMessageConverters converters = new RealConfig().customConverters();
41 GsonHttpMessageConverter httpMessageConverter1 = filter(converters.getConverters(), GsonHttpMessageConverter.class).iterator().next();
42 httpMessageConverter1.canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
43 httpMessageConverter1.canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
44 httpMessageConverter1.canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
45 httpMessageConverter1.canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
46 httpMessageConverter1.canRead(String.class, MediaType.APPLICATION_JSON);
48 MockHttpOutputMessage out = new MockHttpOutputMessage();
49 VnfLifecycleChangeNotification not = new VnfLifecycleChangeNotification();
50 not.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
51 not.setVnfInstanceId("vnfId");
52 OffsetDateTime now = OffsetDateTime.now();
53 not.setTimestamp(now);
54 httpMessageConverter1.write(not, MediaType.APPLICATION_JSON, out);
55 String write = out.getBodyAsString();
56 HttpInputMessage x = new MockHttpInputMessage(write.getBytes());
57 VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter1.read(VnfLifecycleChangeNotification.class, x);
58 assertEquals("vnfId", deserialized.getVnfInstanceId());
59 assertEquals(now, deserialized.getTimestamp());