@Test public void does_not_assign_issue_when_assignee_is_not_member_of_project_issue_organization() { OrganizationDto otherOrganizationDto = db.organizations().insert(); UserDto assignee = db.users().insertUser("john"); // User is not member of the organization of the issue db.organizations().addMember(otherOrganizationDto, assignee); Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "john")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isFalse(); }
@Before public void setup() throws Exception { now = DATE_FORMAT.parse("2015-06-02"); when(system2.now()).thenReturn(now.getTime()); db.organizations().insertForUuid(ORGANIZATION_UUID); branchPersister = mock(BranchPersister.class); underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister); }
@Test public void change_project_visibility_to_public() { dbTester.organizations().setNewProjectPrivate(dbTester.getDefaultOrganization(), true); userSession.logIn().setSystemAdministrator(); wsTester.newRequest() .setParam(PARAM_PROJECT_VISIBILITY, "public") .execute(); assertThat(dbTester.organizations().getNewProjectPrivate(dbTester.getDefaultOrganization())).isFalse(); }
private UserDto insertUser(OrganizationDto... organizations) { UserDto user = db.users().insertUser(); stream(organizations).forEach(organization -> db.organizations().addMember(organization, user)); return user; }
@Test public void createForUser_fails_with_ISE_if_organization_with_slug_of_login_already_exists() { UserDto user = db.users().insertUser(A_LOGIN); when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN); db.organizations().insertForKey(SLUG_OF_A_LOGIN); enableCreatePersonalOrg(true); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't create organization with key '" + SLUG_OF_A_LOGIN + "' " + "because an organization with this key already exists"); underTest.createForUser(dbSession, user); }
private DbTester(System2 system2, @Nullable String schemaPath, MyBatisConfExtension... confExtensions) { super(TestDb.create(schemaPath, confExtensions)); this.system2 = system2; initDbClient(); this.userTester = new UserDbTester(this); this.componentTester = new ComponentDbTester(this); this.componentLinkTester = new ProjectLinkDbTester(this); this.favoriteTester = new FavoriteDbTester(this); this.eventTester = new EventDbTester(this); this.organizationTester = new OrganizationDbTester(this); this.permissionTemplateTester = new PermissionTemplateDbTester(this); this.propertyTester = new PropertyDbTester(this); this.qualityGateDbTester = new QualityGateDbTester(this); this.issueDbTester = new IssueDbTester(this); this.ruleDbTester = new RuleDbTester(this); this.notificationDbTester = new NotificationDbTester(this); this.rootFlagAssertions = new RootFlagAssertions(this); this.qualityProfileDbTester = new QualityProfileDbTester(this); this.measureDbTester = new MeasureDbTester(this); this.fileSourceTester = new FileSourceTester(this); this.pluginDbTester = new PluginDbTester(this); this.webhookDbTester = new WebhookDbTester(this); this.webhookDeliveryDbTester = new WebhookDeliveryDbTester(this); this.almDbTester = new AlmDbTester(this); }
private OrganizationDto insertOrganization(long createdAt) { when(system2.now()).thenReturn(createdAt); OrganizationDto dto = dbTester.organizations().insert(); dbTester.commit(); return dto; }
@Test public void assign_issue() { UserDto assignee = db.users().insertUser("john"); db.organizations().addMember(issueOrganizationDto, assignee); Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "john")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isEqualTo(assignee.getUuid()); }
private ComponentDto initJsonExampleComponents() throws IOException { OrganizationDto organizationDto = db.organizations().insertForKey("my-org-1"); ComponentDto project = newPrivateProjectDto(organizationDto, "MY_PROJECT_ID") .setDbKey("MY_PROJECT_KEY") .setName("Project Name"); db.components().insertProjectAndSnapshot(project); Date now = new Date(); JsonParser jsonParser = new JsonParser(); JsonElement jsonTree = jsonParser.parse(IOUtils.toString(getClass().getResource("tree-example.json"), UTF_8)); JsonArray components = jsonTree.getAsJsonObject().getAsJsonArray("components"); for (JsonElement componentAsJsonElement : components) { JsonObject componentAsJsonObject = componentAsJsonElement.getAsJsonObject(); String uuid = getJsonField(componentAsJsonObject, "id"); db.components().insertComponent(newChildComponent(uuid, project, project) .setDbKey(getJsonField(componentAsJsonObject, "key")) .setName(getJsonField(componentAsJsonObject, "name")) .setLanguage(getJsonField(componentAsJsonObject, "language")) .setPath(getJsonField(componentAsJsonObject, "path")) .setQualifier(getJsonField(componentAsJsonObject, "qualifier")) .setDescription(getJsonField(componentAsJsonObject, "description")) .setEnabled(true) .setCreatedAt(now)); } db.commit(); return project; }
@Before public void setUp() { organization = db.organizations().insert(); project = db.components().insertPrivateProject(organization); user = db.users().insertUser(); db.organizations().addMember(organization, user); UserDto adminUser = db.users().insertAdminByUserPermission(organization); db.organizations().addMember(organization, adminUser); userIndexer.indexOnStartup(new HashSet<>()); }
@Test public void fail_to_update_personal_organization_when_new_key_already_exist() { OrganizationDto organization = db.organizations().insert(); db.organizations().insert(o -> o.setKey("new_login")); when(organizationValidation.generateKeyFrom("new_login")).thenReturn("new_login"); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Can't create organization with key 'new_login' because an organization with this key already exists"); underTest.updateOrganizationKey(dbSession, organization, "new_login"); }
@Test public void set_default_assignee() { settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik"); UserDto userDto = db.users().insertUser("erik"); db.organizations().addMember(organizationDto, userDto); assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid()); }
@Before public void before() { when(system.now()).thenReturn(UtcDateUtils.parseDateTime("2014-01-20T12:00:00+0000").getTime()); organization = db.organizations().insertForUuid("QualityProfileDaoTest-ORG"); }
@Test public void create_fails_with_KeyConflictException_if_org_with_key_in_NewOrganization_arg_already_exists_in_db() throws OrganizationUpdater.KeyConflictException { db.organizations().insertForKey(FULL_POPULATED_NEW_ORGANIZATION.getKey()); UserDto user = db.users().insertUser(); expectedException.expect(OrganizationUpdater.KeyConflictException.class); expectedException.expectMessage("Organization key '" + FULL_POPULATED_NEW_ORGANIZATION.getKey() + "' is already used"); underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION, EMPTY_ORGANIZATION_CONSUMER); }
@Before public void setUp() { organization = db.organizations().insert(); resourceTypes.setAllQualifiers(SUGGESTION_QUALIFIERS); }
private UserDto insertUser(String login) { UserDto user = db.users().insertUser(login); db.organizations().addMember(db.getDefaultOrganization(), user); return user; }
@Before public void setup() throws Exception { now = DATE_FORMAT.parse("2015-06-02"); when(system2.now()).thenReturn(now.getTime()); dbTester.organizations().insertForUuid(ORGANIZATION_UUID); analysisMetadataHolder.setBranch(new DefaultBranchImpl()); BranchPersister branchPersister = mock(BranchPersister.class); underTest = new PersistComponentsStep(dbClient, treeRootHolder, dbIdsRepository, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister); }
@Test public void json_example() { OrganizationDto organization1 = db.organizations().insertForKey("my-org"); OrganizationDto organization2 = db.organizations().insertForKey("openjdk"); addComponent(ComponentTesting.newPrivateProjectDto(organization1).setDbKey("K1").setName("Samba")); addComponent(ComponentTesting.newPrivateProjectDto(organization1).setDbKey("K2").setName("Apache HBase")); addComponent(ComponentTesting.newPrivateProjectDto(organization2).setDbKey("K3").setName("JDK9")); String result = ws.newRequest().execute().getInput(); assertJson(result).isSimilarTo(ws.getDef().responseExampleAsString()); }