added test case to TestRestartServer.java
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / provider / operation / impl / TestRestartServer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Modifications Copyright (C) 2019 IBM
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * ============LICENSE_END=========================================================
24  */
25 package org.onap.appc.adapter.iaas.provider.operation.impl;
26
27 import static org.mockito.Mockito.inOrder;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.mockito.InOrder;
31 import org.onap.appc.exceptions.APPCException;
32 import org.onap.appc.exceptions.UnknownProviderException;
33
34 import com.att.cdp.exceptions.ZoneException;
35 import com.att.cdp.zones.model.Server;
36 import com.att.cdp.zones.model.Server.Status;
37
38 public class TestRestartServer {
39
40     @Test
41     public void restartServerSuspended() throws ZoneException {
42         MockGenerator mg = new MockGenerator(Status.SUSPENDED);
43         Server server = mg.getServer();
44         RestartServer rbs = new RestartServer();
45         rbs.setProviderCache(mg.getProviderCacheMap());
46         try {
47             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
48         } catch (APPCException e) {
49             Assert.fail("Exception during RestartServer.executeProviderOperation");
50         }
51         InOrder inOrderTest = inOrder(server);
52         inOrderTest.verify(server).resume();
53     }
54
55     @Test
56     public void restartServerRunning() throws ZoneException, UnknownProviderException {
57         MockGenerator mg = new MockGenerator(Status.RUNNING);
58         Server server = mg.getServer();
59         RestartServer rbs = new RestartServer();
60         rbs.setProviderCache(mg.getProviderCacheMap());
61         rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
62         
63         InOrder inOrderTest = inOrder(server);
64         inOrderTest.verify(server).stop();
65         inOrderTest.verify(server).start();
66     }
67     
68     @Test
69     public void pauseServerRunning() throws ZoneException, UnknownProviderException {
70         MockGenerator mg = new MockGenerator(Status.READY);
71         Server server = mg.getServer();
72         RestartServer rbs = new RestartServer();
73         rbs.setProviderCache(mg.getProviderCacheMap());
74         rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
75         
76         InOrder inOrderTest = inOrder(server);
77         inOrderTest.verify(server).start();
78     }
79     
80     @Test
81     public void pauseServerError() throws ZoneException, UnknownProviderException {
82         MockGenerator mg = new MockGenerator(Status.ERROR);
83         Server server = mg.getServer();
84         RestartServer rbs = new RestartServer();
85         rbs.setProviderCache(mg.getProviderCacheMap());
86         rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
87             
88     }
89 }