1 | /** | |
2 | * Copyright 2018 SmartBear Software | |
3 | * <p> | |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * <p> | |
8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | * <p> | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
15 | */ | |
16 | ||
17 | package io.swagger.petstore.data; | |
18 | ||
19 | import io.swagger.petstore.model.Address; | |
20 | import io.swagger.petstore.model.Customer; | |
21 | import io.swagger.petstore.model.Customer0; | |
22 | import io.swagger.petstore.model.Order; | |
23 | import io.swagger.petstore.model.Order0; | |
24 | import io.swagger.petstore.model.Pet; | |
25 | import io.swagger.petstore.model.QuantityByZip; | |
26 | ||
27 | import java.util.*; | |
28 | ||
29 | public class OrderData { | |
30 | private static List<Order> orders = new ArrayList<>(); | |
31 | // Add customer data (not included in the original version) | |
32 | private static List<Customer> customers = new ArrayList<>(); | |
33 | ||
34 | static { | |
35 | orders.add(createOrder(1, 1, 1, 100, new Date(), "placed", true)); | |
36 | orders.add(createOrder(2, 1, 1, 50, new Date(), "approved", true)); | |
37 | orders.add(createOrder(3, 1, 1, 50, new Date(), "delivered", true)); | |
38 | customers.add(createCustomer(1,"me")); | |
39 | } | |
40 | | |
41 | //Added methods for test | |
42 | | |
43 | public List<Order> getOrders() { | |
44 | return orders; | |
45 | } | |
46 | ||
47 | public List<Customer> getCustomers() { | |
48 | return customers; | |
49 | } | |
50 | ||
51 | public void deleteAll() { | |
52 | orders = new ArrayList<>(); | |
53 | customers = new ArrayList<>(); | |
54 | } | |
55 | | |
56 | public void addOrder0(final Order0 order) { | |
57 | if (orders.size() > 0) { | |
58 |
2
1. lambda$addOrder0$0 : negated conditional → NO_COVERAGE 2. lambda$addOrder0$0 : replaced boolean return with true for io/swagger/petstore/data/OrderData::lambda$addOrder0$0 → NO_COVERAGE |
orders.removeIf(orderN -> orderN.getId() == order.getId()); |
59 | } | |
60 | orders.add(createOrder(order.getId(), order.getPetId(), order.getCustomerId(), order.getQuantity(), order.getShipDate(), | |
61 | order.getStatus(), order.isComplete())); | |
62 | } | |
63 | ||
64 | public static Order0 createOrder0(final long id, final long petId, final long customerId, final int quantity, final Date shipDate, | |
65 | final String status, final boolean complete) { | |
66 | final Order0 order = new Order0(); | |
67 | order.setId(id); | |
68 | order.setPetId(petId); | |
69 | order.setCustomerId(customerId); | |
70 | order.setComplete(complete); | |
71 | order.setQuantity(quantity); | |
72 | order.setShipDate(shipDate); | |
73 | order.setStatus(status); | |
74 | return order; | |
75 | } | |
76 | ||
77 | public void addCustomer0(final Customer0 customer) { | |
78 | if (customers.size() > 0) { | |
79 |
2
1. lambda$addCustomer0$1 : replaced boolean return with true for io/swagger/petstore/data/OrderData::lambda$addCustomer0$1 → NO_COVERAGE 2. lambda$addCustomer0$1 : negated conditional → NO_COVERAGE |
customers.removeIf(customerN -> customerN.getId() == customer.getId()); |
80 | } | |
81 | customers.add(createCustomer(customer.getId(), customer.getUsername())); | |
82 | } | |
83 | ||
84 | //Customer does not have methods to create from the api, include here | |
85 | | |
86 | public void addCustomer(final Customer customer) { | |
87 | if (customers.size() > 0) { | |
88 |
2
1. lambda$addCustomer$2 : negated conditional → KILLED 2. lambda$addCustomer$2 : replaced boolean return with true for io/swagger/petstore/data/OrderData::lambda$addCustomer$2 → KILLED |
customers.removeIf(customerN -> customerN.getId() == customer.getId()); |
89 | } | |
90 | customers.add(customer); | |
91 | } | |
92 | ||
93 | public static Customer createCustomer(final long id, String username) { | |
94 | final Customer customer = new Customer(); | |
95 | customer.setId(id); | |
96 | customer.setUsername(username); | |
97 | return customer; | |
98 | } | |
99 | | |
100 | //End added methods for test | |
101 | ||
102 | public Order getOrderById(final long orderId) { | |
103 | for (final Order order : orders) { | |
104 | if (order.getId() == orderId) { | |
105 | return order; | |
106 | } | |
107 | } | |
108 | return null; | |
109 | } | |
110 | ||
111 | public Map<String, Integer> getCountByStatus() { | |
112 | ||
113 | final Map<String, Integer> countByStatus = new HashMap<>(); | |
114 | ||
115 | for (final Order order : orders) { | |
116 | final String status = order.getStatus(); | |
117 | if (countByStatus.containsKey(status)) { | |
118 | countByStatus.put(status, countByStatus.get(status) + order.getQuantity()); | |
119 | } else { | |
120 | countByStatus.put(status, order.getQuantity()); | |
121 | } | |
122 | } | |
123 | ||
124 | return countByStatus; | |
125 | } | |
126 | ||
127 | // Add methods to support other queries | |
128 | | |
129 | public List<Order> findOrdersByCategoryAndOrderStatus(final String category, final String status) { | |
130 | final List<Order> result = new ArrayList<>(); | |
131 | for (final Order order: orders) { | |
132 |
1
1. findOrdersByCategoryAndOrderStatus : negated conditional → KILLED |
if (order.getStatus().equals(status)) { |
133 | final long petId = order.getPetId(); | |
134 | for (final Pet pet : new PetData().getPets()) | |
135 |
1
1. findOrdersByCategoryAndOrderStatus : negated conditional → KILLED |
if (pet.getId() == petId) { |
136 |
1
1. findOrdersByCategoryAndOrderStatus : negated conditional → KILLED |
if (pet.getCategory().getName().equals(category)) |
137 | result.add(order); | |
138 | } | |
139 | } | |
140 | } | |
141 |
1
1. findOrdersByCategoryAndOrderStatus : replaced return value with Collections.emptyList for io/swagger/petstore/data/OrderData::findOrdersByCategoryAndOrderStatus → KILLED |
return result; |
142 | } | |
143 | ||
144 | public List<QuantityByZip> totalPetsToDeliverByAddress() { | |
145 | final TreeMap<String, Long> result = new TreeMap<>(); | |
146 | for (final Customer customer: customers) | |
147 |
1
1. totalPetsToDeliverByAddress : negated conditional → KILLED |
if (customer.getAddress() != null) |
148 | for (final Address address: customer.getAddress()) { // collect zips | |
149 | String zip = address.getZip(); | |
150 |
1
1. totalPetsToDeliverByAddress : negated conditional → KILLED |
if (!result.containsKey(zip)) |
151 | result.put(zip, (long) 0); // new zip | |
152 | // count all orders of this customer and add to this zip | |
153 | for (final Order order: orders) | |
154 |
2
1. totalPetsToDeliverByAddress : negated conditional → KILLED 2. totalPetsToDeliverByAddress : negated conditional → KILLED |
if (order.getCustomerId() == customer.getId() && "approved".equals(order.getStatus())) |
155 |
1
1. totalPetsToDeliverByAddress : Replaced long addition with subtraction → KILLED |
result.put(zip, result.get(zip) + order.getQuantity()); |
156 | } | |
157 | List<QuantityByZip> resultDto = new ArrayList<>(); | |
158 | for (Map.Entry<String, Long> entry : result.entrySet()) | |
159 | resultDto.add(new QuantityByZip(entry.getKey(), entry.getValue())); | |
160 |
1
1. totalPetsToDeliverByAddress : replaced return value with Collections.emptyList for io/swagger/petstore/data/OrderData::totalPetsToDeliverByAddress → KILLED |
return resultDto; |
161 | } | |
162 | ||
163 | public List<Order> updateDeliveryToCustomer(long customerId) { | |
164 | final List<Order> result = new ArrayList<>(); | |
165 | for (final Order order: orders) { | |
166 |
2
1. updateDeliveryToCustomer : negated conditional → KILLED 2. updateDeliveryToCustomer : negated conditional → KILLED |
if ("approved".equals(order.getStatus()) && order.getCustomerId() == customerId) { |
167 |
1
1. updateDeliveryToCustomer : removed call to io/swagger/petstore/model/Order::setStatus → KILLED |
order.setStatus("delivered"); |
168 | result.add(order); | |
169 | } | |
170 | } | |
171 |
1
1. updateDeliveryToCustomer : replaced return value with Collections.emptyList for io/swagger/petstore/data/OrderData::updateDeliveryToCustomer → KILLED |
return result; |
172 | } | |
173 | ||
174 | // End added methods | |
175 | ||
176 | public void addOrder(final Order order) { | |
177 | if (orders.size() > 0) { | |
178 |
2
1. lambda$addOrder$3 : negated conditional → KILLED 2. lambda$addOrder$3 : replaced boolean return with true for io/swagger/petstore/data/OrderData::lambda$addOrder$3 → KILLED |
orders.removeIf(orderN -> orderN.getId() == order.getId()); |
179 | } | |
180 | orders.add(order); | |
181 | } | |
182 | ||
183 | public void deleteOrderById(final Long orderId) { | |
184 |
2
1. lambda$deleteOrderById$4 : replaced boolean return with true for io/swagger/petstore/data/OrderData::lambda$deleteOrderById$4 → NO_COVERAGE 2. lambda$deleteOrderById$4 : negated conditional → NO_COVERAGE |
orders.removeIf(order -> order.getId() == orderId); |
185 | } | |
186 | ||
187 | public static Order createOrder(final long id, final long petId, final long customerId, final int quantity, final Date shipDate, | |
188 | final String status, final boolean complete) { | |
189 | final Order order = new Order(); | |
190 | order.setId(id); | |
191 | order.setPetId(petId); | |
192 | order.setCustomerId(customerId); | |
193 | order.setComplete(complete); | |
194 | order.setQuantity(quantity); | |
195 | order.setShipDate(shipDate); | |
196 | order.setStatus(status); | |
197 | return order; | |
198 | } | |
199 | } | |
Mutations | ||
58 |
1.1 2.2 |
|
79 |
1.1 2.2 |
|
88 |
1.1 2.2 |
|
132 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
141 |
1.1 |
|
147 |
1.1 |
|
150 |
1.1 |
|
154 |
1.1 2.2 |
|
155 |
1.1 |
|
160 |
1.1 |
|
166 |
1.1 2.2 |
|
167 |
1.1 |
|
171 |
1.1 |
|
178 |
1.1 2.2 |
|
184 |
1.1 2.2 |