Change the header to SO
[so.git] / adapters / mso-adapter-utils / src / test / java / org / openecomp / mso / adapter_utils / tests / MsoCommonUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.adapter_utils.tests;
22
23
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31
32 import org.openecomp.mso.logger.MsoAlarmLogger;
33 import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
34 import org.openecomp.mso.openstack.exceptions.MsoException;
35 import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
36 import org.openecomp.mso.openstack.exceptions.MsoIOException;
37 import org.openecomp.mso.openstack.exceptions.MsoOpenstackException;
38 import org.openecomp.mso.openstack.utils.MsoCommonUtils;
39 import org.openecomp.mso.properties.MsoJavaProperties;
40 import org.openecomp.mso.properties.MsoPropertiesException;
41 import org.openecomp.mso.properties.MsoPropertiesFactory;
42 import com.woorea.openstack.base.client.OpenStackBaseException;
43 import com.woorea.openstack.base.client.OpenStackConnectException;
44 import com.woorea.openstack.base.client.OpenStackRequest;
45 import com.woorea.openstack.base.client.OpenStackResponseException;
46
47
48 /**
49  * This class implements test methods of the MsoCommonUtils
50  *
51  *
52  */
53 public class MsoCommonUtilsTest extends MsoCommonUtils {
54
55         public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
56         
57         @Test
58     public final void testExecuteAndRecordOpenstackRequest () {
59                 OpenStackRequest openstackRequest = Mockito.mock(OpenStackRequest.class);
60                 Mockito.when(openstackRequest.endpoint()).thenReturn("localhost");
61                 Mockito.when(openstackRequest.path()).thenReturn("/test");
62                 //TODO:Must try a real connection
63                 assertNull(super.executeAndRecordOpenstackRequest (openstackRequest));
64
65         }
66
67         @Test
68     public final void testKeystoneErrorToMsoException () {
69                 OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
70
71                 OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
72
73                 MsoException me = super.keystoneErrorToMsoException (openStackConnectException,"ContextError");
74
75                 assertTrue(me instanceof MsoIOException);
76                 assertTrue("connect".equals(me.getMessage()));
77
78
79                 MsoException me2 = super.keystoneErrorToMsoException (openStackResponseException,"ContextError");
80                 assertTrue(me2 instanceof MsoOpenstackException);
81                 assertTrue("ContextError".equals(me2.getContext()));
82                 assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
83
84         }
85
86         @Test
87         public final void testHeatExceptionToMsoException () {
88                 OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
89
90                 OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
91
92                 MsoException me = super.heatExceptionToMsoException (openStackConnectException,"ContextError");
93
94                 assertTrue(me instanceof MsoIOException);
95                 assertTrue("connect".equals(me.getMessage()));
96
97
98                 MsoException me2 = super.heatExceptionToMsoException (openStackResponseException,"ContextError");
99                 assertTrue(me2 instanceof MsoOpenstackException);
100                 assertTrue("ContextError".equals(me2.getContext()));
101                 assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
102         }
103
104         @Test
105         public final void testNeutronExceptionToMsoException () {
106                 OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
107
108                 OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1);
109
110                 MsoException me = super.neutronExceptionToMsoException (openStackConnectException,"ContextError");
111
112                 assertTrue(me instanceof MsoIOException);
113                 assertTrue("connect".equals(me.getMessage()));
114
115                 MsoException me2 = super.neutronExceptionToMsoException (openStackResponseException,"ContextError");
116                 assertTrue(me2 instanceof MsoOpenstackException);
117                 assertTrue("ContextError".equals(me2.getContext()));
118                 assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
119         }
120
121         @Test
122         public final void testRuntimeExceptionToMsoException () {
123             RuntimeException re = new RuntimeException ("runtime");
124             MsoException me = super.runtimeExceptionToMsoException (re, "ContextError");
125
126             assertTrue (me instanceof MsoAdapterException);
127             assertTrue("ContextError".equals(me.getContext()));
128         assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory()));
129         }
130 }