private static PropertyDtoAssert assertThatDto(@Nullable PropertyDto dto) { return new PropertyDtoAssert(dto); }
public PropertyDtoAssert hasUserId(long expected) { isNotNull(); if (!Objects.equals(actual.getUserId(), expected)) { failWithMessage("Expected PropertyDto to have userId to be <%s> but was <%s>", true, actual.getUserId()); } return this; }
@Test public void selectProjectProperty() { insertProperty("project.one", "one", 10L, null); PropertyDto property = underTest.selectProjectProperty(10L, "project.one"); assertThatDto(property) .hasKey("project.one") .hasResourceId(10L) .hasNoUserId() .hasValue("one"); }
@Test @UseDataProvider("allValuesForSelect") public void selectGlobalProperties_supports_all_values(String dbValue, String expected) { insertProperty("global.one", dbValue, null, null); List<PropertyDto> dtos = underTest.selectGlobalProperties(); assertThat(dtos) .hasSize(1); assertThatDto(dtos.iterator().next()) .hasKey("global.one") .hasNoResourceId() .hasNoUserId() .hasValue(expected); }
@Test @UseDataProvider("allValuesForSelect") public void selectGlobalProperty_supports_all_values(String dbValue, String expected) { insertProperty("global.one", dbValue, null, null); assertThatDto(underTest.selectGlobalProperty("global.one")) .hasNoResourceId() .hasNoUserId() .hasValue(expected); }
@Test @UseDataProvider("allValuesForSelect") public void selectProjectProperties_supports_all_values(String dbValue, String expected) { ComponentDto projectDto = insertPrivateProject("A"); insertProperty("project.one", dbValue, projectDto.getId(), null); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos).hasSize(1); assertThatDto(dtos.iterator().next()) .hasKey("project.one") .hasResourceId(projectDto.getId()) .hasValue(expected); }
@Test public void selectGlobalProperties() { // global long id1 = insertProperty("global.one", "one", null, null); long id2 = insertProperty("global.two", "two", null, null); List<PropertyDto> properties = underTest.selectGlobalProperties(); assertThat(properties.size()) .isEqualTo(2); assertThatDto(findByKey(properties, "global.one")) .hasKey("global.one") .hasNoUserId() .hasNoResourceId() .hasValue("one"); assertThatDto(findByKey(properties, "global.two")) .hasKey("global.two") .hasNoResourceId() .hasNoUserId() .hasValue("two"); }
@Test public void selectGlobalProperty() { // global insertProperty("global.one", "one", null, null); insertProperty("global.two", "two", null, null); // project insertProperty("project.one", "one", 10L, null); // user insertProperty("user.one", "one", null, 100); assertThatDto(underTest.selectGlobalProperty("global.one")) .hasNoResourceId() .hasNoUserId() .hasValue("one"); assertThat(underTest.selectGlobalProperty("project.one")).isNull(); assertThat(underTest.selectGlobalProperty("user.one")).isNull(); assertThat(underTest.selectGlobalProperty("unexisting")).isNull(); }
@Test public void selectProjectProperties() { ComponentDto projectDto = insertPrivateProject("A"); long projectId = projectDto.getId(); // global insertProperty("global.one", "one", null, null); insertProperty("global.two", "two", null, null); // project insertProperty("project.one", "Pone", projectId, null); insertProperty("project.two", "Ptwo", projectId, null); List<PropertyDto> dtos = underTest.selectProjectProperties(projectDto.getDbKey()); assertThat(dtos) .hasSize(2); assertThatDto(findByKey(dtos, "project.one")) .hasKey("project.one") .hasResourceId(projectId) .hasValue("Pone"); assertThatDto(findByKey(dtos, "project.two")) .hasKey("project.two") .hasResourceId(projectId) .hasValue("Ptwo"); }
public PropertyDtoAssert hasResourceId(long expected) { isNotNull(); if (!Objects.equals(actual.getResourceId(), expected)) { failWithMessage("Expected PropertyDto to have resourceId to be <%s> but was <%s>", true, actual.getResourceId()); } return this; }
public PropertyDtoAssert hasNoUserId() { isNotNull(); if (actual.getUserId() != null) { failWithMessage("Expected PropertyDto to have userId to be null but was <%s>", actual.getUserId()); } return this; }
public PropertyDtoAssert hasNoResourceId() { isNotNull(); if (actual.getResourceId() != null) { failWithMessage("Expected PropertyDto to have resourceId to be null but was <%s>", actual.getResourceId()); } return this; }
public PropertyDtoAssert hasKey(String expected) { isNotNull(); if (!Objects.equals(actual.getKey(), expected)) { failWithMessage("Expected PropertyDto to have key to be <%s> but was <%s>", expected, actual.getKey()); } return this; }
public PropertyDtoAssert hasValue(String expected) { requireNonNull(expected); isNotNull(); if (!Objects.equals(actual.getValue(), expected)) { failWithMessage("Expected PropertyDto to have value to be <%s> but was <%s>", true, actual.getValue()); } return this; } }