From cebbe0144bce9b2e9ee1b390dc02389e9ce015d1 Mon Sep 17 00:00:00 2001 From: ayalaben Date: Thu, 30 Aug 2018 13:44:51 +0300 Subject: Associate Artifact Test Change-Id: Ia45b1b1123a76b5642dda64a7bd75a31065de027 Issue-ID: SDC-1535 Signed-off-by: ayalaben --- .../workflow/api/ArtifactAssociationService.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'workflow-designer-be/src/main') diff --git a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java index be327498..a837d700 100644 --- a/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java +++ b/workflow-designer-be/src/main/java/org/onap/sdc/workflow/api/ArtifactAssociationService.java @@ -52,7 +52,8 @@ public class ArtifactAssociationService { private static final String USER_ID_HEADER = "USER_ID"; private static final String MD5_HEADER = "Content-MD5"; private static final String X_ECOMP_INSTANCE_ID_HEADER = "X-ECOMP-InstanceID"; - private static final String INIT_ERROR_MSG = "Failed while attaching workflow artifact to Operation in SDC. Parameters were not initialized: %s"; + private static final String INIT_ERROR_MSG = + "Failed while attaching workflow artifact to Operation in SDC. Parameters were not initialized: %s"; private static final Logger LOGGER = LoggerFactory.getLogger(ArtifactAssociationService.class); @Value("${sdc.be.endpoint}") private String sdcBeEndpoint; @@ -63,19 +64,26 @@ public class ArtifactAssociationService { @Value("${sdc.be.external.password}") private String sdcPassword; - private final RestTemplate restClient; + private RestTemplate restClient; @Autowired public ArtifactAssociationService(RestTemplateBuilder builder) { this.restClient = builder.build(); } + void setRestClient(RestTemplate restClient) { + this.restClient = restClient; + } + + void setSdcBeEndpoint(String value) { + this.sdcBeEndpoint = value; + } ResponseEntity execute(String userId, ArtifactDeliveriesRequestDto deliveriesRequestDto, ArtifactEntity artifactEntity) { Optional initializationState = parametersInitializationState(); - if(initializationState.isPresent()){ + if(initializationState.isPresent()) { LOGGER.error(String.format(INIT_ERROR_MSG,initializationState.get())); return ResponseEntity.status(HttpStatus.EXPECTATION_FAILED).body(String.format(INIT_ERROR_MSG,initializationState.get())); } @@ -90,29 +98,30 @@ public class ArtifactAssociationService { HttpEntity request = new HttpEntity<>(formattedArtifact, createHeaders(userId,formattedArtifact)); - return restClient.exchange(sdcBeProtocol +"://" + sdcBeEndpoint + "/" + deliveriesRequestDto.getEndpoint(), + return restClient.exchange(sdcBeProtocol + "://" + sdcBeEndpoint + "/" + deliveriesRequestDto.getEndpoint(), HttpMethod.valueOf(deliveriesRequestDto.getMethod()), request, String.class); } - private Optional parametersInitializationState() { - ArrayList result=new ArrayList(); - if (sdcBeEndpoint.equals("")) { + Optional parametersInitializationState() { + ArrayList result = new ArrayList<>(); + if (sdcBeEndpoint == null || sdcBeEndpoint.equals("")) { result.add("SDC_ENDPOINT"); } - if (sdcBeProtocol.equals("")) { + if (sdcBeProtocol == null || sdcBeProtocol.equals("")) { result.add("SDC_PROTOCOL"); } - if (sdcUser.equals("")) { + if (sdcUser == null || sdcUser.equals("")) { result.add("SDC_USER"); } - if (sdcPassword.equals("")) { + if (sdcPassword == null || sdcPassword.equals("")) { result.add("SDC_PASSWORD"); } - if(result.isEmpty()) { + if (result.isEmpty()) { return Optional.empty(); + } else { + return Optional.of(result.toString()); } - else return Optional.of(result.toString()); } -- cgit 1.2.3-korg