0316e4b74c10bcdbd25aee113c7b67e14a106a43
[so.git] /
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 public class MsoCommonUtilsTest extends MsoCommonUtils {
52
53     public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
54
55     @Test
56     public final void testExecuteAndRecordOpenstackRequest() {
57         OpenStackRequest openstackRequest = Mockito.mock(OpenStackRequest.class);
58         Mockito.when(openstackRequest.endpoint()).thenReturn("localhost");
59         Mockito.when(openstackRequest.path()).thenReturn("/test");
60         //TODO:Must try a real connection
61         assertNull(super.executeAndRecordOpenstackRequest(openstackRequest));
62
63     }
64
65     @Test
66     public final void testKeystoneErrorToMsoException() {
67         OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
68
69         OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1);
70
71         MsoException me = super.keystoneErrorToMsoException(openStackConnectException, "ContextError");
72
73         assertTrue(me instanceof MsoIOException);
74         assertTrue("connect".equals(me.getMessage()));
75
76
77         MsoException me2 = super.keystoneErrorToMsoException(openStackResponseException, "ContextError");
78         assertTrue(me2 instanceof MsoOpenstackException);
79         assertTrue("ContextError".equals(me2.getContext()));
80         assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
81
82     }
83
84     @Test
85     public final void testHeatExceptionToMsoException() {
86         OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
87
88         OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1);
89
90         MsoException me = super.heatExceptionToMsoException(openStackConnectException, "ContextError");
91
92         assertTrue(me instanceof MsoIOException);
93         assertTrue("connect".equals(me.getMessage()));
94
95
96         MsoException me2 = super.heatExceptionToMsoException(openStackResponseException, "ContextError");
97         assertTrue(me2 instanceof MsoOpenstackException);
98         assertTrue("ContextError".equals(me2.getContext()));
99         assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
100     }
101
102     @Test
103     public final void testNeutronExceptionToMsoException() {
104         OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect");
105
106         OpenStackBaseException openStackResponseException = new OpenStackResponseException("response", 1);
107
108         MsoException me = super.neutronExceptionToMsoException(openStackConnectException, "ContextError");
109
110         assertTrue(me instanceof MsoIOException);
111         assertTrue("connect".equals(me.getMessage()));
112
113         MsoException me2 = super.neutronExceptionToMsoException(openStackResponseException, "ContextError");
114         assertTrue(me2 instanceof MsoOpenstackException);
115         assertTrue("ContextError".equals(me2.getContext()));
116         assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory()));
117     }
118
119     @Test
120     public final void testRuntimeExceptionToMsoException() {
121         RuntimeException re = new RuntimeException("runtime");
122         MsoException me = super.runtimeExceptionToMsoException(re, "ContextError");
123
124         assertTrue(me instanceof MsoAdapterException);
125         assertTrue("ContextError".equals(me.getContext()));
126         assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory()));
127     }
128 }