Search in sources :

Example 61 with Tool

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

the class DockerRegistryManagerTest method testLoadingImageTags.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadingImageTags() {
    DockerRegistry registry = generateRegistry();
    registryDao.createDockerRegistry(registry);
    ToolGroup group = generateToolGroup(registry);
    toolGroupDao.createToolGroup(group);
    Tool tool = generateTool(group);
    toolManager.create(tool, true);
    DockerClient mockClient = Mockito.mock(DockerClient.class);
    when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class), any())).thenReturn(mockClient);
    List<String> expected = Arrays.asList("TAG1", "TAG2");
    when(mockClient.getImageTags(ANOTHER_PATH, TEST_IMAGE)).thenReturn(expected);
    Assert.assertEquals(expected, dockerRegistryManager.loadImageTags(registry, tool));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with Tool

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

the class DockerRegistryManagerTest method testDelete.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testDelete() {
    TestUtils.configureDockerClientMock(Mockito.mock(DockerClient.class), dockerClientFactoryMock);
    DockerRegistry registry = generateRegistry();
    registryDao.createDockerRegistry(registry);
    ToolGroup group = generateToolGroup(registry);
    toolGroupDao.createToolGroup(group);
    Tool tool = generateTool(group);
    toolManager.create(tool, true);
    dockerRegistryManager.delete(registry.getId(), true);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with Tool

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

the class DockerRegistryManagerTest method testLoadingImageDescription.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadingImageDescription() {
    DockerRegistry registry = generateRegistry();
    Date date = new Date();
    registryDao.createDockerRegistry(registry);
    ToolGroup group = generateToolGroup(registry);
    toolGroupDao.createToolGroup(group);
    Tool tool = generateTool(group);
    toolManager.create(tool, true);
    DockerClient mockClient = Mockito.mock(DockerClient.class);
    when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class), any())).thenReturn(mockClient);
    ImageDescription expected = new ImageDescription(1L, TEST_IMAGE, TEST_TAG, date);
    when(mockClient.getImageDescription(registry, tool.getName(), TEST_TAG)).thenReturn(expected);
    Assert.assertEquals(expected, dockerRegistryManager.getImageDescription(registry, tool.getName(), TEST_TAG));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) ImageDescription(com.epam.pipeline.entity.docker.ImageDescription) Date(java.util.Date) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with Tool

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

the class ToolGroupEventServiceTest method shouldAddToolGroupEvent.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void shouldAddToolGroupEvent() {
    doNothing().when(entityManager).setManagers(anyListOf(SecuredEntityManager.class));
    Tool tool1 = new Tool();
    tool1.setId(1L);
    Tool tool2 = new Tool();
    tool2.setId(2L);
    when(issueManager.loadIssuesForEntity(any())).thenReturn(Arrays.asList(Issue.builder().id(1L).build(), Issue.builder().id(2L).build()));
    when(toolManager.loadToolsByGroup(anyLong())).thenReturn(Arrays.asList(tool1, tool2));
    doNothing().when(eventDao).insertUpdateEvent(anyString(), anyLong());
    toolGroupEventService.updateEventsWithChildrenAndIssues(1L);
    verify(eventDao).insertUpdateEvent("tool_group", 1L);
    verify(eventDao).insertUpdateEvent("tool", 1L);
    verify(eventDao).insertUpdateEvent("tool", 2L);
    // 1 toolGroup + 2 tool
    verify(eventDao, times(3)).insertUpdateEvent("issue", 1L);
    verify(eventDao, times(3)).insertUpdateEvent("issue", 2L);
    verifyNoMoreInteractions(eventDao);
}
Also used : SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) Tool(com.epam.pipeline.entity.pipeline.Tool) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with Tool

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

the class ToolApiServiceTest method testCreate.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER)
public void testCreate() {
    Tool tool = generateTool();
    tool.setToolGroupId(allowedGroup.getId());
    tool.setToolGroup(allowedGroup.getName());
    toolApiService.create(tool);
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) 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