package org.onap.sdnc.northbound;
import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.sdnc.northbound.GenericResourceApiProvider.APP_NAME;
import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationInput;
import static org.onap.sdnc.northbound.util.MDSALUtil.serviceTopologyOperationOutput;
-import javax.xml.crypto.Data;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.information.ServiceInformation;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.Service;
import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatus;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
@RunWith(MockitoJUnitRunner.class)
public class ServiceTopologyOperationRPCTest extends GenericResourceApiProviderTest {
-
final String SVC_OPERATION = "service-topology-operation";
-
@Before
public void setUp() throws Exception {
super.setUp();
svcClient.setScvOperation(SVC_OPERATION);
}
-
/**
* Verify ServiceTopologyOperation RPC executes a DG then produces the expected {@link
* ServiceTopologyOperationOutput} and persisted the expected {@link Service} in the {@link DataBroker}
svcClient.mockExecute(svcResultProp);
// create the ServiceTopologyOperationInput from the template
- ServiceTopologyOperationInput serviceTopologyOperationInput = createSTOI();
+ ServiceTopologyOperationInput input = createSTOI();
//execute the mdsal exec
- ServiceTopologyOperationOutput actualServiceTopologyOperationOutput = exec(
+ ServiceTopologyOperationOutput output = exec(
genericResourceApiProvider::serviceTopologyOperation
- , serviceTopologyOperationInput
+ , input
, RpcResult::getResult
);
+ assertEquals("200", output.getResponseCode());
+ assertEquals("OK", output.getResponseMessage());
+ assertEquals("Y", output.getAckFinalIndicator());
+
//verify the returned ServiceTopologyOperationOutput
ServiceTopologyOperationOutput expectedServiceTopologyOperationOutput = createExpectedSTOO(svcResultProp,
- serviceTopologyOperationInput);
- assertEquals(expectedServiceTopologyOperationOutput, actualServiceTopologyOperationOutput);
+ input);
+ assertEquals(expectedServiceTopologyOperationOutput, output);
//verify the persisted Service
- Service actualService = db.read(serviceTopologyOperationInput.getServiceInformation().getServiceInstanceId(),
+ Service actualService = db.read(input.getServiceInformation().getServiceInstanceId(),
LogicalDatastoreType.CONFIGURATION);
Service expectedService = createExpectedService(
expectedServiceTopologyOperationOutput,
- serviceTopologyOperationInput,
+ input,
actualService);
assertEquals(expectedService, actualService);
}
@Test
- public void serviceTopologyOperation_should_fail_when_service_info_not_present() throws Exception {
+ public void should_fail_when_service_info_not_present() throws Exception {
// create the ServiceTopologyOperationInput from the template
ServiceTopologyOperationInput input = build(
serviceTopologyOperationInput()
.setSdncRequestHeader(build(sdncRequestHeader()
- .setSvcRequestId("svc-request-id: xyz")
- .setSvcAction(SvcAction.Assign)
- ))
- .setRequestInformation(build(requestInformation()
- .setRequestId("request-id: xyz")
- .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
- )));
+ .setSvcRequestId("svc-request-id: xyz")
+ .setSvcAction(SvcAction.Assign)
+ ))
+ .setRequestInformation(build(requestInformation()
+ .setRequestId("request-id: xyz")
+ .setRequestAction(RequestInformation.RequestAction.CreateServiceInstance)
+ )));
//execute the mdsal exec
ServiceTopologyOperationOutput output = exec(
@Test
- public void serviceTopologyOperation_should_fail_when_client_execution_failed() throws Exception {
+ public void should_fail_when_client_execution_failed() throws Exception {
svcClient.mockHasGraph(true);
svcClient.mockExecute(new RuntimeException("test exception"));
}
@Test
- public void serviceTopologyOperation_should_fail_when_client_has_no_graph() throws Exception {
+ public void should_fail_when_client_has_no_graph() throws Exception {
svcClient.mockHasGraph(false);
ServiceTopologyOperationInput input = createSTOI();
@Test
- public void serviceTopologyOperation_should_fail_when_failed_to_update_mdsal() throws Exception {
+ public void should_fail_when_failed_to_update_mdsal() throws Exception {
svcClient.mockHasGraph(true);
WriteTransaction mockWriteTransaction = mock(WriteTransaction.class);
assertEquals("Y", output.getAckFinalIndicator());
}
-
-
private ServiceTopologyOperationInput createSTOI() {
return build(