Removing jackson to mitigate cve-2017-4995
[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 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;
28
29 import static com.google.common.collect.Iterables.filter;
30 import static junit.framework.TestCase.assertEquals;
31
32 public class TestRealConfig {
33
34     /**
35      * test that the converter can transform the inherited classes
36      */
37     @Test
38     public void test() throws Exception {
39         HttpMessageConverters converters = new RealConfig().customConverters();
40         //verify
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);
47
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());
60
61     }
62
63 }