@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 hasNotificationSubscribers() { int userId1 = db.users().insertUser(u -> u.setLogin("user1")).getId(); int userId2 = db.users().insertUser(u -> u.setLogin("user2")).getId(); Long projectId = insertPrivateProject("PROJECT_A").getId(); // global subscription insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userId2); // project subscription insertProperty("notification.DispatcherWithProjectSubscribers.Email", "true", projectId, userId1); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", 56L, userId1); insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", projectId, userId1); // global subscription insertProperty("notification.DispatcherWithGlobalAndProjectSubscribers.Email", "true", null, userId2); // Nobody is subscribed assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("NotSexyDispatcher"))) .isFalse(); // Global subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithGlobalSubscribers"))) .isTrue(); // Project subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithProjectSubscribers"))) .isTrue(); assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_B", singletonList("DispatcherWithProjectSubscribers"))) .isFalse(); // Global + Project subscribers assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_A", singletonList("DispatcherWithGlobalAndProjectSubscribers"))) .isTrue(); assertThat(underTest.hasProjectNotificationSubscribersForDispatchers("PROJECT_B", singletonList("DispatcherWithGlobalAndProjectSubscribers"))) .isTrue(); }
@Test public void select_global_properties_by_keys() { insertPrivateProject("A"); int userId = db.users().insertUser(u -> u.setLogin("B")).getId(); String key = "key"; String anotherKey = "anotherKey"; insertProperty(key, "value", null, null); insertProperty(key, "value", 10L, null); insertProperty(key, "value", null, userId); insertProperty(anotherKey, "value", null, null); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key))) .extracting("key") .containsOnly(key); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key, anotherKey))) .extracting("key") .containsOnly(key, anotherKey); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet(key, anotherKey, "unknown"))) .extracting("key") .containsOnly(key, anotherKey); assertThat(underTest.selectGlobalPropertiesByKeys(session, newHashSet("unknown"))) .isEmpty(); }
@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"); }
@Test public void shouldFindUsersForNotification() { ComponentDto project1 = insertPrivateProject("uuid_45"); ComponentDto project2 = insertPrivateProject("uuid_56"); UserDto user1 = db.users().insertUser(u -> u.setLogin("user1")); UserDto user2 = db.users().insertUser(u -> u.setLogin("user2"));
@Test public void delete_project_property() { long projectId1 = insertPrivateProject("A").getId(); long projectId2 = insertPrivateProject("B").getId(); long projectId3 = insertPrivateProject("C").getId(); long id1 = insertProperty("global.one", "one", null, null); long id2 = insertProperty("global.two", "two", null, null);