Add/update license text part 3
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / test / java / org / onap / appc / adapter / iaas / provider / operation / impl / TestRebuildServer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.adapter.iaas.provider.operation.impl;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.inOrder;
30 import org.mockito.InOrder;
31 import com.att.cdp.zones.model.Server;
32 import com.att.cdp.zones.model.Server.Status;
33 import com.att.cdp.exceptions.ZoneException;
34 import org.onap.appc.adapter.iaas.provider.operation.impl.RebuildServer;
35 import org.onap.appc.exceptions.APPCException;
36 import org.onap.appc.configuration.Configuration;
37 import org.onap.appc.configuration.ConfigurationFactory;
38
39
40 public class TestRebuildServer {
41     protected static final Configuration configuration = ConfigurationFactory.getConfiguration();
42
43     @Test
44     public void rebuildServerRunning() throws ZoneException {
45         MockGenerator mg = new MockGenerator(Status.RUNNING);
46         Server server = mg.getServer();
47         RebuildServer rbs = new RebuildServer();
48         rbs.setProviderCache(mg.getProviderCacheMap());
49         rbs.setRebuildSleepTime(0);
50         try {
51             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
52         } catch (APPCException e) {
53             Assert.fail("Exception during RebuildServer.executeProviderOperation");
54         }
55         InOrder inOrderTest = inOrder(server);
56         inOrderTest.verify(server).stop();
57         inOrderTest.verify(server).rebuild("linuxBase");
58         inOrderTest.verify(server).start();
59
60     }
61
62     @Test
63     public void rebuildServerReady() throws ZoneException {
64         MockGenerator mg = new MockGenerator(Status.READY);
65         Server server = mg.getServer();
66         RebuildServer rbs = new RebuildServer();
67         rbs.setProviderCache(mg.getProviderCacheMap());
68         rbs.setRebuildSleepTime(0);
69         try {
70             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
71         } catch (APPCException e) {
72             Assert.fail("Exception during RebuildServer.executeProviderOperation");
73         }
74         InOrder inOrderTest = inOrder(server);
75         inOrderTest.verify(server).rebuild("linuxBase");
76         inOrderTest.verify(server).start();
77     }
78
79     @Test
80     public void rebuildServerPause() throws ZoneException {
81         MockGenerator mg = new MockGenerator(Status.PAUSED);
82         Server server = mg.getServer();
83         RebuildServer rbs = new RebuildServer();
84         rbs.setProviderCache(mg.getProviderCacheMap());
85         rbs.setRebuildSleepTime(0);
86         try {
87             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
88         } catch (APPCException e) {
89             Assert.fail("Exception during RebuildServer.executeProviderOperation");
90         }
91         InOrder inOrderTest = inOrder(server);
92         inOrderTest.verify(server).unpause();
93         inOrderTest.verify(server).stop();
94         inOrderTest.verify(server).rebuild("linuxBase");
95         inOrderTest.verify(server).start();
96     }
97
98     @Test
99     public void rebuildServerError() {
100         MockGenerator mg = new MockGenerator(Status.ERROR);
101         Server server = mg.getServer();
102         RebuildServer rbs = new RebuildServer();
103         rbs.setProviderCache(mg.getProviderCacheMap());
104         try {
105             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
106         } catch (APPCException e) {
107             Assert.fail("Exception during RebuildServer.executeProviderOperation");
108         }
109         verify(mg.getSvcLogicContext()).setAttribute(org.onap.appc.Constants.ATTRIBUTE_ERROR_CODE,
110                 "405");
111     }
112
113     @Test
114     public void rebuildServerSuspended() throws ZoneException {
115         MockGenerator mg = new MockGenerator(Status.SUSPENDED);
116         Server server = mg.getServer();
117         RebuildServer rbs = new RebuildServer();
118         rbs.setProviderCache(mg.getProviderCacheMap());
119         rbs.setRebuildSleepTime(0);
120         try {
121             rbs.executeProviderOperation(mg.getParams(), mg.getSvcLogicContext());
122         } catch (APPCException e) {
123             Assert.fail("Exception during RebuildServer.executeProviderOperation");
124         }
125         InOrder inOrderTest = inOrder(server);
126         inOrderTest.verify(server).resume();
127         inOrderTest.verify(server).stop();
128         inOrderTest.verify(server).rebuild("linuxBase");
129         inOrderTest.verify(server).start();
130     }
131
132 }