6bcce07f5aa8cce80916edefef92dfb4aea63068
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / spring / TestRealConfig.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
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  *     http://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.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
18
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;
29
30 import java.io.IOException;
31 import java.io.InputStream;
32
33 import static junit.framework.TestCase.assertEquals;
34
35 public class TestRealConfig {
36
37     /**
38      * test that the converter can transform the inherited classes
39      */
40     @Test
41     public void test() throws Exception {
42         HttpMessageConverters converters = new RealConfig().customConverters();
43         //verify
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);
49
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());
60     }
61
62 }