Search in sources :

Example 16 with ToolGroup

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

the class ToolGroupApiServiceTest method testLoadOtherPrivateGroupFails2.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER2, roles = TOOL_GROUP_MANAGER_ROLE)
@Test()
public void testLoadOtherPrivateGroupFails2() {
    ToolGroup group = toolGroupApiService.load(existingGroup.getId());
    Assert.assertTrue(group.getTools().isEmpty());
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) 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 17 with ToolGroup

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

the class ToolGroupApiServiceTest method testLoadOtherPrivateGroupFails.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER2, roles = TOOL_GROUP_MANAGER_ROLE)
@Test
public void testLoadOtherPrivateGroupFails() {
    ToolGroup privateGroup = toolGroupApiService.createPrivate(registry.getId());
    List<ToolGroup> groups = toolGroupApiService.loadByRegistryId(registry.getId());
    Assert.assertTrue(groups.stream().noneMatch(g -> g.getName().equals(existingGroup.getName())));
    Assert.assertTrue(groups.stream().anyMatch(g -> g.getName().equals(privateGroup.getName())));
    groups = toolGroupApiService.loadByRegistryNameOrId(registry.getPath());
    Assert.assertTrue(groups.stream().noneMatch(g -> g.getName().equals(existingGroup.getName())));
    Assert.assertTrue(groups.stream().anyMatch(g -> g.getName().equals(privateGroup.getName())));
}
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) 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 18 with ToolGroup

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

the class ToolGroupMapper method map.

@Override
public XContentBuilder map(final EntityContainer<ToolGroup> container) {
    ToolGroup toolGroup = container.getEntity();
    try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) {
        jsonBuilder.startObject();
        jsonBuilder.field(DOC_TYPE_FIELD, SearchDocumentType.TOOL_GROUP.name()).field("id", toolGroup.getId()).field("name", toolGroup.getName()).field("registryId", toolGroup.getRegistryId()).field("createdDate", parseDataToString(toolGroup.getCreatedDate())).field("description", toolGroup.getDescription());
        buildUserContent(container.getOwner(), jsonBuilder);
        buildMetadata(container.getMetadata(), jsonBuilder);
        buildPermissions(container.getPermissions(), jsonBuilder);
        jsonBuilder.endObject();
        return jsonBuilder;
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to create elasticsearch document for tool group: ", e);
    }
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 19 with ToolGroup

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

the class ToolGroupMapperTest method shouldMapToolGroup.

@Test
void shouldMapToolGroup() throws IOException {
    ToolGroupMapper mapper = new ToolGroupMapper();
    ToolGroup toolGroup = new ToolGroup();
    toolGroup.setId(1L);
    toolGroup.setName(TEST_NAME);
    toolGroup.setRegistryId(1L);
    toolGroup.setDescription(TEST_DESCRIPTION);
    EntityContainer<ToolGroup> container = EntityContainer.<ToolGroup>builder().entity(toolGroup).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
    XContentBuilder contentBuilder = mapper.map(container);
    verifyToolGroup(toolGroup, contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
    verifyMetadata(EXPECTED_METADATA, contentBuilder);
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) MapperVerificationUtils.verifyToolGroup(com.epam.pipeline.elasticsearchagent.MapperVerificationUtils.verifyToolGroup) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

Example 20 with ToolGroup

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

the class ToolDao method basicInitTool.

private static Tool basicInitTool(ResultSet rs, Tool tool) throws SQLException {
    tool.setId(rs.getLong(ToolParameters.ID.name()));
    tool.setImage(rs.getString(ToolParameters.IMAGE.name()));
    tool.setCpu(rs.getString(ToolParameters.CPU.name()));
    tool.setRam(rs.getString(ToolParameters.RAM.name()));
    tool.setRegistryId(rs.getLong(ToolParameters.REGISTRY_ID.name()));
    tool.setToolGroupId(rs.getLong(ToolParameters.TOOL_GROUP_ID.name()));
    tool.setRegistry(rs.getString(ToolParameters.REGISTRY.name()));
    tool.setSecretName(rs.getString(ToolParameters.SECRET_NAME.name()));
    tool.setDescription(rs.getString(ToolParameters.DESCRIPTION.name()));
    tool.setShortDescription(rs.getString(ToolParameters.SHORT_DESCRIPTION.name()));
    tool.setDefaultCommand(rs.getString(ToolParameters.DEFAULT_COMMAND.name()));
    tool.setOwner(rs.getString(ToolParameters.OWNER.name()));
    tool.setDisk(rs.getInt(ToolParameters.DISK.name()));
    tool.setInstanceType(rs.getString(ToolParameters.INSTANCE_TYPE.name()));
    long longVal = rs.getLong(ToolParameters.ICON_ID.name());
    tool.setHasIcon(!rs.wasNull());
    tool.setIconId(longVal);
    Array labelsSqlArray = rs.getArray(ToolParameters.LABELS.name());
    if (labelsSqlArray != null) {
        List<String> labels = Arrays.asList((String[]) labelsSqlArray.getArray());
        tool.setLabels(labels);
    }
    Array endpointsSqlArray = rs.getArray(ToolParameters.ENDPOINTS.name());
    if (endpointsSqlArray != null) {
        List<String> endpoints = Arrays.asList((String[]) endpointsSqlArray.getArray());
        tool.setEndpoints(endpoints);
    }
    // restore parent hierarchy
    if (tool.getToolGroupId() != null) {
        tool.setParent(new ToolGroup(tool.getToolGroupId()));
        if (tool.getRegistryId() != null) {
            tool.getParent().setParent(new DockerRegistry(tool.getRegistryId()));
        }
    }
    return tool;
}
Also used : Array(java.sql.Array) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

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