Change code in appc dispatcher for new LCMs in R6
[appc.git] / appc-dispatcher / appc-license-manager / appc-license-manager-core / src / test / java / org / onap / appc / licmgr / impl / XmlToLicenseModelConverterTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia
6  * =============================================================================
7  * Modifications Copyright (C) 2019 AT&T Intellectual Property
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.licmgr.impl;
25
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27 import static org.mockito.BDDMockito.given;
28 import static org.mockito.BDDMockito.then;
29 import static org.mockito.Matchers.any;
30 import static org.mockito.Matchers.anyString;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34 import javax.xml.stream.XMLInputFactory;
35 import javax.xml.stream.XMLStreamException;
36 import javax.xml.stream.XMLStreamReader;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.runners.MockitoJUnitRunner;
41
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class XmlToLicenseModelConverterTest {
45
46     @Mock
47     private XMLStreamReader xmlStreamReader;
48
49     @Mock
50     private XMLInputFactory xmlInputFactory;
51
52     @Test
53     public void apply_shouldCloseXMLStreamReader_whenNoExceptionIsThrown()
54         throws XMLStreamException, IOException {
55
56         // GIVEN
57         XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
58         given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
59
60         // WHEN
61         converter.convert((a, b) -> {
62                 }, anyString(), null);
63
64         // THEN
65         then(xmlStreamReader).should().close();
66     }
67
68     @Test
69     public void apply_shouldCloseXMLStreamReader_whenExceptionIsThrown()
70         throws XMLStreamException {
71         // GIVEN
72         XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
73         given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
74
75         // WHEN THEN
76         assertThatExceptionOfType(XMLStreamException.class)
77                 .isThrownBy(() -> converter.convert((a, b) -> {
78                     throw new XMLStreamException();
79                 }, anyString(), null));
80         then(xmlStreamReader).should().close();
81     }
82 }