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 junit.framework.TestCase;
21 import org.junit.Test;
22 import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
23 import org.springframework.http.HttpHeaders;
24 import org.springframework.http.HttpInputMessage;
25 import org.springframework.http.MediaType;
26 import org.springframework.http.converter.HttpMessageConverter;
27 import org.springframework.mock.http.MockHttpInputMessage;
28 import org.springframework.mock.http.MockHttpOutputMessage;
30 import java.io.IOException;
31 import java.io.InputStream;
33 import static junit.framework.TestCase.assertEquals;
35 public class TestRealConfig {
38 * test that the converter can transform the inherited classes
41 public void test() throws Exception {
42 HttpMessageConverters converters = new RealConfig().customConverters();
44 converters.getConverters().get(0).canRead(VnfIdentifierCreationNotification.class, MediaType.APPLICATION_JSON);
45 converters.getConverters().get(0).canRead(VnfIdentifierDeletionNotification.class, MediaType.APPLICATION_JSON);
46 converters.getConverters().get(0).canRead(VnfInfoAttributeValueChangeNotification.class, MediaType.APPLICATION_JSON);
47 converters.getConverters().get(0).canRead(VnfLifecycleChangeNotification.class, MediaType.APPLICATION_JSON);
48 converters.getConverters().get(0).canRead(String.class, MediaType.APPLICATION_JSON);
50 HttpMessageConverter<VnfLifecycleChangeNotification> httpMessageConverter = (HttpMessageConverter<VnfLifecycleChangeNotification>) converters.getConverters().get(0);
51 MockHttpOutputMessage out = new MockHttpOutputMessage();
52 VnfLifecycleChangeNotification not = new VnfLifecycleChangeNotification();
53 not.setNotificationType(VnfNotificationType.VNFLIFECYCLECHANGENOTIFICATION);
54 not.setVnfInstanceId("vnfId");
55 httpMessageConverter.write(not, MediaType.APPLICATION_JSON, out);
56 String write = out.getBodyAsString();
57 HttpInputMessage x = new MockHttpInputMessage(write.getBytes());
58 VnfLifecycleChangeNotification deserialized = (VnfLifecycleChangeNotification) httpMessageConverter.read(VnfLifecycleChangeNotification.class, x);
59 assertEquals("vnfId", deserialized.getVnfInstanceId());