Search in sources :

Example 11 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubItemScoreTest method Compare_ListWith3HubItems_OrderedList.

@Test
public void Compare_ListWith3HubItems_OrderedList() {
    Language lang = new Language("First", Collections.emptyList(), 50.0, false);
    Language lang2 = new Language("Second", Collections.emptyList(), 1.0, false);
    Language lang3 = new Language("Third", Collections.emptyList(), 49.0, false);
    List<Language> languages = Arrays.asList(lang, lang2, lang3);
    HubItem hubItem1 = buildHubItem("Second", "", Collections.emptyList());
    HubItem hubItem2 = buildHubItem("First", "", Collections.emptyList());
    HubItem hubItem3 = buildHubItem("Third", "", Collections.emptyList());
    List<HubItem> hubItems = Arrays.asList(hubItem1, hubItem2, hubItem3).stream().sorted(new HubItemScore(languages).reversed()).collect(Collectors.toList());
    ;
    assertEquals(3, hubItems.size());
    assertEquals("First", hubItems.get(0).getResource().getName());
    assertEquals("Second", hubItems.get(1).getResource().getName());
    assertEquals("Third", hubItems.get(2).getResource().getName());
}
Also used : Language(com.redhat.devtools.alizer.api.Language) Test(org.junit.Test)

Example 12 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubModelTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    watch = mock(Watch.class);
    when(tkn.getNamespace()).thenReturn("namespace");
    when(tkn.watchPipelines(anyString(), any())).thenReturn(watch);
    when(tkn.watchTasks(anyString(), any())).thenReturn(watch);
    when(tkn.watchClusterTasks(any())).thenReturn(watch);
    pipelinesNode = mock(PipelinesNode.class);
    clusterTasksNode = mock(ClusterTasksNode.class);
    recognizerFactory = mock(RecognizerFactory.class);
    languageRecognizer = mock(LanguageRecognizer.class);
    when(recognizerFactory.createLanguageRecognizer()).thenReturn(languageRecognizer);
    languageJAVA = new Language("java", Collections.emptyList(), 1.0, true);
    languageUnknown = new Language("Unknown", Collections.emptyList(), 1.0, false);
    resourceApi = mock(ResourceApi.class);
    resourceDataJAVA = mock(ResourceData.class);
    resourceVersionDataJAVA = mock(ResourceVersionData.class);
    when(resourceDataJAVA.getName()).thenReturn("java");
    when(resourceDataJAVA.getKind()).thenReturn(KIND_TASK);
    when(resourceDataJAVA.getLatestVersion()).thenReturn(resourceVersionDataJAVA);
    when(resourceVersionDataJAVA.getVersion()).thenReturn("v1");
    resourceDataGO = mock(ResourceData.class);
    resourceVersionDataGO = mock(ResourceVersionData.class);
    when(resourceDataGO.getName()).thenReturn("go");
    when(resourceDataGO.getKind()).thenReturn(KIND_TASK);
    when(resourceDataGO.getLatestVersion()).thenReturn(resourceVersionDataGO);
    when(resourceVersionDataGO.getVersion()).thenReturn("v1");
    resourceDataNET = mock(ResourceData.class);
    resourceVersionDataNET = mock(ResourceVersionData.class);
    when(resourceDataNET.getName()).thenReturn("net");
    when(resourceDataNET.getKind()).thenReturn(KIND_PIPELINE);
    when(resourceDataNET.getLatestVersion()).thenReturn(resourceVersionDataNET);
    when(resourceVersionDataNET.getVersion()).thenReturn("v1");
    when(project.getBasePath()).thenReturn(".");
    resources = new Resources();
    resources.addDataItem(resourceDataJAVA);
    resources.addDataItem(resourceDataGO);
}
Also used : PipelinesNode(com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode) ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) ResourceData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData) LanguageRecognizer(com.redhat.devtools.alizer.api.LanguageRecognizer) Language(com.redhat.devtools.alizer.api.Language) ResourceVersionData(com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData) Watch(io.fabric8.kubernetes.client.Watch) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) ClusterTasksNode(com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode) Before(org.junit.Before)

Example 13 with Language

use of com.redhat.devtools.alizer.api.Language in project intellij-tekton by redhat-developer.

the class HubModelTest method GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList.

@Test
public void GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList() throws IOException {
    Resources resources = new Resources();
    resources.addDataItem(resourceDataNET);
    try (MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class, (mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
        try (MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class, (mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {
            List<Language> languages = Arrays.asList(languageJAVA);
            when(languageRecognizer.analyze(anyString())).thenReturn(languages);
            HubModel model = new HubModel(project, tkn, null);
            List<HubItem> taskItems = model.getAllTaskHubItems();
            assertEquals(0, taskItems.size());
        }
    }
}
Also used : ResourceApi(com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi) Language(com.redhat.devtools.alizer.api.Language) Resources(com.redhat.devtools.intellij.tektoncd.hub.model.Resources) RecognizerFactory(com.redhat.devtools.alizer.api.RecognizerFactory) Test(org.junit.Test) BaseTest(com.redhat.devtools.intellij.tektoncd.BaseTest)

Aggregations

Language (com.redhat.devtools.alizer.api.Language)13 Test (org.junit.Test)11 RecognizerFactory (com.redhat.devtools.alizer.api.RecognizerFactory)3 Tag (com.redhat.devtools.intellij.tektoncd.hub.model.Tag)3 LanguageRecognizer (com.redhat.devtools.alizer.api.LanguageRecognizer)2 ResourceApi (com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi)2 ResourceData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData)2 ResourceVersionData (com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData)2 Resources (com.redhat.devtools.intellij.tektoncd.hub.model.Resources)2 Strings (com.google.common.base.Strings)1 BaseTest (com.redhat.devtools.intellij.tektoncd.BaseTest)1 ClusterTasksNode (com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode)1 PipelinesNode (com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode)1 Watch (io.fabric8.kubernetes.client.Watch)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1