diff options
author | romaingimbert <romain.gimbert@orange.com> | 2019-02-01 15:05:15 +0100 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2019-02-01 15:05:15 +0100 |
commit | 7093b767e7d9a76c4f91ec98e95a9b1ea8a5e14d (patch) | |
tree | bf5d63b7d170504e490ca415345543d855dcbf62 | |
parent | 2afa1a1b9b020c0ada15581658268e98b7219a64 (diff) |
Update to Spring Boot 2
-update pom dependencies
-fix code
-fix test
Change-Id: I23c3c702c598ce46e5b861a2fbdfd06f2d439c51
Issue-ID: EXTAPI-192
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
12 files changed, 147 insertions, 120 deletions
diff --git a/docs/configuration/configuration.rst b/docs/configuration/configuration.rst index 22bd5fd..d0c2bd4 100644 --- a/docs/configuration/configuration.rst +++ b/docs/configuration/configuration.rst @@ -23,7 +23,7 @@ Default values :: # SERVER - server.contextPath=/nbi/api/v3 + server.servlet.context-path=/nbi/api/v3 server.port = 8080 # LOGGING @@ -21,7 +21,7 @@ <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> - <version>1.5.12.RELEASE</version> + <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> @@ -117,7 +117,7 @@ <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> - <version>2.8.11.2</version> + <version>2.9.4</version> </dependency> <dependency> @@ -146,7 +146,13 @@ <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId> - <version>1.13.14.RELEASE</version> + <version>2.1.4.RELEASE</version> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-tomcat</artifactId> + <scope>provided</scope> </dependency> <dependency> diff --git a/src/main/java/org/onap/nbi/ServiceRegisterRunner.java b/src/main/java/org/onap/nbi/ServiceRegisterRunner.java index 90ea9ac..05072c1 100644 --- a/src/main/java/org/onap/nbi/ServiceRegisterRunner.java +++ b/src/main/java/org/onap/nbi/ServiceRegisterRunner.java @@ -63,7 +63,7 @@ public class ServiceRegisterRunner implements CommandLineRunner { @Value("${nbi.version}") private String SERVICE_VERSION; - @Value("${server.contextPath}") + @Value("${server.servlet.context-path}") private String SERVICE_URL; @Value("${msb.service.custom_path}") diff --git a/src/main/java/org/onap/nbi/apis/hub/HubResource.java b/src/main/java/org/onap/nbi/apis/hub/HubResource.java index 6383265..0f94802 100755 --- a/src/main/java/org/onap/nbi/apis/hub/HubResource.java +++ b/src/main/java/org/onap/nbi/apis/hub/HubResource.java @@ -14,6 +14,7 @@ package org.onap.nbi.apis.hub; import java.net.URI; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import org.onap.nbi.apis.hub.model.Subscriber; import org.onap.nbi.apis.hub.model.Subscription; @@ -72,11 +73,12 @@ public class HubResource extends ResourceManagement { @GetMapping(value = "/{subscriptionId}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Subscription> getSubscription(@PathVariable String subscriptionId) { - Subscriber subscriber = subscriptionService.findSubscriptionById(subscriptionId); - if (subscriber == null) { + + Optional<Subscriber> optionalSubscriber = subscriptionService.findSubscriptionById(subscriptionId); + if (!optionalSubscriber.isPresent()) { return ResponseEntity.notFound().build(); } - return ResponseEntity.ok(Subscription.createFromSubscriber(subscriber)); + return ResponseEntity.ok(Subscription.createFromSubscriber(optionalSubscriber.get())); } @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) diff --git a/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java b/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java index 550c185..3507d63 100644 --- a/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java +++ b/src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java @@ -15,6 +15,7 @@ package org.onap.nbi.apis.hub.service; import com.google.common.collect.Lists; import java.text.MessageFormat; import java.util.List; +import java.util.Optional; import org.onap.nbi.apis.hub.model.Subscriber; import org.onap.nbi.apis.hub.model.Subscription; import org.onap.nbi.apis.hub.repository.SubscriberRepository; @@ -30,8 +31,8 @@ public class SubscriptionService { @Autowired SubscriberRepository subscriberRepository; - public Subscriber findSubscriptionById(String subscriptionId) { - return subscriberRepository.findOne(subscriptionId); + public Optional<Subscriber> findSubscriptionById(String subscriptionId) { + return subscriberRepository.findById(subscriptionId); } public Subscriber createSubscription(Subscription subscription) { @@ -51,12 +52,12 @@ public class SubscriptionService { private boolean isSubscriberAlreadyExisting(Subscriber subscriber) { Example<Subscriber> subscriberExample = Example.of(subscriber); - Subscriber subscriberAlreadyExisting = subscriberRepository.findOne(subscriberExample); - return subscriberAlreadyExisting != null; + Optional<Subscriber> subscriberAlreadyExisting = subscriberRepository.findOne(subscriberExample); + return subscriberAlreadyExisting.isPresent(); } public void deleteSubscription(String subscriptionId) { - subscriberRepository.delete(subscriptionId); + subscriberRepository.deleteById(subscriptionId); } public void deleteAll() { diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java index 2cd1c9a..e34a3e7 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java @@ -1,20 +1,20 @@ /** - * Copyright (c) 2018 Orange + * Copyright (c) 2018 Orange * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. */ package org.onap.nbi.apis.serviceorder; +import java.util.List; +import java.util.Optional; +import javax.validation.Valid; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; @@ -35,10 +35,15 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.util.MultiValueMap; import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.*; - -import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/serviceOrder") @@ -66,19 +71,17 @@ public class ServiceOrderResource extends ResourceManagement { MultiCriteriaRequestBuilder multiCriteriaRequestBuilder; - - @GetMapping(value = "/{serviceOrderId}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> getServiceOrder(@PathVariable String serviceOrderId, - @RequestParam MultiValueMap<String, String> params) { + @RequestParam MultiValueMap<String, String> params) { - ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderId); - if (serviceOrder == null) { + Optional<ServiceOrder> optionalServiceOrder = serviceOrderService.findServiceOrderById(serviceOrderId); + if (!optionalServiceOrder.isPresent()) { return ResponseEntity.notFound().build(); } JsonRepresentation filter = new JsonRepresentation(params); - return this.getResponse(serviceOrder, filter); + return this.getResponse(optionalServiceOrder.get(), filter); } @GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE) @@ -107,26 +110,29 @@ public class ServiceOrderResource extends ResourceManagement { @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> createServiceOrder(@Valid @RequestBody ServiceOrder serviceOrder, Errors errors, - @RequestParam MultiValueMap<String, String> params) { - + @RequestParam MultiValueMap<String, String> params) { if (errors != null && errors.hasErrors()) { throw new ValidationException(errors.getAllErrors()); } - ServiceOrder serviceOrderSaved =serviceOrderService.createServiceOrder(serviceOrder); + ServiceOrder serviceOrderSaved = serviceOrderService.createServiceOrder(serviceOrder); JsonRepresentation filter = new JsonRepresentation(params); return this.createResponse(serviceOrderSaved, filter); } - @PutMapping(value = "/test/{serviceOrderId}",consumes = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity<Object> checkServiceOrderRessource(@PathVariable String serviceOrderId,@RequestParam MultiValueMap<String, String> params){ - ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderId); - serviceOrder = checkServiceOrder(serviceOrder); + @PutMapping(value = "/test/{serviceOrderId}", consumes = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<Object> checkServiceOrderRessource(@PathVariable String serviceOrderId, + @RequestParam MultiValueMap<String, String> params) { + Optional<ServiceOrder> optionalServiceOrder = serviceOrderService.findServiceOrderById(serviceOrderId); + if (!optionalServiceOrder.isPresent()) { + return ResponseEntity.notFound().build(); + } + ServiceOrder serviceOrder = checkServiceOrder(optionalServiceOrder.get()); JsonRepresentation filter = new JsonRepresentation(params); - return this.createResponse(serviceOrder,filter); + return this.createResponse(serviceOrder, filter); } @@ -137,10 +143,10 @@ public class ServiceOrderResource extends ResourceManagement { } else if (serviceOrderInfo.isAllItemsCompleted()) { serviceOrderService.updateOrderState(serviceOrder, StateType.COMPLETED); } else { - createAAICustomer.createAAICustomer(serviceOrder,serviceOrderInfo); - if(StateType.ACKNOWLEDGED==serviceOrder.getState()) { + createAAICustomer.createAAICustomer(serviceOrder, serviceOrderInfo); + if (StateType.ACKNOWLEDGED == serviceOrder.getState()) { createAAIServiceType.createAAIServiceType(serviceOrder, serviceOrderInfo); - if(StateType.ACKNOWLEDGED==serviceOrder.getState()) { + if (StateType.ACKNOWLEDGED == serviceOrder.getState()) { serviceOrchestratorManager.registerServiceOrder(serviceOrder, serviceOrderInfo); } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java index b851be8..2b0f22c 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java @@ -1,20 +1,20 @@ /** - * Copyright (c) 2018 Orange + * Copyright (c) 2018 Orange * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. */ package org.onap.nbi.apis.serviceorder.service; +import java.util.Date; +import java.util.List; +import java.util.Optional; import org.onap.nbi.apis.serviceorder.model.OrderMessage; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; @@ -24,9 +24,6 @@ import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Date; -import java.util.List; - @Service public class ServiceOrderService { @@ -35,28 +32,28 @@ public class ServiceOrderService { private static final String SERVICE_ID = "service.id"; - public ServiceOrder findServiceOrderById(String serviceOrderId){ - return serviceOrderRepository.findOne(serviceOrderId); + public Optional<ServiceOrder> findServiceOrderById(String serviceOrderId) { + return serviceOrderRepository.findById(serviceOrderId); } - public List<ServiceOrder> findServiceOrdersByState(StateType state){ + public List<ServiceOrder> findServiceOrdersByState(StateType state) { return serviceOrderRepository.findByState(state); } - public ServiceOrder updateOrderState(ServiceOrder serviceOrder,StateType state){ - if(StateType.COMPLETED.equals(state) || StateType.REJECTED.equals(state)) { + public ServiceOrder updateOrderState(ServiceOrder serviceOrder, StateType state) { + if (StateType.COMPLETED.equals(state) || StateType.REJECTED.equals(state)) { serviceOrder.setCompletionDateTime(new Date()); } serviceOrder.setState(state); return serviceOrderRepository.save(serviceOrder); } - public void updateOrderItemState(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, StateType state){ + public void updateOrderItemState(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, StateType state) { serviceOrderItem.setState(state); serviceOrderRepository.save(serviceOrder); } - public ServiceOrder createServiceOrder(ServiceOrder serviceOrder){ + public ServiceOrder createServiceOrder(ServiceOrder serviceOrder) { serviceOrder.setState(StateType.ACKNOWLEDGED); serviceOrder.setOrderDate(new Date()); serviceOrder.setId(null); @@ -68,11 +65,11 @@ public class ServiceOrderService { return serviceOrderRepository.save(serviceOrder); } - public void deleteServiceOrder(String serviceOrderId){ - serviceOrderRepository.delete(serviceOrderId); + public void deleteServiceOrder(String serviceOrderId) { + serviceOrderRepository.deleteById(serviceOrderId); } - public long countServiceOrder(){ + public long countServiceOrder() { return serviceOrderRepository.count(); } @@ -107,7 +104,7 @@ public class ServiceOrderService { serviceOrderRepository.save(serviceOrder); } - public void addOrderItemMessage(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, String code) { + public void addOrderItemMessage(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, String code) { OrderMessage orderMessage = new OrderMessage(); orderMessage.setCode(code); orderMessage.setSeverity(SeverityMessage.ERROR); @@ -148,7 +145,8 @@ public class ServiceOrderService { } - public void addOrderItemMessageRequestSo(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, String message) { + public void addOrderItemMessageRequestSo(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, + String message) { OrderMessage orderMessage = new OrderMessage(); orderMessage.setCode("105"); orderMessage.setSeverity(SeverityMessage.ERROR); diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java index b153ff1..67f3a86 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Optional; import org.onap.nbi.apis.serviceorder.model.ActionType; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; @@ -70,7 +71,13 @@ public class SOTaskProcessor { ServiceOrderInfo serviceOrderInfo = getServiceOrderInfo(executionTask); - ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderInfo.getServiceOrderId()); + Optional<ServiceOrder> optionalServiceOrder = serviceOrderService + .findServiceOrderById(serviceOrderInfo.getServiceOrderId()); + if (!optionalServiceOrder.isPresent()) { + throw new TechnicalException( + "Unable to retrieve service order for id " + serviceOrderInfo.getServiceOrderId()); + } + ServiceOrder serviceOrder = optionalServiceOrder.get(); ServiceOrderItem serviceOrderItem = getServiceOrderItem(executionTask, serviceOrder); boolean e2eService = E2EServiceUtils .isE2EService(serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId())); @@ -84,14 +91,14 @@ public class SOTaskProcessor { } else { ResponseEntity<CreateServiceInstanceResponse> response = postSoProcessor - .postServiceOrderItem(serviceOrderInfo,serviceOrderItem); + .postServiceOrderItem(serviceOrderInfo, serviceOrderItem); updateServiceOrderItem(response, serviceOrderItem, serviceOrder); } } boolean shouldStopPolling = shouldStopPolling(executionTask); if (!shouldStopPolling && StateType.FAILED != serviceOrderItem.getState() - ) { + ) { // TODO lancer en asynchrone sOGetStatusManager.pollRequestStatus(serviceOrder, serviceOrderItem, e2eService); @@ -109,7 +116,8 @@ public class SOTaskProcessor { } private boolean shouldPostSo(ServiceOrderItem serviceOrderItem) { - return StateType.ACKNOWLEDGED == serviceOrderItem.getState() || StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState(); + return StateType.ACKNOWLEDGED == serviceOrderItem.getState() + || StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState(); } private ServiceOrderItem getServiceOrderItem(ExecutionTask executionTask, ServiceOrder serviceOrder) { @@ -178,7 +186,6 @@ public class SOTaskProcessor { } - /** * Update ServiceOrderItem with SO response by using serviceOrderRepository with the serviceOrderId */ @@ -188,7 +195,7 @@ public class SOTaskProcessor { if (response == null || !response.getStatusCode().is2xxSuccessful()) { LOGGER.warn("response ko for serviceOrderItem.id=" + orderItem.getId()); serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED); - buildOrderMessageIfNeeded(orderItem,serviceOrder,response); + buildOrderMessageIfNeeded(orderItem, serviceOrder, response); } else { CreateServiceInstanceResponse createServiceInstanceResponse = response.getBody(); if (createServiceInstanceResponse != null && !orderItem.getState().equals(StateType.FAILED)) { @@ -209,14 +216,16 @@ public class SOTaskProcessor { } - private void updateOrderItemToInProgress(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem){ - if(serviceOrderItem.getAction()!= ActionType.MODIFY){ + private void updateOrderItemToInProgress(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem) { + if (serviceOrderItem.getAction() != ActionType.MODIFY) { serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.INPROGRESS); } else { - if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()){ - serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND); + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, + StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND); } else { - serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND); + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, + StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND); } } } @@ -224,17 +233,16 @@ public class SOTaskProcessor { private void buildOrderMessageIfNeeded(ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder, ResponseEntity<?> response) { - if(response!=null) - { - if(response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) { + if (response != null) { + if (response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) { serviceOrderService.addOrderMessage(serviceOrder, "502"); - } - else if(response.getStatusCode()== HttpStatus.BAD_REQUEST) { - ResponseEntity<?> messageError=response; - if(messageError.getBody().toString().toLowerCase().contains("serviceinstance already exists")){ + } else if (response.getStatusCode() == HttpStatus.BAD_REQUEST) { + ResponseEntity<?> messageError = response; + if (messageError.getBody().toString().toLowerCase().contains("serviceinstance already exists")) { serviceOrderService.addOrderItemMessage(serviceOrder, serviceOrderItem, "105"); } else { - serviceOrderService.addOrderItemMessageRequestSo(serviceOrder, serviceOrderItem, messageError.getBody().toString()); + serviceOrderService.addOrderItemMessageRequestSo(serviceOrder, serviceOrderItem, + messageError.getBody().toString()); } } } @@ -273,7 +281,7 @@ public class SOTaskProcessor { * Update an executionTask in database when it's process with a success */ private void updateSuccessTask(ExecutionTask executionTask) { - executionTaskRepository.delete(executionTask.getInternalId()); + executionTaskRepository.deleteById(executionTask.getInternalId()); executionTaskRepository.updateReliedTaskAfterDelete(executionTask.getInternalId()); } @@ -326,8 +334,8 @@ public class SOTaskProcessor { private boolean shouldStopPolling(ExecutionTask executionTask) { long createTimeinMillis = executionTask.getCreateDate().getTime(); long lastAttemptTimeInMillis = executionTask.getLastAttemptDate().getTime(); - long differenceInMillis = lastAttemptTimeInMillis-createTimeinMillis; - float pollingDurationInMillis = pollingDurationInMins*60000; + long differenceInMillis = lastAttemptTimeInMillis - createTimeinMillis; + float pollingDurationInMillis = pollingDurationInMins * 60000; LOGGER.debug("Task {} with orderitem id {}: Task create date: {} Task last attempt date: {}", executionTask.getInternalId(), executionTask.getOrderItemId(), createTimeinMillis, lastAttemptTimeInMillis); diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index b890216..b959b47 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -17,7 +17,7 @@ nbi.version = v3 # SERVER -server.contextPath = /nbi/api/${nbi.version} +server.servlet.context-path = /nbi/api/${nbi.version} server.port = 8080 # LOGGING @@ -29,7 +29,7 @@ onap.tenantId = 31047205ce114b60833b23e400d6a535 onap.cloudOwner = CloudOwner # NBI -nbi.url = http://localhost:${server.port}${server.contextPath} +nbi.url = http://localhost:${server.port}${server.servlet.context-path} nbi.callForVNF = false # SCHEDULER diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6a66737..633e029 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,7 +23,7 @@ spring.profiles.active = default nbi.version = v3 # SERVER -server.contextPath = /nbi/api/${nbi.version} +server.servlet.context-path = /nbi/api/${nbi.version} server.port = 8080 # LOGGING @@ -35,7 +35,7 @@ onap.tenantId = 6e97a2bd51d74f6db5671d8dc1517d82 onap.cloudOwner = CloudOwner # NBI -nbi.url = http://localhost:${server.port}${server.contextPath} +nbi.url = http://localhost:${server.port}${server.servlet.context-path} nbi.callForVNF = false # SCHEDULER diff --git a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java index bc51541..7bc8a41 100644 --- a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java +++ b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java @@ -24,6 +24,7 @@ import com.github.tomakehurst.wiremock.stubbing.StubMapping; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Optional; import javax.validation.Validation; import javax.validation.Validator; import javax.validation.ValidatorFactory; @@ -120,7 +121,10 @@ public class ExecutionTaskTest { } - + private ServiceOrder getServiceOrder(String serviceOrderId) { + Optional<ServiceOrder> serviceOrderChecked = serviceOrderRepository.findById(serviceOrderId); + return serviceOrderChecked.get(); + } @@ -133,7 +137,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -149,7 +153,7 @@ public class ExecutionTaskTest { assertThat(executionTaskA).isNull(); SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); @@ -171,7 +175,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -187,7 +191,7 @@ public class ExecutionTaskTest { assertThat(executionTaskA).isNull(); SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); @@ -209,7 +213,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -225,7 +229,7 @@ public class ExecutionTaskTest { assertThat(executionTaskA).isNull(); SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); @@ -247,7 +251,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -263,7 +267,7 @@ public class ExecutionTaskTest { assertThat(executionTaskA).isNull(); SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); @@ -287,7 +291,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -303,7 +307,7 @@ public class ExecutionTaskTest { changeCreationDate(executionTaskA); SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -333,7 +337,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -347,7 +351,7 @@ public class ExecutionTaskTest { changeCreationDate(executionTaskA); SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -369,7 +373,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -392,7 +396,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -413,7 +417,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -438,7 +442,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -466,7 +470,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -477,7 +481,7 @@ public class ExecutionTaskTest { } } SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -495,7 +499,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskB); SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); @@ -519,7 +523,7 @@ public class ExecutionTaskTest { SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { if (serviceOrderItem.getId().equals("A")) { @@ -534,7 +538,7 @@ public class ExecutionTaskTest { changeCreationDate(executionTaskA); SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = serviceOrderRepository.findOne("test"); + serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); @@ -552,7 +556,7 @@ public class ExecutionTaskTest { executionTaskRepository, ActionType.ADD); SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = serviceOrderRepository.findOne("test"); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); diff --git a/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java b/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java index 11ed493..fd83ec0 100644 --- a/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java +++ b/src/test/java/org/onap/nbi/test/ServiceOrderRepositoryTest.java @@ -18,8 +18,10 @@ package org.onap.nbi.test; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.List; +import java.util.Optional; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,8 +55,8 @@ public class ServiceOrderRepositoryTest { @Test public void findById() { - ServiceOrder result = serviceOrderRepository.findOne("test"); - assertNotNull(result); + Optional<ServiceOrder> optionalServiceOrderChecked = serviceOrderRepository.findById("test"); + assertTrue(optionalServiceOrderChecked.isPresent()); } @Test |