Skip to content

Commit

Permalink
fix gatling tests
Browse files Browse the repository at this point in the history
project: organization was not provided as valid json
Sourcetype: catalogversion was incorrectly set during save
subject: incomplete projectDTO was provided (no name). this could be resolved by looking up the name if an id is provided.
  • Loading branch information
Bdegraaf1234 committed Nov 6, 2023
1 parent 74e6b3c commit 86f4c45
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/gatling/scala/ProjectGatlingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProjectGatlingTest extends ManagementPortalSimulation {
.exec(http("Create new project")
.post("/api/projects")
.headers(headers_http_authenticated)
.body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organization":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJson
.body(StringBody("""{"id":null, "projectName":"PROJECT-${randstring}", "description":"SAMPLE_TEXT", "organizationName":"SAMPLE_TEXT", "location":"SAMPLE_TEXT", "startDate":"2020-01-01T00:00:00.000Z", "projectStatus":null, "endDate":"2020-01-01T00:00:00.000Z", "projectAdmin":null}""")).asJson
.check(status.is(201))
.check(headerRegex("Location", "(.*)").saveAs("new_project_url"))).exitHereIfFailed
.pause(5)
Expand Down
3 changes: 2 additions & 1 deletion src/gatling/scala/SubjectGatlingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SubjectGatlingTest extends ManagementPortalSimulation {
.get("/api/projects")
.headers(headers_http_authenticated)
.check(status.is(200))
.check(jsonPath("$[0].projectName").saveAs("project_name"))
.check(jsonPath("$[0].id").saveAs("project_id"))).exitHereIfFailed
.repeat(2) {
exec(http("Get all subjects")
Expand All @@ -49,7 +50,7 @@ class SubjectGatlingTest extends ManagementPortalSimulation {
.exec(http("Create new subject")
.post("/api/subjects")
.headers(headers_http_authenticated)
.body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "enternalId":"${randstring}", "project": {"id": "${project_id}"}}""")).asJson
.body(StringBody("""{"id":null, "externalLink":"SAMPLE_TEXT", "externalId":"${randstring}", "project": {"id": "${project_id}", "projectName": "${project_name}"}}""")).asJson
.check(status.is(201))
.check(headerRegex("Location", "(.*)").saveAs("new_subject_url"))).exitHereIfFailed
.pause(5)
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/radarbase/management/service/ProjectService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import java.util.*
*/
@Service
@Transactional
open class ProjectService(
class ProjectService(
@Autowired private val projectRepository: ProjectRepository,
@Autowired private val projectMapper: ProjectMapper,
@Autowired private val sourceTypeMapper: SourceTypeMapper,
Expand All @@ -50,7 +50,7 @@ open class ProjectService(
* @return the list of entities
*/
@Transactional(readOnly = true)
open fun findAll(fetchMinimal: Boolean, pageable: Pageable): Page<*> {
fun findAll(fetchMinimal: Boolean, pageable: Pageable): Page<*> {
val projects: Page<Project>
val referents = authService.referentsByScope(Permission.PROJECT_READ)
projects = if (referents.isEmpty()) {
Expand All @@ -76,7 +76,7 @@ open class ProjectService(
* @return the entity
*/
@Transactional(readOnly = true)
open fun findOne(id: Long): ProjectDTO? {
fun findOne(id: Long): ProjectDTO? {
log.debug("Request to get Project : {}", id)
val project = projectRepository.findOneWithEagerRelationships(id)
?: throw NotFoundException(
Expand All @@ -96,7 +96,7 @@ open class ProjectService(
* @return the entity
*/
@Transactional(readOnly = true)
open fun findOneByName(name: String): ProjectDTO {
fun findOneByName(name: String): ProjectDTO {
log.debug("Request to get Project by name: {}", name)
val project = projectRepository.findOneWithEagerRelationshipsByName(name)
?: throw NotFoundException(
Expand All @@ -115,10 +115,10 @@ open class ProjectService(
* @return the list of source-types assigned.
*/
@Transactional(readOnly = true)
open fun findSourceTypesByProjectId(id: Long): List<SourceTypeDTO> {
fun findSourceTypesByProjectId(id: Long): List<SourceTypeDTO> {
log.debug("Request to get Project.sourceTypes of project: {}", id)
val sourceTypes = projectRepository.findSourceTypesByProjectId(id)
return sourceTypeMapper.sourceTypesToSourceTypeDTOs(sourceTypes).filterNotNull()
return sourceTypeMapper.sourceTypesToSourceTypeDTOs(sourceTypes)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object ResourceUriService {
return URI(
HeaderUtil.buildPath(
"api", "source-types", resource.producer,
resource.model, resource.model
resource.model, resource.catalogVersion
)
)
}
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/org/radarbase/management/service/SourceTypeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import javax.validation.constraints.NotNull
*/
@Service
@Transactional
open class SourceTypeService(
class SourceTypeService(
@Autowired private val sourceTypeRepository: SourceTypeRepository,
@Autowired private val sourceTypeMapper: SourceTypeMapper,
@Autowired private val sourceDataRepository: SourceDataRepository,
Expand Down Expand Up @@ -61,7 +61,7 @@ open class SourceTypeService(
* @return the list of entities
*/
@Transactional(readOnly = true)
open fun findAll(): List<SourceTypeDTO> {
fun findAll(): List<SourceTypeDTO> {
log.debug("Request to get all SourceTypes")
val result = sourceTypeRepository.findAllWithEagerRelationships()
return result
Expand Down Expand Up @@ -95,23 +95,33 @@ open class SourceTypeService(
* Fetch SourceType by producer and model.
*/
fun findByProducerAndModelAndVersion(
@NotNull producer: String,
@NotNull model: String, @NotNull version: String
@NotNull producer: String?,
@NotNull model: String?, @NotNull version: String?
): SourceTypeDTO {
log.debug(
"Request to get SourceType by producer and model and version: {}, {}, {}",
producer, model, version
)
return sourceTypeRepository
.findOneWithEagerRelationshipsByProducerAndModelAndVersion(producer, model, version)
.let { sourceType: SourceType? -> sourceType?.let { sourceTypeMapper.sourceTypeToSourceTypeDTO(it) } }
?: throw NotFoundException(
"SourceType not found with producer, model, " + "version ", EntityName.Companion.SOURCE_TYPE,
ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap<String, String?>(
if (producer == null || model == null || version == null) {
throw NotFoundException(
"SourceType not found with producer, model, " + "version ", EntityName.SOURCE_TYPE,
ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap(
"producer-model-version",
"$producer-$model-$version"
)
)
}
val result =
sourceTypeRepository.findOneWithEagerRelationshipsByProducerAndModelAndVersion(producer, model, version)
?: throw NotFoundException(
"SourceType not found with producer, model, " + "version ", EntityName.SOURCE_TYPE,
ErrorConstants.ERR_SOURCE_TYPE_NOT_FOUND, Collections.singletonMap(
"producer-model-version",
"$producer-$model-$version"
)
)

return sourceTypeMapper.sourceTypeToSourceTypeDTO(result)
}

/**
Expand Down Expand Up @@ -159,7 +169,7 @@ open class SourceTypeService(
* @param catalogSourceTypes list of source-type from catalogue-server.
*/
@Transactional
open fun saveSourceTypesFromCatalogServer(catalogSourceTypes: List<CatalogSourceType>) {
fun saveSourceTypesFromCatalogServer(catalogSourceTypes: List<CatalogSourceType>) {
for (catalogSourceType in catalogSourceTypes) {
var sourceType = catalogSourceTypeMapper
.catalogSourceTypeToSourceType(catalogSourceType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ class ProjectResource(
@Throws(URISyntaxException::class, NotAuthorizedException::class)
fun createProject(@RequestBody @Valid projectDto: ProjectDTO?): ResponseEntity<ProjectDTO> {
log.debug("REST request to save Project : {}", projectDto)
val org = projectDto?.organization
if (org?.name == null) {
val org = projectDto?.organizationName
if (org == null) {
throw BadRequestException(
"Organization must be provided",
ENTITY_NAME, ErrorConstants.ERR_VALIDATION
)
}
authService.checkPermission(
Permission.PROJECT_CREATE,
{ e: EntityDetails -> e.organization(org.name) })
{ e: EntityDetails -> e.organization(org) })
if (projectDto.id != null) {
return ResponseEntity.badRequest()
.headers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class SourceTypeResource(
producer, model,
version
)
if (!projects.isEmpty()) {
if (projects.isNotEmpty()) {
throw InvalidRequestException( // we know the list is not empty so calling get() is safe here
"Cannot delete a source-type that " + "is being used by project(s)", EntityName.SOURCE_TYPE,
ErrorConstants.ERR_SOURCE_TYPE_IN_USE, Collections.singletonMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class SubjectResource(
.body(result)
}


private fun getProjectName(subjectDto: SubjectDTO): String {
// not ideal, because only name is needed. however, id is checked to verify the project is in the database
// this does prevent calls to the database?
if (subjectDto.project == null || subjectDto.project!!.id == null || subjectDto.project!!.projectName == null) {
throw BadRequestException(
"A subject should be assigned to a project", EntityName.SUBJECT,
Expand Down Expand Up @@ -215,7 +218,7 @@ class SubjectResource(
listOf(
subjectMapper.subjectToSubjectReducedProjectDTO(s)
)
});
})
ResponseUtil.wrapOrNotFound(subject)
} else if (projectName == null && externalId != null) {
val page = subjectService.findAll(subjectCriteria)
Expand Down

0 comments on commit 86f4c45

Please sign in to comment.