f23df3312f6e4106c9de4f6bae0691dbc7da6074
[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 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
21
22 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
23 import static org.junit.Assert.assertThat;
24 import static org.mockito.Mockito.doReturn;
25 import static org.mockito.Mockito.times;
26 import static org.mockito.Mockito.verify;
27
28 import java.util.Map;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
33 import org.onap.so.bpmn.BaseTaskTest;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
37 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
38 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.springframework.beans.factory.annotation.Autowired;
41
42 public class CreateNetworkTest extends BaseTaskTest{
43         @Autowired
44         private CreateNetwork createNetwork;
45         
46         private L3Network network;
47         private ServiceInstance serviceInstance;
48         private CloudRegion cloudRegion;
49         private OrchestrationContext orchestrationContext;
50         private Map<String, String> userInput;
51         private RequestContext requestContext;
52         private String cloudRegionPo = "testCloudRegionPo";
53         private Customer customer;
54         
55         @Before
56         public void before() {
57                 customer = setCustomer();
58                 serviceInstance = setServiceInstance();
59                 network = setL3Network();
60                 cloudRegion = setCloudRegion();
61                 orchestrationContext = setOrchestrationContext();
62                 orchestrationContext.setIsRollbackEnabled(true);
63                 requestContext = setRequestContext();
64                 userInput = setUserInput();
65
66                 customer.getServiceSubscription().getServiceInstances().add(serviceInstance);
67
68         }
69         
70         @Test
71         public void buildCreateNetworkRequestTest() throws Exception {
72                 execution.setVariable("cloudRegionPo", cloudRegionPo);
73                 
74                 CreateNetworkRequest expectedCreateNetworkRequest = new CreateNetworkRequest();
75                 
76                 doReturn(expectedCreateNetworkRequest).when(networkAdapterObjectMapper).createNetworkRequestMapper(requestContext, cloudRegion,  orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer);
77                 
78                 createNetwork.buildCreateNetworkRequest(execution);
79                 
80                 verify(networkAdapterObjectMapper, times(1)).createNetworkRequestMapper(requestContext, cloudRegion,  orchestrationContext, serviceInstance, network, userInput, cloudRegionPo, customer);
81                 
82                 assertThat(expectedCreateNetworkRequest, sameBeanAs(execution.getVariable("createNetworkRequest")));
83         }
84 }