Search in sources :

Example 66 with Tool

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

the class PipelineVersionManagerTest method mockToolManager.

private void mockToolManager() {
    Mockito.when(toolManager.loadTool(Mockito.anyString(), Mockito.anyString())).then(invocation -> {
        Tool tool = new Tool();
        tool.setRegistry(TEST_REPOSITORY);
        tool.setImage((String) invocation.getArguments()[0]);
        return tool;
    });
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 67 with Tool

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

the class PipelineVersionManagerTest method testDockerImageSetFromProperties.

@Test
public void testDockerImageSetFromProperties() throws GitClientException, IOException {
    Mockito.when(preferenceManager.getPreference(SystemPreferences.LAUNCH_DOCKER_IMAGE)).thenReturn(IMAGE_FROM_PROPERTIES);
    Tool mockTool = getMockTool(TEST_REPOSITORY, IMAGE_FROM_PROPERTIES);
    Mockito.when(gitManager.getConfigFileContent(Mockito.any(Pipeline.class), Mockito.anyString())).thenReturn(getFileContent(WITHOUT_IMAGE_CONFIG));
    Mockito.when(toolManager.loadByNameOrId(IMAGE_FROM_PROPERTIES)).thenReturn(mockTool);
    PipelineConfiguration configuration = pipelineVersionManager.loadParametersFromScript(1L, "");
    Assert.assertEquals(TEST_REPOSITORY + "/" + IMAGE_FROM_PROPERTIES, configuration.getDockerImage());
}
Also used : PipelineConfiguration(com.epam.pipeline.entity.configuration.PipelineConfiguration) Tool(com.epam.pipeline.entity.pipeline.Tool) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) Test(org.junit.Test) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest)

Example 68 with Tool

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

the class ToolGroupApiServiceTest method testCreateToolInOtherPrivateGroupFails.

/**
 * Should fail on attempt to add a tool to other user's private group
 */
@Test(expected = AccessDeniedException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER2)
public void testCreateToolInOtherPrivateGroupFails() {
    Tool tool = ToolApiServiceTest.generateTool();
    tool.setToolGroupId(existingGroup.getId());
    tool.setToolGroup(existingGroup.getName());
    toolApiService.create(tool);
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with Tool

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

the class ToolGroupApiServiceTest method testCreateToolInOwnGroupOk.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER2, roles = TOOL_GROUP_MANAGER_ROLE)
@Test
public void testCreateToolInOwnGroupOk() {
    ToolGroup privateGroup = toolGroupApiService.createPrivate(registry.getId());
    Tool tool = ToolApiServiceTest.generateTool();
    tool.setImage(privateGroup.getName() + "/" + tool.getImage());
    tool.setToolGroupId(privateGroup.getId());
    tool.setToolGroup(privateGroup.getName());
    toolApiService.create(tool);
    ToolGroup loadedPrivateGroup = toolGroupApiService.loadPrivate(registry.getId());
    Assert.assertEquals(privateGroup.getId(), loadedPrivateGroup.getId());
    Assert.assertEquals(privateGroup.getName(), loadedPrivateGroup.getName());
    Assert.assertEquals(privateGroup.getRegistryId(), loadedPrivateGroup.getRegistryId());
    Assert.assertFalse(loadedPrivateGroup.getTools().isEmpty());
    Assert.assertTrue(loadedPrivateGroup.getTools().stream().anyMatch(t -> t.getImage().equals(tool.getImage())));
    Assert.assertTrue(loadedPrivateGroup.isPrivateGroup());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) TestApplicationWithAclSecurity(com.epam.pipeline.app.TestApplicationWithAclSecurity) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AclTestDao(com.epam.pipeline.dao.util.AclTestDao) Mock(org.mockito.Mock) Autowired(org.springframework.beans.factory.annotation.Autowired) Propagation(org.springframework.transaction.annotation.Propagation) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) AclPermission(com.epam.pipeline.security.acl.AclPermission) TestUtils(com.epam.pipeline.util.TestUtils) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ToolDao(com.epam.pipeline.dao.tool.ToolDao) Test(org.junit.Test) AccessDeniedException(org.springframework.security.access.AccessDeniedException) DockerRegistryDao(com.epam.pipeline.dao.docker.DockerRegistryDao) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Tool(com.epam.pipeline.entity.pipeline.Tool) List(java.util.List) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DockerClientFactory(com.epam.pipeline.manager.docker.DockerClientFactory) Assert(org.junit.Assert) ToolGroupDao(com.epam.pipeline.dao.tool.ToolGroupDao) DockerClient(com.epam.pipeline.manager.docker.DockerClient) Transactional(org.springframework.transaction.annotation.Transactional) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 70 with Tool

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

the class ToolMapper method map.

@Override
public XContentBuilder map(final EntityContainer<Tool> doc) {
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        Tool tool = doc.getEntity();
        jsonBuilder.startObject().field(DOC_TYPE_FIELD, SearchDocumentType.TOOL.name()).field("id", tool.getId()).field("registry", tool.getRegistry()).field("registryId", tool.getRegistryId()).field("image", tool.getImage()).field("createdDate", parseDataToString(tool.getCreatedDate())).field("description", tool.getDescription()).field("shortDescription", tool.getShortDescription()).field("defaultCommand", tool.getDefaultCommand()).field("toolGroupId", tool.getToolGroupId());
        buildLabels(tool.getLabels(), jsonBuilder);
        buildUserContent(doc.getOwner(), jsonBuilder);
        buildMetadata(doc.getMetadata(), jsonBuilder);
        buildPermissions(doc.getPermissions(), jsonBuilder);
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for tool: ", e);
    }
}
Also used : IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Tool(com.epam.pipeline.entity.pipeline.Tool)

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