-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding unit tests for ingestor & provider * On Docs : redirect test task to build
- Loading branch information
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
backend/src/test/java/ai/dragon/repository/IngestorRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package ai.dragon.repository; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.UUID; | ||
|
||
import org.dizitart.no2.repository.Cursor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import ai.dragon.entity.IngestorEntity; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
public class IngestorRepositoryTest { | ||
@Autowired | ||
private IngestorRepository ingestorRepository; | ||
|
||
@Test | ||
void insertIngestors() { | ||
ingestorRepository.deleteAll(); | ||
String ingestorName = "dRAGon Ingestor #1"; | ||
|
||
IngestorEntity ingestor = new IngestorEntity(); | ||
ingestor.setUuid(UUID.randomUUID()); | ||
ingestor.setName(ingestorName); | ||
ingestorRepository.save(ingestor); | ||
|
||
IngestorEntity retrievedIngestor = ingestorRepository.getByUuid(ingestor.getUuid()); | ||
assertNotNull(ingestorRepository.getByUuid(retrievedIngestor.getUuid())); | ||
assertEquals(ingestorName, retrievedIngestor.getName()); | ||
} | ||
|
||
@Test | ||
void findAllIngestors() { | ||
ingestorRepository.deleteAll(); | ||
int nbIngestorsToInsert = 3; | ||
|
||
for (int i = 0; i < nbIngestorsToInsert; i++) { | ||
ingestorRepository.save(new IngestorEntity()); | ||
} | ||
|
||
assertEquals(nbIngestorsToInsert, ingestorRepository.countAll()); | ||
|
||
ingestorRepository.find().forEach(ingestor -> { | ||
assertNotNull(ingestor.getUuid()); | ||
}); | ||
} | ||
|
||
@Test | ||
void findIngestorsByName() { | ||
ingestorRepository.deleteAll(); | ||
int nbIngestorsToInsert = 3; | ||
|
||
for (int i = 0; i < nbIngestorsToInsert; i++) { | ||
IngestorEntity ingestor = new IngestorEntity(); | ||
ingestor.setName(String.format("Ingestor %d", i)); | ||
ingestorRepository.save(ingestor); | ||
} | ||
|
||
assertEquals(nbIngestorsToInsert, ingestorRepository.countAll()); | ||
|
||
Cursor<IngestorEntity> cursor = ingestorRepository.findByFieldValue("name", "Ingestor 1"); | ||
assertEquals(1, cursor.size()); | ||
} | ||
|
||
@Test | ||
void deleteIngestors() { | ||
ingestorRepository.deleteAll(); | ||
int nbIngestorsToInsert = 3; | ||
|
||
for (int i = 0; i < nbIngestorsToInsert; i++) { | ||
ingestorRepository.save(new IngestorEntity()); | ||
} | ||
|
||
assertEquals(nbIngestorsToInsert, ingestorRepository.countAll()); | ||
|
||
ingestorRepository.find().forEach(ingestor -> { | ||
ingestorRepository.delete(ingestor.getUuid()); | ||
}); | ||
|
||
assertEquals(0, ingestorRepository.countAll()); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
backend/src/test/java/ai/dragon/repository/ProviderRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package ai.dragon.repository; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import java.util.UUID; | ||
|
||
import org.dizitart.no2.repository.Cursor; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import ai.dragon.entity.ProviderEntity; | ||
import ai.dragon.enumeration.ProviderType; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles("test") | ||
public class ProviderRepositoryTest { | ||
@Autowired | ||
private ProviderRepository providerRepository; | ||
|
||
@Test | ||
void insertProviders() { | ||
providerRepository.deleteAll(); | ||
String providerName = "dRAGon Provider #1"; | ||
|
||
ProviderEntity provider = new ProviderEntity(); | ||
provider.setUuid(UUID.randomUUID()); | ||
provider.setName(providerName); | ||
provider.setType(ProviderType.OPENAI); | ||
providerRepository.save(provider); | ||
|
||
ProviderEntity retrievedProvider = providerRepository.getByUuid(provider.getUuid()); | ||
assertNotNull(providerRepository.getByUuid(retrievedProvider.getUuid())); | ||
assertEquals(providerName, retrievedProvider.getName()); | ||
} | ||
|
||
@Test | ||
void findAllProviders() { | ||
providerRepository.deleteAll(); | ||
int nbProvidersToInsert = 3; | ||
|
||
for (int i = 0; i < nbProvidersToInsert; i++) { | ||
ProviderEntity provider = new ProviderEntity(); | ||
provider.setName(String.format("Provider %d", i)); | ||
provider.setType(ProviderType.OPENAI); | ||
providerRepository.save(provider); | ||
} | ||
|
||
assertEquals(nbProvidersToInsert, providerRepository.countAll()); | ||
|
||
providerRepository.find().forEach(provider -> { | ||
assertNotNull(provider.getUuid()); | ||
}); | ||
} | ||
|
||
@Test | ||
void findProvidersByName() { | ||
providerRepository.deleteAll(); | ||
int nbProvidersToInsert = 3; | ||
|
||
for (int i = 0; i < nbProvidersToInsert; i++) { | ||
ProviderEntity provider = new ProviderEntity(); | ||
provider.setName(String.format("Provider %d", i)); | ||
provider.setType(ProviderType.OPENAI); | ||
providerRepository.save(provider); | ||
} | ||
|
||
assertEquals(nbProvidersToInsert, providerRepository.countAll()); | ||
|
||
Cursor<ProviderEntity> cursor = providerRepository.findByFieldValue("name", "Provider 1"); | ||
assertEquals(1, cursor.size()); | ||
} | ||
|
||
@Test | ||
void deleteProviders() { | ||
providerRepository.deleteAll(); | ||
int nbProvidersToInsert = 3; | ||
|
||
for (int i = 0; i < nbProvidersToInsert; i++) { | ||
ProviderEntity provider = new ProviderEntity(); | ||
provider.setType(ProviderType.OPENAI); | ||
providerRepository.save(provider); | ||
} | ||
|
||
assertEquals(nbProvidersToInsert, providerRepository.countAll()); | ||
|
||
providerRepository.find().forEach(provider -> { | ||
providerRepository.delete(provider.getUuid()); | ||
}); | ||
|
||
assertEquals(0, providerRepository.countAll()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters