return checkFound(dbClient.qualityGateDao().selectByOrganizationAndName(dbSession, organization, name), "No quality gate has been found for name %s", name);
}
if (id != null) {
- return qualityGateFinder.getById(dbSession, id);
+ return qualityGateFinder.getByOrganizationAndId(dbSession, organization, id);
}
throw new IllegalArgumentException("No parameter has been set to identify a quality gate");
}
.setParam("organization", "Unknown")
.execute();
}
+
+ @Test
+ public void fail_when_quality_gate_belongs_to_another_organization() {
+ OrganizationDto organization = db.organizations().insert();
+ OrganizationDto otherOrganization = db.organizations().insert();
+ QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
+
+ expectedException.expect(NotFoundException.class);
+ expectedException.expectMessage(format("No quality gate has been found for name %s", qualityGate.getName()));
+
+ ws.newRequest()
+ .setParam("name", qualityGate.getName())
+ .setParam("organization", organization.getKey())
+ .execute();
+ }
+
+ @Test
+ public void fail_when_quality_gate_belongs_to_another_organization_using_id_parameter() {
+ OrganizationDto organization = db.organizations().insert();
+ OrganizationDto otherOrganization = db.organizations().insert();
+ QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(otherOrganization);
+
+ expectedException.expect(NotFoundException.class);
+ expectedException.expectMessage(format("No quality gate has been found for id %s in organization %s", qualityGate.getId(), organization.getName()));
+
+ ws.newRequest()
+ .setParam("id", qualityGate.getId().toString())
+ .setParam("organization", organization.getKey())
+ .execute();
+ }
}