use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolDaoTest method setUp.
@Before
public void setUp() {
firstRegistry = new DockerRegistry();
firstRegistry.setPath(TEST_REPO);
firstRegistry.setOwner(TEST_USER);
registryDao.createDockerRegistry(firstRegistry);
library1 = new ToolGroup();
library1.setName(TOOL_GROUP_NAME);
library1.setRegistryId(firstRegistry.getId());
library1.setOwner(TEST_USER);
toolGroupDao.createToolGroup(library1);
secondRegistry = new DockerRegistry();
secondRegistry.setPath(TEST_REPO_2);
secondRegistry.setOwner(TEST_USER);
registryDao.createDockerRegistry(secondRegistry);
library2 = new ToolGroup();
library2.setName(TOOL_GROUP_NAME);
library2.setRegistryId(secondRegistry.getId());
library2.setOwner(TEST_USER);
toolGroupDao.createToolGroup(library2);
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolDaoTest method testSaveIcon.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testSaveIcon() throws IOException {
Tool tool = generateTool();
tool.setRegistryId(firstRegistry.getId());
tool.setToolGroupId(library1.getId());
toolDao.createTool(tool);
byte[] randomBytes = new byte[10];
new Random().nextBytes(randomBytes);
String testFileName = "test";
long iconId = toolDao.updateIcon(tool.getId(), testFileName, randomBytes);
Tool loaded = toolDao.loadTool(tool.getId());
Assert.assertTrue(loaded.isHasIcon());
Assert.assertEquals(iconId, loaded.getIconId().longValue());
List<DockerRegistry> registries = registryDao.loadAllRegistriesContent();
DockerRegistry registry = registries.stream().filter(r -> r.getId().equals(firstRegistry.getId())).findFirst().get();
ToolGroup group = registry.getGroups().stream().filter(g -> g.getId().equals(library1.getId())).findFirst().get();
loaded = group.getTools().stream().filter(t -> t.getId().equals(tool.getId())).findFirst().get();
Assert.assertTrue(loaded.isHasIcon());
Assert.assertEquals(iconId, loaded.getIconId().longValue());
Optional<Pair<String, InputStream>> loadedImage = toolDao.loadIcon(tool.getId());
Assert.assertEquals(testFileName, loadedImage.get().getLeft());
try (InputStream imageStream = loadedImage.get().getRight()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtils.copy(imageStream, os);
byte[] loadedBytes = os.toByteArray();
for (int i = 0; i < loadedBytes.length; i++) {
Assert.assertEquals(randomBytes[i], loadedBytes[i]);
}
}
// update again
new Random().nextBytes(randomBytes);
toolDao.updateIcon(tool.getId(), testFileName, randomBytes);
loaded = toolDao.loadTool(tool.getId());
Assert.assertTrue(loaded.isHasIcon());
toolDao.deleteToolIcon(tool.getId());
toolDao.deleteTool(tool.getId());
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolVersionDaoTest method setUp.
@Before
public void setUp() {
DockerRegistry dockerRegistry = new DockerRegistry();
dockerRegistry.setPath(TEST_REGISTRY_PATH);
dockerRegistry.setOwner(TEST_OWNER);
dockerRegistryDao.createDockerRegistry(dockerRegistry);
ToolGroup toolGroup = new ToolGroup();
toolGroup.setName(TEST_GROUP_NAME);
toolGroup.setRegistryId(dockerRegistry.getId());
toolGroup.setOwner(TEST_OWNER);
toolGroupDao.createToolGroup(toolGroup);
tool = new Tool();
tool.setImage(TEST_IMAGE);
tool.setCpu(TEST_CPU);
tool.setRam(TEST_RAM);
tool.setRegistryId(dockerRegistry.getId());
tool.setOwner(TEST_OWNER);
tool.setToolGroupId(toolGroup.getId());
toolDao.createTool(tool);
toolVersion1 = ToolVersion.builder().digest(TEST_DIGEST).size(TEST_SIZE).version(TEST_VERSION).modificationDate(TEST_LAST_MODIFIED_DATE).toolId(tool.getId()).build();
toolVersion2 = ToolVersion.builder().digest(TEST_DIGEST_2).size(TEST_SIZE).version(TEST_VERSION_2).modificationDate(TEST_LAST_MODIFIED_DATE).toolId(tool.getId()).build();
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryDaoTest method createDockerRegistry.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void createDockerRegistry() throws Exception {
DockerRegistry created = getDockerRegistry();
registryDao.createDockerRegistry(created);
DockerRegistry loaded = registryDao.loadDockerRegistry(created.getId());
Assert.assertEquals(created.getId(), loaded.getId());
Assert.assertEquals(created.getDescription(), loaded.getDescription());
Assert.assertEquals(created.getPath(), loaded.getPath());
ToolGroup library = createToolGroup(created);
toolGroupDao.createToolGroup(library);
Tool tool = createTool(TOOL_IMAGE, loaded.getId(), library);
toolDao.createTool(tool);
Tool tool2 = createTool(ANOTHER_TOOL_IMAGE, loaded.getId(), library);
toolDao.createTool(tool2);
loaded = registryDao.loadDockerRegistry(created.getId());
Assert.assertEquals(loaded.getTools().size(), EXPECTED_TOOLS_TOTAL_COUNT);
Tool loadedTool = loaded.getTools().get(0);
Tool loadedTool2 = loaded.getTools().get(1);
Assert.assertNotEquals(loadedTool.getImage(), loadedTool2.getImage());
Assert.assertEquals(loaded.getPath(), loadedTool.getRegistry());
Assert.assertEquals(loaded.getPath(), loadedTool2.getRegistry());
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryDaoTest method deleteDockerRegistryWithToolShouldThrowsException.
@Test(expected = DataIntegrityViolationException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void deleteDockerRegistryWithToolShouldThrowsException() throws Exception {
DockerRegistry created = getDockerRegistry();
registryDao.createDockerRegistry(created);
ToolGroup library = createToolGroup(created);
Tool tool = createTool(TOOL_IMAGE, created.getId(), library);
toolDao.createTool(tool);
registryDao.deleteDockerRegistry(created.getId());
}
Aggregations