|
| 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 | +} |
0 commit comments