Search in sources :

Example 1 with AllowList

use of org.kie.workbench.common.services.shared.allowlist.AllowList in project kie-wb-common by kiegroup.

the class PackageNameAllowListSaverTest method testSave.

@Test
public void testSave() throws Exception {
    final Path path = testFileSystem.createTempFile("allowlist");
    final AllowList allowList = new AllowList();
    allowList.add("org.drools");
    allowList.add("org.guvnor");
    final Metadata metadata = new Metadata();
    final String comment = "comment";
    final HashMap<String, Object> attributes = new HashMap<String, Object>();
    when(metadataService.setUpAttributes(path, metadata)).thenReturn(attributes);
    final CommentedOption commentedOption = mock(CommentedOption.class);
    when(commentedOptionFactory.makeCommentedOption("comment")).thenReturn(commentedOption);
    saver.save(path, allowList, metadata, comment);
    ArgumentCaptor<String> allowListTextArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(ioService).write(any(org.uberfire.java.nio.file.Path.class), allowListTextArgumentCaptor.capture(), eq(attributes), eq(commentedOption));
    final String allowListAsText = allowListTextArgumentCaptor.getValue();
    assertTrue(allowListAsText.contains("org.drools"));
    assertTrue(allowListAsText.contains("org.guvnor"));
}
Also used : Path(org.uberfire.backend.vfs.Path) HashMap(java.util.HashMap) CommentedOption(org.uberfire.java.nio.base.options.CommentedOption) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) AllowList(org.kie.workbench.common.services.shared.allowlist.AllowList) Test(org.junit.Test)

Example 2 with AllowList

use of org.kie.workbench.common.services.shared.allowlist.AllowList in project kie-wb-common by kiegroup.

the class PackageNameAllowListServiceImplTest method ifAllowListIsEmptyAllowListEverything.

@Test
public void ifAllowListIsEmptyAllowListEverything() throws Exception {
    final PackageNameAllowListService packageNameAllowListService = makeService("");
    AllowList filterPackageNames = packageNameAllowListService.filterPackageNames(mock(KieModule.class), new ArrayList<String>() {

        {
            add("a");
            add("b");
            add("c");
        }
    });
    assertEquals(3, filterPackageNames.size());
    assertTrue(filterPackageNames.contains("a"));
    assertTrue(filterPackageNames.contains("b"));
    assertTrue(filterPackageNames.contains("c"));
}
Also used : PackageNameAllowListService(org.kie.workbench.common.services.shared.allowlist.PackageNameAllowListService) AllowList(org.kie.workbench.common.services.shared.allowlist.AllowList) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 3 with AllowList

use of org.kie.workbench.common.services.shared.allowlist.AllowList in project kie-wb-common by kiegroup.

the class PackageNameAllowListFilter method getFilteredPackageNames.

/**
 * @return Package Names matching the Allow List to the available packages
 */
public AllowList getFilteredPackageNames() {
    final AllowList allowList = new AllowList();
    final Map<String, String> packageNamePatterns = getPatterns();
    for (String pattern : patterns) {
        for (Map.Entry<String, String> packageNamePath : packageNamePatterns.entrySet()) {
            if (ANT_PATH_MATCHER.match(pattern, packageNamePath.getValue())) {
                allowList.add(packageNamePath.getKey());
            }
        }
    }
    return allowList;
}
Also used : AllowList(org.kie.workbench.common.services.shared.allowlist.AllowList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with AllowList

use of org.kie.workbench.common.services.shared.allowlist.AllowList in project kie-wb-common by kiegroup.

the class DependenciesItemPresenterTest method testSetupTransitive.

@Test
public void testSetupTransitive() {
    dependenciesItemPresenter.setup(new TransitiveEnhancedDependency(mock(Dependency.class), emptySet()), new AllowList(), mock(DependenciesPresenter.class));
    verify(view).init(any());
    verify(view).setGroupId(any());
    verify(view).setArtifactId(any());
    verify(view).setVersion(any());
    verify(view).setPackagesAllowListedState(any());
    verify(view).setTransitiveDependency(eq(true));
}
Also used : TransitiveEnhancedDependency(org.kie.workbench.common.services.shared.dependencies.TransitiveEnhancedDependency) AllowList(org.kie.workbench.common.services.shared.allowlist.AllowList) Test(org.junit.Test)

Example 5 with AllowList

use of org.kie.workbench.common.services.shared.allowlist.AllowList in project kie-wb-common by kiegroup.

the class DependenciesPresenterTest method testRemoveAllFromAllowList.

@Test
public void testRemoveAllFromAllowList() {
    final Set<String> packages = new HashSet<>(Arrays.asList("foo", "bar"));
    dependenciesPresenter.model = mock(ProjectScreenModel.class);
    doReturn(new AllowList(packages)).when(dependenciesPresenter.model).getAllowList();
    assertEquals(2, dependenciesPresenter.model.getAllowList().size());
    dependenciesPresenter.removeAllFromAllowList(packages);
    assertEquals(0, dependenciesPresenter.model.getAllowList().size());
    verify(enhancedDependenciesManager).update();
}
Also used : ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) AllowList(org.kie.workbench.common.services.shared.allowlist.AllowList) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AllowList (org.kie.workbench.common.services.shared.allowlist.AllowList)12 Test (org.junit.Test)11 ProjectScreenModel (org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel)5 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)4 Path (org.uberfire.backend.vfs.Path)3 HashMap (java.util.HashMap)2 PackageNameAllowListService (org.kie.workbench.common.services.shared.allowlist.PackageNameAllowListService)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 BuildMessage (org.guvnor.common.services.project.builder.model.BuildMessage)1 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)1 NormalEnhancedDependency (org.kie.workbench.common.services.shared.dependencies.NormalEnhancedDependency)1 TransitiveEnhancedDependency (org.kie.workbench.common.services.shared.dependencies.TransitiveEnhancedDependency)1 KieModule (org.kie.workbench.common.services.shared.project.KieModule)1 CommentedOption (org.uberfire.java.nio.base.options.CommentedOption)1