Search in sources :

Example 56 with Tool

use of com.epam.pipeline.entity.pipeline.Tool 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());
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IssueVO(com.epam.pipeline.controller.vo.IssueVO) Autowired(org.springframework.beans.factory.annotation.Autowired) Random(java.util.Random) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Pair(org.apache.commons.lang3.tuple.Pair) Propagation(org.springframework.transaction.annotation.Propagation) ToolWithIssuesCount(com.epam.pipeline.entity.pipeline.ToolWithIssuesCount) IssueManager(com.epam.pipeline.manager.issue.IssueManager) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) DockerRegistryDao(com.epam.pipeline.dao.docker.DockerRegistryDao) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) IOUtils(org.apache.commons.io.IOUtils) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Tool(com.epam.pipeline.entity.pipeline.Tool) List(java.util.List) Optional(java.util.Optional) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) AuthManager(com.epam.pipeline.manager.security.AuthManager) Assert(org.junit.Assert) EntityVO(com.epam.pipeline.controller.vo.EntityVO) InputStream(java.io.InputStream) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Random(java.util.Random) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) Pair(org.apache.commons.lang3.tuple.Pair) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 57 with Tool

use of com.epam.pipeline.entity.pipeline.Tool 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();
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) Before(org.junit.Before)

Example 58 with Tool

use of com.epam.pipeline.entity.pipeline.Tool 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());
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 59 with Tool

use of com.epam.pipeline.entity.pipeline.Tool 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());
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class DockerRegistryDaoTest method deleteDockerRegistryAfterDeletingToolShouldNotThrowsException.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void deleteDockerRegistryAfterDeletingToolShouldNotThrowsException() throws Exception {
    DockerRegistry created = getDockerRegistry();
    registryDao.createDockerRegistry(created);
    ToolGroup library = createToolGroup(created);
    toolGroupDao.createToolGroup(library);
    Tool tool = createTool(TOOL_IMAGE, created.getId(), library);
    toolDao.createTool(tool);
    toolDao.deleteTool(tool.getId());
    toolGroupDao.deleteToolGroup(library.getId());
    registryDao.deleteDockerRegistry(created.getId());
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Tool (com.epam.pipeline.entity.pipeline.Tool)72 Transactional (org.springframework.transaction.annotation.Transactional)28 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)24 Test (org.junit.Test)22 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)14 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 DockerClient (com.epam.pipeline.manager.docker.DockerClient)9 List (java.util.List)9 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)8 MessageHelper (com.epam.pipeline.common.MessageHelper)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)7 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)7 ToolScanExternalServiceException (com.epam.pipeline.exception.ToolScanExternalServiceException)7 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)7 Optional (java.util.Optional)7 MessageConstants (com.epam.pipeline.common.MessageConstants)6 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)6 ToolScanStatus (com.epam.pipeline.entity.pipeline.ToolScanStatus)6 DockerClientFactory (com.epam.pipeline.manager.docker.DockerClientFactory)6