|
78 | 78 | @Tag("integration") |
79 | 79 | final class TimeSeriesGroupControllerTestIT extends DataApiTestIT { |
80 | 80 |
|
81 | | - private List<TimeSeriesCategory> categoriesToCleanup = new ArrayList<>(); |
82 | | - private List<TimeSeriesGroup> groupsToCleanup = new ArrayList<>(); |
83 | | - private List<TimeSeries> timeSeriesToCleanup = new ArrayList<>(); |
| 81 | + private final List<TimeSeriesCategory> categoriesToCleanup = new ArrayList<>(); |
| 82 | + private final List<TimeSeriesGroup> groupsToCleanup = new ArrayList<>(); |
| 83 | + private final List<TimeSeries> timeSeriesToCleanup = new ArrayList<>(); |
84 | 84 | private static final FluentLogger LOGGER = FluentLogger.forEnclosingClass(); |
85 | 85 | TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL; |
86 | 86 | TestAccounts.KeyUser user2 = TestAccounts.KeyUser.SWT_NORMAL; |
@@ -1671,4 +1671,182 @@ void testRetrievalTiming() { |
1671 | 1671 | .body("assigned-time-series.size()", greaterThan(0)) |
1672 | 1672 | .time(lessThan(500L)); // should be pretty quick, under 0.5 seconds. Old query was ~3 seconds |
1673 | 1673 | } |
| 1674 | + |
| 1675 | + @ParameterizedTest |
| 1676 | + @ValueSource(strings = {Formats.JSON, Formats.DEFAULT}) |
| 1677 | + void test_create_read_delete_null_attributes(String format) throws Exception { |
| 1678 | + String officeId = user.getOperatingOffice(); |
| 1679 | + String timeSeriesId = "Alder Springs.Precip-Cumulative.Inst.1Day.0.cda-attr"; |
| 1680 | + createLocation(timeSeriesId.split("\\.")[0],true, officeId); |
| 1681 | + TimeSeriesCategory cat = new TimeSeriesCategory(officeId, "test_attr", "NullTesting"); |
| 1682 | + TimeSeriesGroup group = new TimeSeriesGroup(cat, officeId, "test_attr", "NullTesting", |
| 1683 | + null, null); |
| 1684 | + List<AssignedTimeSeries> assignedTimeSeries = group.getAssignedTimeSeries(); |
| 1685 | + |
| 1686 | + assignedTimeSeries.add(new AssignedTimeSeries(officeId,timeSeriesId, null, null, 0)); |
| 1687 | + ContentType contentType = Formats.parseHeader(Formats.JSON, TimeSeriesCategory.class); |
| 1688 | + String categoryXml = Formats.format(contentType, cat); |
| 1689 | + String groupXml = Formats.format(contentType, group); |
| 1690 | + |
| 1691 | + //Create Category |
| 1692 | + given() |
| 1693 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1694 | + .accept(format) |
| 1695 | + .contentType(Formats.JSON) |
| 1696 | + .body(categoryXml) |
| 1697 | + .header("Authorization", user.toHeaderValue()) |
| 1698 | + .queryParam(OFFICE, officeId) |
| 1699 | + .queryParam(FAIL_IF_EXISTS, false) |
| 1700 | + .when() |
| 1701 | + .redirects().follow(true) |
| 1702 | + .redirects().max(3) |
| 1703 | + .post("/timeseries/category") |
| 1704 | + .then() |
| 1705 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1706 | + .assertThat() |
| 1707 | + .statusCode(is(HttpServletResponse.SC_CREATED)); |
| 1708 | + |
| 1709 | + // insert the time series |
| 1710 | + createTimeseries(officeId, timeSeriesId, 0); |
| 1711 | + |
| 1712 | + //Create Group |
| 1713 | + given() |
| 1714 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1715 | + .accept(format) |
| 1716 | + .contentType(Formats.JSON) |
| 1717 | + .body(groupXml) |
| 1718 | + .header("Authorization", user.toHeaderValue()) |
| 1719 | + .queryParam(FAIL_IF_EXISTS, false) |
| 1720 | + .when() |
| 1721 | + .redirects().follow(true) |
| 1722 | + .redirects().max(3) |
| 1723 | + .post("/timeseries/group") |
| 1724 | + .then() |
| 1725 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1726 | + .assertThat() |
| 1727 | + .statusCode(is(HttpServletResponse.SC_CREATED)); |
| 1728 | + |
| 1729 | + //Read |
| 1730 | + var tsGroup = given() |
| 1731 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1732 | + .accept(format) |
| 1733 | + .contentType(Formats.JSON) |
| 1734 | + .queryParam(OFFICE, officeId) |
| 1735 | + .queryParam(CATEGORY_OFFICE_ID, officeId) |
| 1736 | + .queryParam(GROUP_OFFICE_ID, officeId) |
| 1737 | + .queryParam(CATEGORY_ID, group.getTimeSeriesCategory().getId()) |
| 1738 | + .when() |
| 1739 | + .redirects().follow(true) |
| 1740 | + .redirects().max(3) |
| 1741 | + .get("/timeseries/group/" + group.getId()) |
| 1742 | + .then() |
| 1743 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1744 | + .assertThat() |
| 1745 | + .statusCode(is(HttpServletResponse.SC_OK)) |
| 1746 | + .body("office-id", equalTo(group.getOfficeId())) |
| 1747 | + .body("id", equalTo(group.getId())) |
| 1748 | + .body("description", equalTo(group.getDescription())) |
| 1749 | + .body("assigned-time-series[0].timeseries-id", equalTo(timeSeriesId)) |
| 1750 | + .extract(); |
| 1751 | + |
| 1752 | + var body = tsGroup.body().jsonPath().getList("assigned-time-series"); |
| 1753 | + for (Object o : body) { |
| 1754 | + String content = o.toString(); |
| 1755 | + assertFalse(content.contains("ref-ts-id")); |
| 1756 | + assertFalse(content.contains("ts-code")); |
| 1757 | + assertFalse(content.contains("alias-id")); |
| 1758 | + assertFalse(content.contains("null")); |
| 1759 | + } |
| 1760 | + |
| 1761 | + //Clear Assigned TS |
| 1762 | + group.getAssignedTimeSeries().clear(); |
| 1763 | + groupXml = Formats.format(contentType, group); |
| 1764 | + given() |
| 1765 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1766 | + .accept(format) |
| 1767 | + .contentType(Formats.JSON) |
| 1768 | + .body(groupXml) |
| 1769 | + .header("Authorization", user.toHeaderValue()) |
| 1770 | + .queryParam(CATEGORY_ID, group.getTimeSeriesCategory().getId()) |
| 1771 | + .queryParam(REPLACE_ASSIGNED_TS, true) |
| 1772 | + .queryParam(OFFICE, group.getOfficeId()) |
| 1773 | + .when() |
| 1774 | + .redirects().follow(true) |
| 1775 | + .redirects().max(3) |
| 1776 | + .patch("/timeseries/group/"+ group.getId()) |
| 1777 | + .then() |
| 1778 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1779 | + .assertThat() |
| 1780 | + .statusCode(is(HttpServletResponse.SC_OK)); |
| 1781 | + |
| 1782 | + //Delete timeseries |
| 1783 | + given() |
| 1784 | + .log().ifValidationFails(LogDetail.ALL, true) |
| 1785 | + .accept(format) |
| 1786 | + .header("Authorization", user.toHeaderValue()) |
| 1787 | + .queryParam(OFFICE, officeId) |
| 1788 | + .queryParam(BEGIN, "2025-05-08T11:00:00+00:00") |
| 1789 | + .queryParam(END, "2025-05-19T11:00:00+00:00") |
| 1790 | + .queryParam("start-time-inclusive", "true") |
| 1791 | + .queryParam("end-time-inclusive", "true") |
| 1792 | + .queryParam("override-protection", "true") |
| 1793 | + .when() |
| 1794 | + .redirects().follow(true) |
| 1795 | + .redirects().max(3) |
| 1796 | + .delete("/timeseries/" + timeSeriesId) |
| 1797 | + .then() |
| 1798 | + .log().ifValidationFails(LogDetail.ALL, true) |
| 1799 | + .assertThat() |
| 1800 | + .statusCode(is(HttpServletResponse.SC_OK)); |
| 1801 | + |
| 1802 | + //Delete Group |
| 1803 | + given() |
| 1804 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1805 | + .accept(format) |
| 1806 | + .contentType(Formats.JSON) |
| 1807 | + .header("Authorization", user.toHeaderValue()) |
| 1808 | + .queryParam(OFFICE, officeId) |
| 1809 | + .queryParam(CATEGORY_ID, cat.getId()) |
| 1810 | + .when() |
| 1811 | + .redirects().follow(true) |
| 1812 | + .redirects().max(3) |
| 1813 | + .delete("/timeseries/group/" + group.getId()) |
| 1814 | + .then() |
| 1815 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1816 | + .assertThat() |
| 1817 | + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); |
| 1818 | + |
| 1819 | + //Read Empty |
| 1820 | + given() |
| 1821 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1822 | + .accept(format) |
| 1823 | + .contentType(Formats.JSON) |
| 1824 | + .queryParam(OFFICE, officeId) |
| 1825 | + .queryParam(GROUP_OFFICE_ID, officeId) |
| 1826 | + .queryParam(CATEGORY_OFFICE_ID, officeId) |
| 1827 | + .when() |
| 1828 | + .redirects().follow(true) |
| 1829 | + .redirects().max(3) |
| 1830 | + .get("/timeseries/group/" + group.getId()) |
| 1831 | + .then() |
| 1832 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1833 | + .assertThat() |
| 1834 | + .statusCode(is(HttpServletResponse.SC_NOT_FOUND)); |
| 1835 | + |
| 1836 | + //Delete Category |
| 1837 | + given() |
| 1838 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1839 | + .accept(format) |
| 1840 | + .contentType(Formats.JSON) |
| 1841 | + .header("Authorization", user.toHeaderValue()) |
| 1842 | + .queryParam(OFFICE, officeId) |
| 1843 | + .when() |
| 1844 | + .redirects().follow(true) |
| 1845 | + .redirects().max(3) |
| 1846 | + .delete("/timeseries/category/" + group.getTimeSeriesCategory().getId()) |
| 1847 | + .then() |
| 1848 | + .log().ifValidationFails(LogDetail.ALL,true) |
| 1849 | + .assertThat() |
| 1850 | + .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); |
| 1851 | + } |
1674 | 1852 | } |
0 commit comments