Skip to content

Commit 69d062e

Browse files
committed
fix: Non odo components are not visible
Fixes redhat-developer#369 Signed-off-by: Jeff MAURY <[email protected]>
1 parent e54700e commit 69d062e

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

src/main/java/org/jboss/tools/intellij/openshift/utils/odo/ComponentDeserializer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class ComponentDeserializer extends StdNodeBasedDeserializer<List<Component>> {
2323

2424
public static final String DEVFILE_FIELD = "devfileComponents";
25+
public static final String OTHER_FIELD = "otherComponents";
2526
public static final String METADATA_FIELD = "metadata";
2627
public static final String NAME_FIELD = "name";
2728

@@ -33,6 +34,7 @@ public ComponentDeserializer() {
3334
public List<Component> convert(JsonNode root, DeserializationContext context) {
3435
List<Component> result = new ArrayList<>();
3536
result.addAll(parseComponents(root.get(DEVFILE_FIELD)));
37+
result.addAll(parseComponents(root.get(OTHER_FIELD)));
3638
return result;
3739
}
3840

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2022 Red Hat, Inc.
3+
* Distributed under license by Red Hat, Inc. All rights reserved.
4+
* This program is made available under the terms of the
5+
* Eclipse Public License v2.0 which accompanies this distribution,
6+
* and is available at http://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
******************************************************************************/
11+
package org.jboss.tools.intellij.openshift.utils.odo;
12+
13+
import com.fasterxml.jackson.core.type.TypeReference;
14+
import com.fasterxml.jackson.databind.ObjectMapper;
15+
import com.fasterxml.jackson.databind.module.SimpleModule;
16+
import org.junit.Assert;
17+
import org.junit.BeforeClass;
18+
import org.junit.Test;
19+
20+
import java.io.IOException;
21+
import java.net.URL;
22+
import java.util.List;
23+
24+
public class ComponentDeserializerTest {
25+
private static final URL url = ComponentDeserializerTest.class.getResource("/components-test.json");
26+
27+
private static ObjectMapper MAPPER;
28+
29+
@BeforeClass
30+
public static void setup() {
31+
MAPPER = new ObjectMapper();
32+
SimpleModule module = new SimpleModule();
33+
module.addDeserializer(List.class, new ComponentDeserializer());
34+
MAPPER.registerModule(module);
35+
}
36+
37+
@Test
38+
public void verifyThatComponentsCanLoad() throws IOException {
39+
List<Component> components = MAPPER.readValue(url, new TypeReference<List<Component>>() {});
40+
Assert.assertNotNull(components);
41+
}
42+
43+
@Test
44+
public void verifyThatComponentDeserializerReturnsComponents() throws IOException {
45+
List<Component> components = MAPPER.readValue(url, new TypeReference<List<Component>>() {});
46+
Assert.assertNotNull(components);
47+
Assert.assertEquals(2, components.size());
48+
Assert.assertNotNull(components.get(0));
49+
Assert.assertNotNull(components.get(1));
50+
}
51+
52+
@Test
53+
public void verifyThatComponentDeserializerReturnsComponentsPropertiesForDevfileComponent() throws IOException {
54+
List<Component> components = MAPPER.readValue(url, new TypeReference<List<Component>>() {});
55+
Assert.assertNotNull(components);
56+
Assert.assertEquals(2, components.size());
57+
//Devfile components
58+
Component component = components.get(0);
59+
Assert.assertNotNull(component);
60+
Assert.assertEquals("nodejs1", component.getName());
61+
}
62+
63+
@Test
64+
public void verifyThatComponentDeserializerReturnsComponentsPropertiesForNonOdoComponent() throws IOException {
65+
List<Component> components = MAPPER.readValue(url, new TypeReference<List<Component>>() {});
66+
Assert.assertNotNull(components);
67+
Assert.assertEquals(2, components.size());
68+
//non odo components
69+
Component component = components.get(1);
70+
Assert.assertNotNull(component);
71+
Assert.assertEquals("quarkus1", component.getName());
72+
}
73+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"kind": "List",
3+
"apiVersion": "odo.dev/v1alpha1",
4+
"metadata": {},
5+
"devfileComponents": [
6+
{
7+
"kind": "Component",
8+
"apiVersion": "odo.dev/v1alpha1",
9+
"metadata": {
10+
"name": "nodejs1",
11+
"namespace": "jmaury-dev",
12+
"creationTimestamp": null,
13+
"labels": {
14+
"app": "sample-app",
15+
"app.kubernetes.io/instance": "nodejs1",
16+
"app.kubernetes.io/managed-by": "odo",
17+
"app.kubernetes.io/managed-by-version": "v2.5.0",
18+
"app.kubernetes.io/name": "",
19+
"app.kubernetes.io/part-of": "sample-app",
20+
"component": "nodejs1"
21+
},
22+
"annotations": {
23+
"app.openshift.io/vcs-uri": "[email protected]:odo-devfiles/nodejs-ex.git",
24+
"deployment.kubernetes.io/revision": "1",
25+
"odo.dev/project-type": "nodejs"
26+
}
27+
},
28+
"spec": {
29+
"app": "sample-app",
30+
"type": "nodejs",
31+
"env": [
32+
{
33+
"name": "PROJECTS_ROOT",
34+
"value": "/project"
35+
},
36+
{
37+
"name": "PROJECT_SOURCE",
38+
"value": "/project"
39+
},
40+
{
41+
"name": "DEBUG_PORT",
42+
"value": "5858"
43+
}
44+
]
45+
},
46+
"status": {
47+
"state": "Pushed"
48+
}
49+
}
50+
],
51+
"otherComponents": [
52+
{
53+
"kind": "Component",
54+
"apiVersion": "odo.dev/v1alpha1",
55+
"metadata": {
56+
"name": "quarkus1",
57+
"namespace": "jmaury-dev",
58+
"creationTimestamp": null,
59+
"labels": {
60+
"app": "quarkus1",
61+
"app.kubernetes.io/component": "quarkus1",
62+
"app.kubernetes.io/instance": "quarkus1",
63+
"app.kubernetes.io/name": "quarkus1",
64+
"app.kubernetes.io/part-of": "sample-app",
65+
"app.openshift.io/runtime": "quarkus1"
66+
},
67+
"annotations": {
68+
"alpha.image.policy.openshift.io/resolve-names": "*",
69+
"app.openshift.io/vcs-ref": "",
70+
"app.openshift.io/vcs-uri": "https://github.com/elsony/devfile-sample-code-with-quarkus.git",
71+
"deployment.kubernetes.io/revision": "2",
72+
"image.openshift.io/triggers": "[{\"from\":{\"kind\":\"ImageStreamTag\",\"name\":\"quarkus1:latest\",\"namespace\":\"jmaury-dev\"},\"fieldPath\":\"spec.template.spec.containers[?(@.name==\\\"quarkus1\\\")].image\",\"pause\":\"false\"}]",
73+
"isFromDevfile": "true",
74+
"openshift.io/generated-by": "OpenShiftWebConsole"
75+
}
76+
},
77+
"spec": {
78+
"app": "sample-app",
79+
"type": "Not available",
80+
"env": [
81+
{
82+
"name": "PROJECTS_ROOT",
83+
"value": "/projects"
84+
},
85+
{
86+
"name": "PROJECT_SOURCE",
87+
"value": "/projects"
88+
}
89+
]
90+
},
91+
"status": {
92+
"state": "Pushed"
93+
}
94+
}
95+
]
96+
}

0 commit comments

Comments
 (0)