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