Skip to content

Commit

Permalink
TestSuitesSource storage
Browse files Browse the repository at this point in the history
### What's done:
- added storage for TestSuitesSource snapshots
- refactored discovering tests and test suites
- added GIT cloning with new run
  • Loading branch information
nulls committed Jul 22, 2022
1 parent a4378e5 commit b440965
Show file tree
Hide file tree
Showing 41 changed files with 1,420 additions and 379 deletions.
1 change: 1 addition & 0 deletions db/v-2/tables/db.changelog-tables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<include file="git.xml" relativeToChangelogFile="true"/>
<include file="agent-status.xml" relativeToChangelogFile="true"/>
<include file="project-privacy.xml" relativeToChangelogFile="true"/>
<include file="test_suites_source.xml" relativeToChangelogFile="true"/>
<include file="test_suite.xml" relativeToChangelogFile="true"/>
<include file="test_execution.xml" relativeToChangelogFile="true"/>
<include file="execution.xml" relativeToChangelogFile="true"/>
Expand Down
8 changes: 8 additions & 0 deletions db/v-2/tables/git.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@
<addUniqueConstraint tableName="git" columnNames="project_id" constraintName="uq_project_id"/>
</changeSet>

<changeSet id="add-sub-directory" author="nulls">
<addColumn tableName="git" >
<column name="sub_directory" type="varchar(255)" defaultValue="">
<constraints nullable="false"/>
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
22 changes: 22 additions & 0 deletions db/v-2/tables/test_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@
</addColumn>
</changeSet>

<changeSet id="add-test-suites-source" author="nulls">
<delete tableName="test_execution" />
<delete tableName="test" />
<delete tableName="test_suite" />
<dropForeignKeyConstraint baseTableName="test_suite" constraintName="fk_test_suite_project" />
<dropColumn tableName="test_suite">
<column name="type"/>
<column name="project_id"/>
<column name="test_root_path"/>
<column name="test_suite_repo_url"/>
</dropColumn>
<addColumn tableName="test_suite">
<column name="source_id" type="bigint">
<constraints foreignKeyName="fk_test_suite_source" references="test_suites_source(id)"/>
</column>
<column name="version" type="varchar(100)">
<constraints nullable="false"/>
</column>
</addColumn>
<addUniqueConstraint tableName="test_suite" columnNames="source_id,version"/>
</changeSet>

</databaseChangeLog>
31 changes: 31 additions & 0 deletions db/v-2/tables/test_suites_source.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

<changeSet id="create-test-suites-source-table" author="nulls">
<createTable tableName="test_suites_source">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="organization_id" type="bigint">
<constraints foreignKeyName="fk_lnk_test_suites_source_organization" references="organization(id)" nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="description" type="text"/>
<column name="type" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="additional_info" type="varchar(255)">
<constraints nullable="false"/>
</column>
</createTable>

<addUniqueConstraint tableName="test_suites_source" columnNames="organization_id,name" constraintName="test_suites_source_name"/>
<addUniqueConstraint tableName="test_suites_source" columnNames="type,additional_info" constraintName="test_suites_source_additional_info"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ class TestSuitesController(
)
}

/**
* @param testSuiteDtos suites, which need to be marked as obsolete
* @return response entity
*/
@PostMapping("/internal/markObsoleteTestSuites")
@Transactional
fun markObsoleteTestSuites(@RequestBody testSuiteDtos: List<TestSuiteDto>) =
ResponseEntity.status(HttpStatus.OK).body(testSuitesService.markObsoleteTestSuites(testSuiteDtos))

/**
* @param testSuiteDtos suites, which need to be deleted
* @return response entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ interface GitRepository : BaseEntityRepository<Git> {
* @return git by project
*/
fun findByProjectId(projectId: Long): Git?

/**
* @param url
* @return all [Git] entities by [Git.url]
*/
fun findAllByUrl(url: String): List<Git>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saveourtool.save.backend.repository

import com.saveourtool.save.entities.TestSuite
import com.saveourtool.save.entities.TestSuitesSource
import com.saveourtool.save.testsuite.TestSuiteType
import org.springframework.data.repository.query.QueryByExampleExecutor
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -42,4 +43,35 @@ interface TestSuiteRepository : BaseEntityRepository<TestSuite>, QueryByExampleE
testRootPath: String,
testSuiteRepoUrl: String?,
): TestSuite

/**
* @param name name of the test suite
* @param source source of the test suite
* @param version version of snapshot of source
* @return matched test suite
*/
fun findByNameAndSourceAndVersion(
name: String,
source: TestSuitesSource,
version: String
): TestSuite?

/**
* @param source source of the test suite
* @param version version of snapshot of source
* @return matched test suites
*/
fun findAllBySourceAndVersion(
source: TestSuitesSource,
version: String
): List<TestSuite>


/**
* @param source source of the test suite
* @return matched test suites
*/
fun findAllBySource(
source: TestSuitesSource,
): List<TestSuite>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.saveourtool.save.backend.repository

import com.saveourtool.save.entities.TestSuitesSource
import com.saveourtool.save.testsuite.TestSuitesSourceType
import org.springframework.stereotype.Repository

/**
* Repository of [TestSuitesSource]
*/
@Repository
interface TestSuitesSourceRepository : BaseEntityRepository<TestSuitesSource> {
/**
* @param organizationId
* @param name
* @return found entity or null
*/
fun findByOrganizationIdAndName(organizationId: Long, name: String): TestSuitesSource?

/**
* @param type
* @param additionalInfo
* @return found entity or null
*/
fun findByTypeAndAdditionalInfo(type: TestSuitesSourceType, additionalInfo: String): TestSuitesSource?
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package com.saveourtool.save.backend.service

import com.saveourtool.save.backend.repository.GitRepository
import com.saveourtool.save.backend.utils.justOrNotFound
import com.saveourtool.save.backend.utils.switchToNotFoundIfEmpty
import com.saveourtool.save.entities.Git
import com.saveourtool.save.entities.GitDto
import com.saveourtool.save.entities.Project
import org.springframework.data.repository.findByIdOrNull
import org.springframework.http.HttpStatus
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.server.ResponseStatusException
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

/**
* Service of git
*/
@Service
@RestController
class GitService(private val gitRepository: GitRepository) {
/**
* @param project
Expand Down Expand Up @@ -37,4 +48,48 @@ class GitService(private val gitRepository: GitRepository) {
* @return git by project id if exists
*/
fun findByProjectId(projectId: Long) = gitRepository.findByProjectId(projectId)

@GetMapping("/internal/git")
fun getById(@RequestParam id: Long): Mono<GitDto> = Mono.justOrEmpty(gitRepository.findByIdOrNull(id))
.map { it.toDto() }
.switchToNotFoundIfEmpty {
"Git entity not found by id $id"
}

fun findByUrlSubDirectoryAndBranchOrCopy(
url: String,
subDirectory: String,
branch: String,
): Mono<Git> {
val gits = gitRepository.findAllByUrl(url)
return if (gits.isEmpty()) {
Mono.error(
ResponseStatusException(
HttpStatus.NOT_FOUND,
"There is no registered Git configuration for url: $url"
)
)
} else {
Mono.fromCallable {
gits.find { it.subDirectory == subDirectory && it.branch == branch }
?: gits.first()
.createCopy(
subDirectory = subDirectory,
branch = branch,
)
}
}
}

private fun Git.createCopy(subDirectory: String, branch: String): Git {
return saveGit(
toDto().copy(
branch = branch,
subDirectory = subDirectory
),
project.requiredId()
)
}

fun findAllByUrl(url: String): List<Git> = gitRepository.findAllByUrl(url)
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.saveourtool.save.backend.service

import com.saveourtool.save.backend.repository.OrganizationRepository
import com.saveourtool.save.backend.utils.switchToNotFoundIfEmpty
import com.saveourtool.save.domain.OrganizationSaveStatus
import com.saveourtool.save.entities.Organization
import com.saveourtool.save.entities.OrganizationStatus
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

/**
* Service for organization
*
* @property organizationRepository
*/
@Service
@RestController
class OrganizationService(
private val organizationRepository: OrganizationRepository,
) {
Expand Down Expand Up @@ -58,6 +64,11 @@ class OrganizationService(
*/
fun findByName(name: String) = organizationRepository.findByName(name)

@GetMapping("/internal/organization/{name}")
fun getByName(@PathVariable name: String): Mono<Organization> = Mono.justOrEmpty(findByName(name)).switchToNotFoundIfEmpty {
"Organization not found by name $name"
}

/**
* @param organization
* @return organization
Expand Down
Loading

0 comments on commit b440965

Please sign in to comment.