Search in sources :

Example 31 with ToolGroup

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

Example 32 with ToolGroup

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());
}
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 33 with ToolGroup

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();
}
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 34 with ToolGroup

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());
}
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 35 with ToolGroup

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());
}
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

ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)53 Transactional (org.springframework.transaction.annotation.Transactional)27 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)25 Test (org.junit.Test)20 Tool (com.epam.pipeline.entity.pipeline.Tool)14 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)10 Before (org.junit.Before)10 AclPermission (com.epam.pipeline.security.acl.AclPermission)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Propagation (org.springframework.transaction.annotation.Propagation)6 DockerRegistryDao (com.epam.pipeline.dao.docker.DockerRegistryDao)4 AclTestDao (com.epam.pipeline.dao.util.AclTestDao)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 Optional (java.util.Optional)4 Assert (org.junit.Assert)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 ToolGroupDao (com.epam.pipeline.dao.tool.ToolGroupDao)3