Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class AdminBasicInfoControllerTest {
private MockMvc mockMvc;
private Response response = new Response();

private static final String DEFAULT_PRICE_ID = String.valueOf(1);
private static final String DEFAULT_STATION_ID = String.valueOf(1);

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand Down Expand Up @@ -101,7 +104,7 @@ public void testDeleteStation() throws Exception {
Station s = new Station();
Mockito.when(adminBasicInfoService.deleteStation(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response);
String requestJson = JSONObject.toJSONString(s);
String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/adminbasicservice/adminbasic/stations").contentType(MediaType.APPLICATION_JSON).content(requestJson))
String result = mockMvc.perform(MockMvcRequestBuilders.delete(String.join("/", "/api/v1/adminbasicservice/adminbasic/stations", DEFAULT_STATION_ID)).contentType(MediaType.APPLICATION_JSON).content(requestJson))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn().getResponse().getContentAsString();
Assert.assertEquals(response, JSONObject.parseObject(result, Response.class));
Expand Down Expand Up @@ -223,7 +226,7 @@ public void testDeletePrice() throws Exception {
PriceInfo pi = new PriceInfo();
Mockito.when(adminBasicInfoService.deletePrice(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response);
String requestJson = JSONObject.toJSONString(pi);
String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/adminbasicservice/adminbasic/prices").contentType(MediaType.APPLICATION_JSON).content(requestJson))
String result = mockMvc.perform(MockMvcRequestBuilders.delete(String.join("/", "/api/v1/adminbasicservice/adminbasic/prices", DEFAULT_PRICE_ID)).contentType(MediaType.APPLICATION_JSON).content(requestJson))
.andExpect(MockMvcResultMatchers.status().isOk())
.andReturn().getResponse().getContentAsString();
Assert.assertEquals(response, JSONObject.parseObject(result, Response.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class AdminBasicInfoServiceImplTest {
private Response response = new Response();
private ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);

private static final String DEFAULT_PRICE_ID = String.valueOf(1);
private static final String DEFAULT_STATION_ID = String.valueOf(1);

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand All @@ -37,7 +40,7 @@ public void setUp() {
@Test
public void testGetAllContacts() {
Mockito.when(restTemplate.exchange(
"http://ts-contacts-service:12347/api/v1/contactservice/contacts",
"http://ts-contacts-service/api/v1/contactservice/contacts",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -48,7 +51,7 @@ public void testGetAllContacts() {
@Test
public void testDeleteContact() {
Mockito.when(restTemplate.exchange(
"http://ts-contacts-service:12347/api/v1/contactservice/contacts/" + "contactsId",
"http://ts-contacts-service/api/v1/contactservice/contacts/" + "contactsId",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -61,7 +64,7 @@ public void testModifyContact() {
Contacts mci = new Contacts();
HttpEntity<Contacts> requestEntity = new HttpEntity<>(mci, headers);
Mockito.when(restTemplate.exchange(
"http://ts-contacts-service:12347/api/v1/contactservice/contacts",
"http://ts-contacts-service/api/v1/contactservice/contacts",
HttpMethod.PUT,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -74,7 +77,7 @@ public void testAddContact() {
Contacts c = new Contacts();
HttpEntity<Contacts> requestEntity = new HttpEntity<>(c, headers);
Mockito.when(restTemplate.exchange(
"http://ts-contacts-service:12347/api/v1/contactservice/contacts/admin",
"http://ts-contacts-service/api/v1/contactservice/contacts/admin",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -85,7 +88,7 @@ public void testAddContact() {
@Test
public void testGetAllStations() {
Mockito.when(restTemplate.exchange(
"http://ts-station-service:12345/api/v1/stationservice/stations",
"http://ts-station-service/api/v1/stationservice/stations",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -98,7 +101,7 @@ public void testAddStation() {
Station s = new Station();
HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers);
Mockito.when(restTemplate.exchange(
"http://ts-station-service:12345/api/v1/stationservice/stations",
"http://ts-station-service/api/v1/stationservice/stations",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -109,9 +112,10 @@ public void testAddStation() {
@Test
public void testDeleteStation() {
Station s = new Station();
HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers);
s.setId(DEFAULT_STATION_ID);
HttpEntity requestEntity = new HttpEntity(headers);
Mockito.when(restTemplate.exchange(
"http://ts-station-service:12345/api/v1/stationservice/stations",
"http://ts-station-service/api/v1/stationservice/stations/" + DEFAULT_STATION_ID,
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -124,7 +128,7 @@ public void testModifyStation() {
Station s = new Station();
HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers);
Mockito.when(restTemplate.exchange(
"http://ts-station-service:12345/api/v1/stationservice/stations",
"http://ts-station-service/api/v1/stationservice/stations",
HttpMethod.PUT,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -135,7 +139,7 @@ public void testModifyStation() {
@Test
public void testGetAllTrains() {
Mockito.when(restTemplate.exchange(
"http://ts-train-service:14567/api/v1/trainservice/trains",
"http://ts-train-service/api/v1/trainservice/trains",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -148,7 +152,7 @@ public void testAddTrain() {
TrainType t = new TrainType();
HttpEntity<TrainType> requestEntity = new HttpEntity<>(t, headers);
Mockito.when(restTemplate.exchange(
"http://ts-train-service:14567/api/v1/trainservice/trains",
"http://ts-train-service/api/v1/trainservice/trains",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -159,7 +163,7 @@ public void testAddTrain() {
@Test
public void testDeleteTrain() {
Mockito.when(restTemplate.exchange(
"http://ts-train-service:14567/api/v1/trainservice/trains/" + "id",
"http://ts-train-service/api/v1/trainservice/trains/" + "id",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -172,7 +176,7 @@ public void testModifyTrain() {
TrainType t = new TrainType();
HttpEntity<TrainType> requestEntity = new HttpEntity<>(t, headers);
Mockito.when(restTemplate.exchange(
"http://ts-train-service:14567/api/v1/trainservice/trains",
"http://ts-train-service/api/v1/trainservice/trains",
HttpMethod.PUT,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -183,7 +187,7 @@ public void testModifyTrain() {
@Test
public void testGetAllConfigs() {
Mockito.when(restTemplate.exchange(
"http://ts-config-service:15679/api/v1/configservice/configs",
"http://ts-config-service/api/v1/configservice/configs",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -196,7 +200,7 @@ public void testAddConfig() {
Config c = new Config();
HttpEntity<Config> requestEntity = new HttpEntity<>(c, headers);
Mockito.when(restTemplate.exchange(
"http://ts-config-service:15679/api/v1/configservice/configs",
"http://ts-config-service/api/v1/configservice/configs",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -207,7 +211,7 @@ public void testAddConfig() {
@Test
public void testDeleteConfig() {
Mockito.when(restTemplate.exchange(
"http://ts-config-service:15679/api/v1/configservice/configs/" + "name",
"http://ts-config-service/api/v1/configservice/configs/" + "name",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -220,7 +224,7 @@ public void testModifyConfig() {
Config c = new Config();
HttpEntity<Config> requestEntity = new HttpEntity<>(c, headers);
Mockito.when(restTemplate.exchange(
"http://ts-config-service:15679/api/v1/configservice/configs",
"http://ts-config-service/api/v1/configservice/configs",
HttpMethod.PUT,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -231,7 +235,7 @@ public void testModifyConfig() {
@Test
public void testGetAllPrices() {
Mockito.when(restTemplate.exchange(
"http://ts-price-service:16579/api/v1/priceservice/prices",
"http://ts-price-service/api/v1/priceservice/prices",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -244,7 +248,7 @@ public void testAddPrice() {
PriceInfo pi = new PriceInfo();
HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers);
Mockito.when(restTemplate.exchange(
"http://ts-price-service:16579/api/v1/priceservice/prices",
"http://ts-price-service/api/v1/priceservice/prices",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -255,9 +259,10 @@ public void testAddPrice() {
@Test
public void testDeletePrice() {
PriceInfo pi = new PriceInfo();
HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers);
pi.setId(DEFAULT_PRICE_ID);
HttpEntity requestEntity = new HttpEntity(headers);
Mockito.when(restTemplate.exchange(
"http://ts-price-service:16579/api/v1/priceservice/prices",
"http://ts-price-service/api/v1/priceservice/prices/" + DEFAULT_PRICE_ID,
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -270,7 +275,7 @@ public void testModifyPrice() {
PriceInfo pi = new PriceInfo();
HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers);
Mockito.when(restTemplate.exchange(
"http://ts-price-service:16579/api/v1/priceservice/prices",
"http://ts-price-service/api/v1/priceservice/prices",
HttpMethod.PUT,
requestEntity,
Response.class)).thenReturn(re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public void testGetAllOrders1() {
Response<ArrayList<Order>> response = new Response<>(0, null, null);
ResponseEntity<Response<ArrayList<Order>>> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-service:12031/api/v1/orderservice/order",
"http://ts-order-service/api/v1/orderservice/order",
HttpMethod.GET,
requestEntity,
new ParameterizedTypeReference<Response<ArrayList<Order>>>() {
})).thenReturn(re);
Mockito.when(restTemplate.exchange(
"http://ts-order-other-service:12032/api/v1/orderOtherService/orderOther",
"http://ts-order-other-service/api/v1/orderOtherService/orderOther",
HttpMethod.GET,
requestEntity,
new ParameterizedTypeReference<Response<ArrayList<Order>>>() {
Expand All @@ -61,13 +61,13 @@ public void testGetAllOrders2() {
Response<ArrayList<Order>> response = new Response<>(1, null, orders);
ResponseEntity<Response<ArrayList<Order>>> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-service:12031/api/v1/orderservice/order",
"http://ts-order-service/api/v1/orderservice/order",
HttpMethod.GET,
requestEntity,
new ParameterizedTypeReference<Response<ArrayList<Order>>>() {
})).thenReturn(re);
Mockito.when(restTemplate.exchange(
"http://ts-order-other-service:12032/api/v1/orderOtherService/orderOther",
"http://ts-order-other-service/api/v1/orderOtherService/orderOther",
HttpMethod.GET,
requestEntity,
new ParameterizedTypeReference<Response<ArrayList<Order>>>() {
Expand All @@ -81,7 +81,7 @@ public void testDeleteOrder1() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-service:12031/api/v1/orderservice/order/" + "orderId",
"http://ts-order-service/api/v1/orderservice/order/" + "orderId",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -94,7 +94,7 @@ public void testDeleteOrder2() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-other-service:12032/api/v1/orderOtherService/orderOther/" + "orderId",
"http://ts-order-other-service/api/v1/orderOtherService/orderOther/" + "orderId",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -109,7 +109,7 @@ public void testUpdateOrder1() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-service:12031/api/v1/orderservice/order/admin",
"http://ts-order-service/api/v1/orderservice/order/admin",
HttpMethod.PUT,
requestEntity2,
Response.class)).thenReturn(re);
Expand All @@ -124,7 +124,7 @@ public void testUpdateOrder2() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-other-service:12032/api/v1/orderOtherService/orderOther/admin",
"http://ts-order-other-service/api/v1/orderOtherService/orderOther/admin",
HttpMethod.PUT,
requestEntity2,
Response.class)).thenReturn(re);
Expand All @@ -139,7 +139,7 @@ public void testAddOrder1() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-service:12031/api/v1/orderservice/order/admin",
"http://ts-order-service/api/v1/orderservice/order/admin",
HttpMethod.POST,
requestEntity2,
Response.class)).thenReturn(re);
Expand All @@ -154,7 +154,7 @@ public void testAddOrder2() {
Response response = new Response();
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-order-other-service:12032/api/v1/orderOtherService/orderOther/admin",
"http://ts-order-other-service/api/v1/orderOtherService/orderOther/admin",
HttpMethod.POST,
requestEntity2,
Response.class)).thenReturn(re);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RunWith(JUnit4.class)
public class AdminRouteServiceImplTest {

Expand All @@ -38,7 +44,7 @@ public void setUp() {
@Test
public void testGetAllRoutes() {
Mockito.when(restTemplate.exchange(
"http://ts-route-service:11178/api/v1/routeservice/routes",
"http://ts-route-service/api/v1/routeservice/routes",
HttpMethod.GET,
requestEntity,
Response.class)).thenReturn(re);
Expand All @@ -49,22 +55,45 @@ public void testGetAllRoutes() {
@Test
public void testCreateAndModifyRoute() {
RouteInfo request = new RouteInfo();
List<String> stations = new ArrayList<>();
stations.add("NYC");
stations.add("MCO");
stations.add("CHI");
request.setStationList(stations.stream().collect(Collectors.joining(",")));
request.setStartStation("NYC");
request.setEndStation("CHI");

HttpEntity requestEntity = new HttpEntity(stations, null);
Response response = new Response();
response.setStatus(1);
Map<String, String> stationMap = new HashMap<>();
stationMap.put("NYC", "1");
stationMap.put("MCO", "2");
stationMap.put("CHI", "3");
response.setData(stationMap);
ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK);
Mockito.when(restTemplate.exchange(
"http://ts-station-service/api/v1/stationservice/stations/idlist",
HttpMethod.POST,
requestEntity,
Response.class)).thenReturn(re);

HttpEntity requestEntity2 = new HttpEntity(request, headers);
ResponseEntity<Response<Route>> re2 = new ResponseEntity<>(response, HttpStatus.OK);
ResponseEntity<Response<Route>> re2 = new ResponseEntity<>(response, HttpStatus.ACCEPTED);
Mockito.when(restTemplate.exchange(
"http://ts-route-service:11178/api/v1/routeservice/routes",
"http://ts-route-service/api/v1/routeservice/routes",
HttpMethod.POST,
requestEntity2,
new ParameterizedTypeReference<Response<Route>>() {
})).thenReturn(re2);
Response result = adminRouteServiceImpl.createAndModifyRoute(request, headers);
Assert.assertEquals(new Response<>(null, null, null), result);
Assert.assertEquals(new Response<>(1, null, stationMap), result);
}

@Test
public void testDeleteRoute() {
Mockito.when(restTemplate.exchange(
"http://ts-route-service:11178/api/v1/routeservice/routes/" + "routeId",
"http://ts-route-service/api/v1/routeservice/routes/" + "routeId",
HttpMethod.DELETE,
requestEntity,
Response.class)).thenReturn(re);
Expand Down
Loading