|
@@ -35,7 +35,7 @@ class FieldClimateFetcherTest {
|
|
|
|
|
|
|
|
private static FieldClimateConfig config;
|
|
private static FieldClimateConfig config;
|
|
|
private static AuthenticationService authService;
|
|
private static AuthenticationService authService;
|
|
|
- private static LocalDateTime startDate = LocalDateTime.of(2019, 10, 1, 0, 0,0);
|
|
|
|
|
|
|
+ private static LocalDateTime startDate = LocalDateTime.of(2019, 3, 6, 00, 00,0);
|
|
|
|
|
|
|
|
@BeforeAll
|
|
@BeforeAll
|
|
|
static void init() {
|
|
static void init() {
|
|
@@ -61,6 +61,7 @@ class FieldClimateFetcherTest {
|
|
|
}});
|
|
}});
|
|
|
|
|
|
|
|
fcDConfig.setProperty("startDate", startDate);
|
|
fcDConfig.setProperty("startDate", startDate);
|
|
|
|
|
+ fcDConfig.setProperty("period", 12);
|
|
|
|
|
|
|
|
config = new FieldClimateConfig(fcDConfig);
|
|
config = new FieldClimateConfig(fcDConfig);
|
|
|
authService = new AuthenticationService(config.getAuthentication());
|
|
authService = new AuthenticationService(config.getAuthentication());
|
|
@@ -88,7 +89,6 @@ class FieldClimateFetcherTest {
|
|
|
FieldClimateFetcher fetcher = new FieldClimateFetcher(config, authService, httpClient);
|
|
FieldClimateFetcher fetcher = new FieldClimateFetcher(config, authService, httpClient);
|
|
|
|
|
|
|
|
fetcher.init();
|
|
fetcher.init();
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -370,6 +370,60 @@ class FieldClimateFetcherTest {
|
|
|
assertEquals(100, Integer.valueOf(data.get(sensorDataHash)));
|
|
assertEquals(100, Integer.valueOf(data.get(sensorDataHash)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void fetch_TimeRange_EmptyModel() throws Exception {
|
|
|
|
|
+ String stationName = "original_name";
|
|
|
|
|
+ HttpClient httpClient = mock(HttpClient.class);
|
|
|
|
|
+ when(httpClient.send(any(HttpRequest.class))).thenAnswer((Answer<HttpResponse>) invocationOnMock -> {
|
|
|
|
|
+ HttpRequest request = invocationOnMock.getArgument(0, HttpRequest.class);
|
|
|
|
|
+ String path = request.getUrl().getPath();
|
|
|
|
|
+ if (path.contains("/user/stations")) {
|
|
|
|
|
+ StationInfo stationInfo = new StationInfo();
|
|
|
|
|
+ StationInfo.Name name = new StationInfo.Name();
|
|
|
|
|
+ name.setOriginal(stationName);
|
|
|
|
|
+ stationInfo.setName(name);
|
|
|
|
|
+ List<StationInfo> stations = singletonList(stationInfo);
|
|
|
|
|
+ return HttpResponse.newBuilder()
|
|
|
|
|
+ .status(OK).body(stations.toString()).build();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (path.contains("/data/"+stationName)) {
|
|
|
|
|
+ String json = String.format("{\"min_date\":\"%s\",\"max_date\":\"%s\"}",
|
|
|
|
|
+ startDate.minusDays(1).format(ofPattern("yyyy-MM-dd HH:mm:ss")),
|
|
|
|
|
+ startDate.plusDays(1).format(ofPattern("yyyy-MM-dd HH:mm:ss"))
|
|
|
|
|
+ );
|
|
|
|
|
+ return HttpResponse.newBuilder().status(OK).body(json).build();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (path.contains("/data/normal/"+stationName)) {
|
|
|
|
|
+ StationData data = new StationData();
|
|
|
|
|
+ data.setId(stationName);
|
|
|
|
|
+ SensorDataInfo dataInfo = new SensorDataInfo();
|
|
|
|
|
+ Map<String, String> dataMap = new HashMap<>();
|
|
|
|
|
+ dataMap.put("date", startDate.plusHours(1).format(ofPattern("yyyy-MM-dd HH:mm:ss")));
|
|
|
|
|
+ data.setSensors(singletonList(dataInfo));
|
|
|
|
|
+ data.setData(singletonList(dataMap));
|
|
|
|
|
+ String json = data.toString();
|
|
|
|
|
+ return HttpResponse.newBuilder()
|
|
|
|
|
+ .status(OK).body(json).build();
|
|
|
|
|
+ }
|
|
|
|
|
+ return HttpResponse.newBuilder()
|
|
|
|
|
+ .status(SERVER_ERROR).build();
|
|
|
|
|
+ });
|
|
|
|
|
+ FieldClimateFetcher fetcher = new FieldClimateFetcher(config, authService, httpClient);
|
|
|
|
|
+ fetcher.init();
|
|
|
|
|
+
|
|
|
|
|
+ FieldClimateModel model1 = fetcher.fetch();
|
|
|
|
|
+ assertEquals(startDate, model1.getFrom());
|
|
|
|
|
+ assertEquals(startDate.plusHours(config.getPeriod()), model1.getTo());
|
|
|
|
|
+
|
|
|
|
|
+ FieldClimateModel model2 = fetcher.fetch();
|
|
|
|
|
+ assertEquals(startDate.plusHours(config.getPeriod()), model2.getFrom());
|
|
|
|
|
+ assertEquals(startDate.plusHours(2*config.getPeriod()), model2.getTo());
|
|
|
|
|
+
|
|
|
|
|
+ FieldClimateModel model3 = fetcher.fetch();
|
|
|
|
|
+ assertEquals(startDate.plusHours(2*config.getPeriod()), model3.getFrom());
|
|
|
|
|
+ assertEquals(startDate.plusHours(2*config.getPeriod()), model3.getTo());
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -380,15 +434,30 @@ class FieldClimateFetcherTest {
|
|
|
|
|
|
|
|
fetcher.init();
|
|
fetcher.init();
|
|
|
|
|
|
|
|
-// fetcher.fetch();
|
|
|
|
|
-// fetcher.fetch();
|
|
|
|
|
|
|
+ for (int i = 0; i < 10; i++) {
|
|
|
|
|
+ FieldClimateModel model = fetcher.fetch();
|
|
|
|
|
+
|
|
|
|
|
+ model.getStations().removeIf(s -> !s.getId().equals("0120821E"));
|
|
|
|
|
+ model.getStations().forEach(s -> s.getSensors().removeIf(se -> se.getCode() != 19969));
|
|
|
|
|
+
|
|
|
|
|
+ model.getStations().stream().peek(st -> System.out.println(format("%s %s-%s", st.getId(), model.getFrom(), model.getTo()))).forEach(st -> st.getSensors()
|
|
|
|
|
+ .forEach(se -> System.out.println(format("\t%s\t%s\t%s", se.getName(), se.getCode(), se.getCh()))));
|
|
|
|
|
+
|
|
|
|
|
+ SenslogV1Model sModel = new FieldClimateModelSenslogV1ModelConverter().convert(model);
|
|
|
|
|
+
|
|
|
|
|
+ System.out.println("\nObservation");
|
|
|
|
|
+ sModel.getObservations().stream().map(s -> (Observation)s).forEach(s -> System.out.println(format("\t%s\t%s", s.getUnitId(), s.getSensorId())));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
SenslogV1Model model = new FieldClimateModelSenslogV1ModelConverter().convert(fetcher.fetch());
|
|
SenslogV1Model model = new FieldClimateModelSenslogV1ModelConverter().convert(fetcher.fetch());
|
|
|
Observation obs = (Observation)model.getObservations().get(0);
|
|
Observation obs = (Observation)model.getObservations().get(0);
|
|
|
|
|
|
|
|
System.out.println(obs);
|
|
System.out.println(obs);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-*/
|
|
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
private void saveToCSV(FieldClimateModel model) throws IOException {
|
|
private void saveToCSV(FieldClimateModel model) throws IOException {
|
|
|
|
|
|