summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorNicolasLaplaud <nicolas.laplaud@orange.com>2018-09-07 16:18:11 +0200
committerMatthieuGeerebaert <matthieu.geerebaert@orange.com>2018-09-12 16:52:30 +0200
commitd04ad9a5abd23a93e948ebac2cbe5ae1925e2099 (patch)
tree007324164767c6d5efd4d75e66d92176322e70ff /src/main
parent5bfec6934fc307aecadca43e75b3c04d647bf005 (diff)
Add HubRessource Test
- Improve junit test coverage on HubResource method Change-Id: I90e96ed57b4cb781a2454ac26953f5384a60c032 Issue-ID: EXTAPI-135 Signed-off-by: NicolasLaplaud <nicolas.laplaud@orange.com>
Diffstat (limited to 'src/main')
-rwxr-xr-xsrc/main/java/org/onap/nbi/apis/hub/HubResource.java46
-rw-r--r--src/main/java/org/onap/nbi/apis/hub/service/SubscriptionService.java4
2 files changed, 30 insertions, 20 deletions
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 811dd51..bd98820 100755
--- a/src/main/java/org/onap/nbi/apis/hub/HubResource.java
+++ b/src/main/java/org/onap/nbi/apis/hub/HubResource.java
@@ -1,20 +1,21 @@
/**
- * 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.hub;
+import java.net.URI;
+import java.util.List;
+import java.util.stream.Collectors;
import org.onap.nbi.apis.hub.model.Subscriber;
import org.onap.nbi.apis.hub.model.Subscription;
import org.onap.nbi.apis.hub.service.SubscriptionService;
@@ -32,12 +33,17 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.MultiValueMap;
-import org.springframework.web.bind.annotation.*;
+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.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-import java.net.URI;
-import java.util.List;
-
@RestController
@RequestMapping("/hub")
@EnableScheduling
@@ -60,10 +66,7 @@ public class HubResource extends ResourceManagement {
Subscriber subscriber = subscriptionService.createSubscription(subscription);
- URI location = ServletUriComponentsBuilder
- .fromCurrentRequest()
- .path("/{id}")
- .buildAndExpand(subscriber.getId())
+ URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(subscriber.getId())
.toUri();
return ResponseEntity.created(location).build();
@@ -72,7 +75,7 @@ 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);
+ Subscriber subscriber = subscriptionService.findSubscriptionById(subscriptionId);
if (subscriber == null) {
return ResponseEntity.notFound().build();
}
@@ -90,7 +93,10 @@ public class HubResource extends ResourceManagement {
headers.add("X-Total-Count", String.valueOf(totalCount));
headers.add("X-Result-Count", String.valueOf(subscribers.size()));
- return this.findResponse(subscribers, filter, headers);
+ List<Subscription> subscriptions =
+ subscribers.stream().map(Subscription::createFromSubscriber).collect(Collectors.toList());
+
+ return this.findResponse(subscriptions, filter, headers);
}
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 65eaea3..cf9ab66 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
@@ -40,6 +40,10 @@ public class SubscriptionService {
subscriberRepository.delete(subscriptionId);
}
+ public void deleteAll() {
+ subscriberRepository.deleteAll();
+ }
+
public long countSubscription(){
return subscriberRepository.count();
}