From 6159cb862e49b2ab8b06c11b159681beaf7cbd89 Mon Sep 17 00:00:00 2001 From: "m.kowalski3" Date: Fri, 14 Jun 2019 15:17:03 +0200 Subject: Improve unit tests for MapAction Issue-ID: SDC-2327 Signed-off-by: Marcin Kowalski Change-Id: I15e555c6c65fa2ba253d53a67d00d895668b22f9 --- .../restmodels/ruleeditor/MapActionTest.java | 68 ++++++++++++++++++++-- 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java index 7a3c9a1..1a21d50 100644 --- a/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java +++ b/src/test/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapActionTest.java @@ -1,27 +1,83 @@ -package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END=========================================== + * =================================================================== + * + */ -import org.junit.Test; +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.util.List; +import org.junit.Before; +import org.junit.Test; + + public class MapActionTest { - private MapAction classUnderTest = new MapAction(); + + private MapAction mapAction; + + private static Gson gson = new GsonBuilder().registerTypeAdapter(BaseAction.class, new ActionDeserializer()) + .registerTypeAdapter(BaseCondition.class, new ConditionDeserializer()).create(); + + @Before + public void setup() { + String json = + "{\"map\":{\"default\":\"defaultValue\",\"haveDefault\":true,\"values\":[{\"UIHashMap\":{\"key\":\"val\"}}]}}"; + mapAction = gson.fromJson(json, MapAction.class); + } @Test public void checkEqualsTrueOther() { MapAction equalMapAction = new MapAction(); - assertTrue(classUnderTest.equals(equalMapAction)); + assertTrue(equalMapAction.equals(new MapAction())); } @Test public void checkEqualsTrueSame() { - assertTrue(classUnderTest.equals(classUnderTest)); + assertTrue(mapAction.equals(mapAction)); } @Test public void checkEqualsFalse() { - assertFalse(classUnderTest.equals(null)); + assertFalse(mapAction.equals(null)); + } + + @Test + public void testMapHasDefault() { + assertTrue(mapAction.mapHasDefault()); + } + + @Test + public void testGetMapDefaultValue() { + String defaultValue = mapAction.getMapDefaultValue(); + assertEquals("defaultValue", defaultValue); + } + + @Test + public void testGetMapValues() { + List list = mapAction.getMapValues(); + assertEquals(1, list.size()); } } -- cgit 1.2.3-korg