LoadUserArtifactsCommand extends AbstractCommand { protected DocumentMetadataHandle buildMetadata(String permissions, String collection) { DocumentMetadataHandle meta = new DocumentMetadataHandle(); meta.getCollections().add(collection); documentPermissionsParser.parsePermissions(permissions, meta.getPermissions()); return meta; } LoadUserArtifactsCommand();  LoadUserArtifactsCommand(HubConfig hubConfig); void setForceLoad(boolean forceLoad); @Override void execute(CommandContext context); void setHubConfig(HubConfig hubConfig); void setObjectMapper(ObjectMapper objectMapper);  }
@Test public void defaultEntityModelPermissions() { DocumentMetadataHandle.DocumentPermissions perms = loadUserArtifactsCommand.buildMetadata(adminHubConfig.getEntityModelPermissions(), "http: assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("data-hub-entity-model-writer").iterator().next()); perms = loadUserArtifactsCommand.buildMetadata(adminHubConfig.getStepDefinitionPermissions(), "http: assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("data-hub-step-definition-writer").iterator().next()); perms = loadUserArtifactsCommand.buildMetadata(adminHubConfig.getFlowPermissions(), "http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("data-hub-flow-reader").iterator().next()); perms = loadUserArtifactsCommand.buildMetadata(adminHubConfig.getMappingPermissions(), "http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("data-hub-mapping-reader").iterator().next()); }
@Test public void customEntityModelPermissions() { HubConfigImpl config = new HubConfigImpl(); config.setEntityModelPermissions("manage-user,read,manage-admin,update"); config.setFlowPermissions("manage-user,read,manage-admin,update"); config.setMappingPermissions("manage-user,read,manage-admin,update"); config.setStepDefinitionPermissions("manage-user,read,manage-admin,update"); DocumentMetadataHandle.DocumentPermissions perms = loadUserArtifactsCommand.buildMetadata(config.getEntityModelPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-entity-model-writer")); perms = loadUserArtifactsCommand.buildMetadata(config.getStepDefinitionPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-step-definition-writer")); perms = loadUserArtifactsCommand.buildMetadata(config.getFlowPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-flow-reader")); perms = loadUserArtifactsCommand.buildMetadata(config.getMappingPermissions(),"http: assertEquals(DocumentMetadataHandle.Capability.READ, perms.get("manage-user").iterator().next()); assertEquals(DocumentMetadataHandle.Capability.UPDATE, perms.get("manage-admin").iterator().next()); assertNull(perms.get("data-hub-mapping-reader")); }