use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.
the class HubModel method retrieveAllResources.
private List<ResourceData> retrieveAllResources() {
try {
ResourceApi resApi = new ResourceApi();
Resources resources = resApi.resourceList(500);
return resources.getData();
} catch (ApiException e) {
logger.warn(e.getLocalizedMessage(), e);
}
return Collections.emptyList();
}
use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi in project intellij-tekton by redhat-developer.
the class HubModel method getVersionsById.
public List<ResourceVersionData> getVersionsById(int id) {
List<ResourceVersionData> versions = new ArrayList<>();
Optional<HubItem> itemSelected = getAllHubItems().stream().filter(item -> item.getResource().getId() == id).findFirst();
if (itemSelected.isPresent()) {
versions = itemSelected.get().getResource().getVersions();
}
if (versions.isEmpty()) {
ResourceApi res = new ResourceApi();
try {
versions = res.resourceVersionsByID(id).getData().getVersions();
if (itemSelected.isPresent()) {
itemSelected.get().getResource().setVersions(versions);
}
} catch (ApiException e) {
logger.warn(e.getLocalizedMessage());
}
}
return versions;
}
use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi 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);
}
use of com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi 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());
}
}
}
Aggregations