Skip to content

Commit

Permalink
remove had text from test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ntqdinh-axonivy committed Dec 27, 2024
1 parent ea1a226 commit 3ac46cf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.Duration;
import java.time.OffsetDateTime;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.openweathermap.api.data2_5.client.AirPollution;

Expand All @@ -21,8 +22,8 @@ public class AirPollutionProcessTest extends BaseProcessTest {
@Test
public void testGetAirPollutionByGeoCode_ReturnsAirPollution(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152);
var object = result.data().last().get("result");
GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(AirPollution.class);
}

Expand All @@ -32,16 +33,16 @@ public void testGetAirPollutionByGeoCode_ThrowsBpmException(BpmClient bpmClient)
getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}

@Test
public void testGetForecastAirPollutionByGeoCode_ReturnsAirPollution(BpmClient bpmClient)
throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152);
var object = result.data().last().get("result");
GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(AirPollution.class);
}

Expand All @@ -52,7 +53,7 @@ public void testGetForecastAirPollutionByGeoCode_ThrowsBpmException(BpmClient bp
getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_FORECAST_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}

Expand All @@ -62,8 +63,9 @@ public void testGetHistoricalAirPollutionByGeoCode_ReturnsAirPollution(BpmClient
OffsetDateTime now = OffsetDateTime.now();
OffsetDateTime twoDaysLater = now.plus(Duration.ofDays(2));
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(40.7127281, -74.0060152, now, twoDaysLater);
var object = result.data().last().get("result");
GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE)
.execute(TEST_LON_VALUE, TEST_LAT_VALUE, now, twoDaysLater);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(AirPollution.class);
}

Expand All @@ -76,7 +78,7 @@ public void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionCanNotGeo(B
getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE).execute(null, null, now, twoDaysLater);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}

Expand All @@ -88,9 +90,9 @@ public void testGetHistoricalAirPollutionByGeoCode_ThrowsBpmExceptionStartMoreTh
try {
getSubProcessWithNameAndPath(bpmClient, GET_AIR_POLLUTION_PROCESS_PATH,
GET_HISTORICAL_AIR_POLLUTION_BY_GEOCODE_SIGNATURE)
.execute(40.7127281, -74.0060152, twoDaysLater, now);
.execute(TEST_LON_VALUE, TEST_LAT_VALUE, twoDaysLater, now);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public class BaseProcessTest {
private static final String LOCAL_CREDENTIALS_FILE_PATH = "credentials.properties";
private static final String WEATHER_DATA_REST_CLIENT_NAME = "WeatherData (Openweathermap weather API)";
private static final String GEO_DATA_REST_CLIENT_NAME = "GeocodingCoordinates (Openweathermap geocoding API)";
protected static final String RESULT_KEY = "result";
protected static final String RESULTS_KEY = "results";
protected static final Double TEST_LON_VALUE = 40.7484;
protected static final Double TEST_LAT_VALUE = -73.9967;
protected static final String TEST_ZIPCODE_VALUE = "10001";
private static String appId;
private static String weatherDataUrl;
private static String weatherGeoUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.openweathermap.api.data2_5.client.Current;

Expand All @@ -18,8 +19,8 @@ public class CurrentWeatherProcessTest extends BaseProcessTest {
public void testGetCurrentWeatherByGeoCode_ReturnsCurrentWeather(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_CURRENT_WEATHER_PROCESS_PATH,
GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE)
.execute(40.7127281, -74.0060152, StringUtils.EMPTY, StringUtils.EMPTY);
var object = result.data().last().get("result");
.execute(TEST_LON_VALUE, TEST_LAT_VALUE, StringUtils.EMPTY, StringUtils.EMPTY);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(Current.class);
}

Expand All @@ -29,7 +30,7 @@ public void testGetCurrentWeatherByGeoCode_ThrowsBpmException(BpmClient bpmClien
getSubProcessWithNameAndPath(bpmClient, GET_CURRENT_WEATHER_PROCESS_PATH,
GET_CURRENT_WEATHER_BY_GEOCODE_SIGNATURE).execute(null, null, StringUtils.EMPTY, StringUtils.EMPTY);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.openweathermap.api.data2_5.client.Forecast;

Expand All @@ -19,8 +20,8 @@ public class ForecastWeatherProcessTest extends BaseProcessTest {
public void testGetForecastWeatherByGeoCode_ReturnsForecast(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GET_FORECAST_PROCESS_PATH,
GET_FORECAST_BY_GEOCODE_SIGNATURE)
.execute(40.7127281, -74.0060152, 1, StringUtils.EMPTY, StringUtils.EMPTY);
var object = result.data().last().get("result");
.execute(TEST_LON_VALUE, TEST_LAT_VALUE, 1, StringUtils.EMPTY, StringUtils.EMPTY);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(Forecast.class);
}

Expand All @@ -30,7 +31,7 @@ public void testGetForecastByGeoCode_ThrowsBpmException(BpmClient bpmClient) thr
getSubProcessWithNameAndPath(bpmClient, GET_FORECAST_PROCESS_PATH, GET_FORECAST_BY_GEOCODE_SIGNATURE)
.execute(null, null, 1, StringUtils.EMPTY, StringUtils.EMPTY);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.junit.jupiter.api.Test;
import org.openweathermap.api.geo1_0.client.GeoLocation;

Expand All @@ -24,7 +25,7 @@ public class GeocodingLocationProcessTest extends BaseProcessTest {
public void testGeocodingByName_ReturnsListOfGeoLocations(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH,
GEOCODING_LOCATION_BY_NAME_SIGNATURE).execute("London", StringUtils.EMPTY, StringUtils.EMPTY, 1);
var object = result.data().last().get("results");
var object = result.data().last().get(RESULTS_KEY);
assertThat(object).isInstanceOf(List.class);
var objects = (ArrayList<?>) object;
assertThat(objects).isNotEmpty();
Expand All @@ -38,15 +39,15 @@ public void testGeocodingByName_ThrowsBpmException(BpmClient bpmClient) throws N
GEOCODING_LOCATION_BY_NAME_SIGNATURE)
.execute(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, 1);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}

@Test
public void testGeocodingByZip_ReturnsGeoLocation(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH,
GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute("10001", StringUtils.EMPTY);
var object = result.data().last().get("result");
GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute(TEST_ZIPCODE_VALUE, StringUtils.EMPTY);
var object = result.data().last().get(RESULT_KEY);
assertThat(object).isInstanceOf(GeoLocation.class);
}

Expand All @@ -56,15 +57,15 @@ public void testGeocodingByZip_ThrowsBpmException(BpmClient bpmClient) throws No
getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH,
GEOCODING_LOCATION_BY_ZIP_CODE_SIGNATURE).execute(StringUtils.EMPTY, StringUtils.EMPTY);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}

@Test
public void testReverse_ReturnsListOfGeoLocations(BpmClient bpmClient) throws NoSuchFieldException {
ExecutionResult result = getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH,
GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(40.7484, -73.9967, 1);
var object = result.data().last().get("results");
GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(TEST_LON_VALUE, TEST_LAT_VALUE, 1);
var object = result.data().last().get(RESULTS_KEY);
assertThat(object).isInstanceOf(List.class);
var objects = (ArrayList<?>) object;
assertThat(objects).isNotEmpty();
Expand All @@ -77,7 +78,7 @@ public void testReverse_ThrowsBpmException(BpmClient bpmClient) throws NoSuchFie
getSubProcessWithNameAndPath(bpmClient, GEOCODING_LOCATION_PROCESS_PATH,
GEOCODING_LOCATION_REVERSE_SIGNATURE).execute(null, null, 1);
} catch (BpmError e) {
assertThat(e.getHttpStatusCode()).isEqualTo(400);
assertThat(e.getHttpStatusCode()).isEqualTo(HttpStatus.SC_BAD_REQUEST);
}
}
}

0 comments on commit 3ac46cf

Please sign in to comment.