diff options
author | dermot123 <dermot.melia@est.tech> | 2019-04-15 10:47:39 +0000 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2019-04-24 06:01:51 +0000 |
commit | 9142d9cea9f033c798c7f669df05e0f6f5b63205 (patch) | |
tree | 61a5a052017e8c58fd974e8b83f13040fec3d160 /catalog-be/src/test/java/org | |
parent | c21ba95e56f70ba9fbe0daa3ac4b413424b323eb (diff) |
ArtifactsBusinessLogic handlePayload() method refactoring and code coverage
Change-Id: I256520e3921c445b9972c78305af615155f7a2c7
Issue-ID: SDC-2239
Signed-off-by: dermot123 <dermot.melia@est.tech>
Diffstat (limited to 'catalog-be/src/test/java/org')
3 files changed, 363 insertions, 65 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java index f35de43613..ccba26461a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java @@ -29,6 +29,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import fj.data.Either; import mockit.Deencapsulation; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Before; import org.junit.Test; @@ -55,13 +56,29 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.info.ArtifactTemplateInfo; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.ArtifactType; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.DataTypeDefinition; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupInstance; +import org.openecomp.sdc.be.model.HeatParameterDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations; import org.openecomp.sdc.be.model.jsontitan.operations.NodeTemplateOperation; import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade; -import org.openecomp.sdc.be.model.operations.api.*; +import org.openecomp.sdc.be.model.operations.api.IElementOperation; +import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation; +import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation; +import org.openecomp.sdc.be.model.operations.api.IUserAdminOperation; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.ArtifactOperation; import org.openecomp.sdc.be.resources.data.ESArtifactData; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -72,22 +89,28 @@ import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.datastructure.Wrapper; -import org.openecomp.sdc.common.datastructure.Wrapper; import org.openecomp.sdc.common.impl.ExternalConfiguration; import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; import java.io.IOException; -import java.util.*; - +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; - -import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_ENV_NAME; import static org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic.HEAT_VF_ENV_NAME; @@ -981,21 +1004,6 @@ public class ArtifactsBusinessLogicTest { } - - - - @Test - public void testIsValidJson() throws Exception { - ArtifactsBusinessLogic testSubject; - byte[] jsonToParse = new byte[] { ' ' }; - boolean result; - - // default test - testSubject = createTestSubject(); - result = Deencapsulation.invoke(testSubject, "isValidJson", new Object[] { jsonToParse }); - } - - @Test public void testValidateSingleDeploymentArtifactName() throws Exception { ArtifactsBusinessLogic testSubject;Wrapper<ResponseFormat> errorWrapper = new Wrapper<>(); @@ -1160,71 +1168,96 @@ public class ArtifactsBusinessLogicTest { } + @Test + public void testGivenValidVesEventsArtifactPayload_WhenHandlePayload_ThenResultIsDecodedPayload() { + final byte[] payload = "validYaml: yes".getBytes(); + ArtifactDefinition artifactInfo = createArtifactInfo(payload, "ves_events_file.yaml", ArtifactTypeEnum.VES_EVENTS); + final boolean isArtifactMetadataUpdate = false; + ArtifactsBusinessLogic testSubject = new ArtifactsBusinessLogic(); + Either<byte[], ResponseFormat> result = Deencapsulation.invoke(testSubject, "handlePayload", + new Object[] { artifactInfo, isArtifactMetadataUpdate }); + assertArrayEquals(payload, result.left().value()); + } - @Test - public void testHandlePayload() throws Exception { - ArtifactsBusinessLogic testSubject; - ArtifactDefinition artifactInfo = buildArtifactPayload(); - boolean isArtifactMetadataUpdate = false; - Either<byte[], ResponseFormat> result; + public void testGivenInValidVesEventsArtifactPayload_WhenHandlePayload_ThenResultIsInvalidYaml() { + final int expectedStatus = 100; + when(componentsUtils.getResponseFormat(eq(ActionStatus.INVALID_YAML), any(String.class))).thenReturn(new ResponseFormat(expectedStatus)); + final byte[] payload = "invalidYaml".getBytes(); + ArtifactDefinition artifactInfo = createArtifactInfo(payload, "ves_events_file.yaml", ArtifactTypeEnum.VES_EVENTS); - // default test - testSubject = createTestSubject(); - result = Deencapsulation.invoke(testSubject, "handlePayload", + final boolean isArtifactMetadataUpdate = false; + ArtifactsBusinessLogic testSubject = new ArtifactsBusinessLogic(); + testSubject.setComponentsUtils(componentsUtils); + + Either<byte[], ResponseFormat> result = Deencapsulation.invoke(testSubject, "handlePayload", new Object[] { artifactInfo, isArtifactMetadataUpdate }); + + int status = result.right().value().getStatus(); + assertEquals(expectedStatus, status); } - + @Test + public void testGivenEmptyVesEventsArtifactPayload_WhenHandlePayload_ThenResultIsMissingData() { + final int expectedStatus = 101; + when(componentsUtils.getResponseFormat(eq(ActionStatus.MISSING_DATA), any(String.class))).thenReturn(new ResponseFormat(expectedStatus)); + final byte[] payload = "".getBytes(); + ArtifactDefinition artifactInfo = createArtifactInfo(payload, "ves_events_file.yaml", ArtifactTypeEnum.VES_EVENTS); + final boolean isArtifactMetadataUpdate = false; + ArtifactsBusinessLogic testSubject = new ArtifactsBusinessLogic(); + testSubject.setComponentsUtils(componentsUtils); - - @Test - public void testValidateYmlPayload() throws Exception { - ArtifactsBusinessLogic testSubject; - byte[] decodedPayload = new byte[] { ' ' }; - String artifactType = ""; - Either<Boolean, ResponseFormat> result; + Either<byte[], ResponseFormat> result = Deencapsulation.invoke(testSubject, "handlePayload", + new Object[] { artifactInfo, isArtifactMetadataUpdate }); - // default test - testSubject = createTestSubject(); - result = Deencapsulation.invoke(testSubject, "validateYmlPayload", - new Object[] { decodedPayload, artifactType }); + int status = result.right().value().getStatus(); + assertEquals(expectedStatus, status); } - @Test - public void testValidateXmlPayload() throws Exception { - ArtifactsBusinessLogic testSubject; - byte[] payload = new byte[] { ' ' }; - String artifactType = ""; - Either<Boolean, ResponseFormat> result; + public void testGivenValidHeatArtifactPayload_WhenHandlePayload_ThenResultIsDecodedPayload() { + final byte[] payload = "heat_template_version: 1.0".getBytes(); + ArtifactDefinition artifactInfo = createArtifactInfo(payload, "heat_template.yaml", ArtifactTypeEnum.HEAT); - // default test - testSubject = createTestSubject(); - result = Deencapsulation.invoke(testSubject, "validateXmlPayload", new Object[] { payload, artifactType }); + final boolean isArtifactMetadataUpdate = false; + ArtifactsBusinessLogic testSubject = new ArtifactsBusinessLogic(); + + Either<byte[], ResponseFormat> result = Deencapsulation.invoke(testSubject, "handlePayload", + new Object[] { artifactInfo, isArtifactMetadataUpdate }); + assertArrayEquals(payload, result.left().value()); } - @Test - public void testValidateJsonPayload() throws Exception { - ArtifactsBusinessLogic testSubject; - byte[] payload = new byte[] { ' ' }; - String type = ""; - Either<Boolean, ResponseFormat> result; + public void testGivenInValidHeatArtifactPayload_WhenHandlePayload_ThenResultIsInvalidYaml() { + final int expectedStatus = 1000; + when(componentsUtils.getResponseFormat(eq(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT), any(String.class))).thenReturn(new ResponseFormat(expectedStatus)); + final byte[] payload = "validYaml: butNoHeatTemplateVersion".getBytes(); + ArtifactDefinition artifactInfo = createArtifactInfo(payload, "heat_template.yaml", ArtifactTypeEnum.HEAT); - // default test - testSubject = createTestSubject(); - result = Deencapsulation.invoke(testSubject, "validateJsonPayload", new Object[] { payload, type }); - } - + final boolean isArtifactMetadataUpdate = false; + ArtifactsBusinessLogic testSubject = new ArtifactsBusinessLogic(); + testSubject.setComponentsUtils(componentsUtils); + + Either<byte[], ResponseFormat> result = Deencapsulation.invoke(testSubject, "handlePayload", + new Object[] { artifactInfo, isArtifactMetadataUpdate }); + int status = result.right().value().getStatus(); + assertEquals(expectedStatus, status); + } + private ArtifactDefinition createArtifactInfo(byte[] payload, String artifactName, ArtifactTypeEnum artifactType) { + ArtifactDefinition artifactInfo = new ArtifactDefinition(); + artifactInfo.setArtifactName(artifactName); + artifactInfo.setArtifactType(artifactType.getType()); + artifactInfo.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); + artifactInfo.setPayload(Base64.encodeBase64(payload)); + return artifactInfo; + } - @Test public void testValidateUserRole() throws Exception { ArtifactsBusinessLogic testSubject; diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/ArtifactTypeToPayloadTypeSelectorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/ArtifactTypeToPayloadTypeSelectorTest.java new file mode 100644 index 0000000000..4f772ea7de --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/ArtifactTypeToPayloadTypeSelectorTest.java @@ -0,0 +1,112 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.artifact; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.openecomp.sdc.common.api.ArtifactTypeEnum; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.openecomp.sdc.be.components.impl.artifact.ArtifactTypeToPayloadTypeSelector.getPayloadType; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.HEAT_ENV; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.HEAT_YAML; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.NOT_DEFINED; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.XML; + +@RunWith(Parameterized.class) +public class ArtifactTypeToPayloadTypeSelectorTest { + + private static final String ANY_EXTENSION = "anyExtension"; + private static final String JSON = "json"; + private static final String YAML = "yaml"; + private static final String YML = "yml"; + private String artifactType; + private String extension; + private PayloadTypeEnum expectedPayloadTypeEnum; + + public ArtifactTypeToPayloadTypeSelectorTest(String artifactType, String extension, PayloadTypeEnum expectedPayloadTypeEnum) { + this.artifactType = artifactType; + this.extension = extension; + this.expectedPayloadTypeEnum = expectedPayloadTypeEnum; + } + + @Parameters(name = "{index}: {0}, {1}") + public static Collection<Object[]> data() { + return Arrays.asList(new Object[][] { + { ArtifactTypeEnum.HEAT.getType(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT.getType().toLowerCase(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT_VOL.getType(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT_VOL.getType().toLowerCase(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT_NET.getType(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT_NET.getType().toLowerCase(), ANY_EXTENSION, HEAT_YAML }, + { ArtifactTypeEnum.HEAT_ENV.getType(), ANY_EXTENSION, HEAT_ENV }, + { ArtifactTypeEnum.HEAT_ENV.getType().toLowerCase(), ANY_EXTENSION, HEAT_ENV }, + { ArtifactTypeEnum.YANG_XML.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.YANG_XML.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VNF_CATALOG.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VNF_CATALOG.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VF_LICENSE.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VF_LICENSE.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VENDOR_LICENSE.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.VENDOR_LICENSE.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.MODEL_QUERY_SPEC.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.MODEL_QUERY_SPEC.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.UCPE_LAYER_2_CONFIGURATION.getType(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.UCPE_LAYER_2_CONFIGURATION.getType().toLowerCase(), ANY_EXTENSION, XML }, + { ArtifactTypeEnum.DCAE_INVENTORY_JSON.getType(), JSON, PayloadTypeEnum.JSON }, + { ArtifactTypeEnum.DCAE_INVENTORY_JSON.getType().toLowerCase(), JSON, PayloadTypeEnum.JSON }, + { ArtifactTypeEnum.DCAE_INVENTORY_TOSCA.getType(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.DCAE_INVENTORY_TOSCA.getType().toLowerCase(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.DCAE_INVENTORY_TOSCA.getType(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.DCAE_INVENTORY_TOSCA.getType().toLowerCase(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.VES_EVENTS.getType(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.VES_EVENTS.getType().toLowerCase(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.VES_EVENTS.getType(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.VES_EVENTS.getType().toLowerCase(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.LIFECYCLE_OPERATIONS.getType(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.LIFECYCLE_OPERATIONS.getType().toLowerCase(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.LIFECYCLE_OPERATIONS.getType(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.LIFECYCLE_OPERATIONS.getType().toLowerCase(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.PM_DICTIONARY.getType(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.PM_DICTIONARY.getType().toLowerCase(), YAML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.PM_DICTIONARY.getType(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.PM_DICTIONARY.getType().toLowerCase(), YML, PayloadTypeEnum.YAML }, + { ArtifactTypeEnum.ANSIBLE_PLAYBOOK.getType(), ANY_EXTENSION, NOT_DEFINED }, + { ArtifactTypeEnum.ANSIBLE_PLAYBOOK.getType().toLowerCase(), ANY_EXTENSION, NOT_DEFINED } + }); + } + + @Test + public void testCorrectPayloadTypeEnumSelectedForArtifactTypeAndExtension() { + PayloadTypeEnum payloadType = getPayloadType(artifactType, extension); + assertEquals(expectedPayloadTypeEnum, payloadType); + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnumTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnumTest.java new file mode 100644 index 0000000000..0456a83690 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/artifact/PayloadTypeEnumTest.java @@ -0,0 +1,153 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * 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. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.artifact; + +import fj.data.Either; +import org.junit.Test; +import org.openecomp.sdc.be.dao.api.ActionStatus; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.HEAT_ENV; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.HEAT_YAML; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.JSON; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.NOT_DEFINED; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.XML; +import static org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum.YAML; + +public class PayloadTypeEnumTest { + + private static final byte[] INVALID_YAML = "invalidYaml".getBytes(); + + @Test + public void testGivenValidContentForHeatYamlType_WhenCheckValid_ThenResultTrue() { + byte[] input = "heat_template_version: 1".getBytes(); + Either<Boolean, ActionStatus> result = HEAT_YAML.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenInvalidYamlContentForHeatYamlType_WhenCheckValid_ThenInvalidYamlResultReturned() { + Either<Boolean, ActionStatus> result = HEAT_YAML.isValid(INVALID_YAML); + assertEquals(ActionStatus.INVALID_YAML, result.right().value()); + } + + @Test + public void testGivenValidYamlButInvalidHeatTempleContentForHeatYamlType_WhenCheckValid_ThenInvalidHeatReturned() { + byte[] input = "validYaml: butNotTopologyTemplate".getBytes(); + Either<Boolean, ActionStatus> result = HEAT_YAML.isValid(input); + assertEquals(ActionStatus.INVALID_DEPLOYMENT_ARTIFACT_HEAT, result.right().value()); + } + + @Test + public void testGivenHeatYamlType_WhenCheckIfHeatRelated_ThenResultTrue() { + assertTrue(HEAT_YAML.isHeatRelated()); + } + + @Test + public void testGivenValidYamlForHeatEnvType_WhenCheckValid_ThenResultTrue() { + byte[] input = "validYaml: yes".getBytes(); + Either<Boolean, ActionStatus> result = HEAT_ENV.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenInvalidYamlContentForHeatEnvType_WhenCheckValid_ThenInvalidYamlResultReturned() { + Either<Boolean, ActionStatus> result = HEAT_ENV.isValid(INVALID_YAML); + assertEquals(ActionStatus.INVALID_YAML, result.right().value()); + } + + @Test + public void testGivenHeatEnvType_WhenCheckIfHeatRelated_ThenResultTrue() { + assertTrue(HEAT_ENV.isHeatRelated()); + } + + @Test + public void testGivenValidYamlForYamlType_WhenCheckValid_ThenResultTrue() { + byte[] input = "validYaml: yes".getBytes(); + Either<Boolean, ActionStatus> result = YAML.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenInvalidYamlContentForYamlType_WhenCheckValid_ThenInvalidYamlResultReturned() { + Either<Boolean, ActionStatus> result = YAML.isValid(INVALID_YAML); + assertEquals(ActionStatus.INVALID_YAML, result.right().value()); + } + + @Test + public void testGivenYamlType_WhenCheckIfHeatRelated_ThenResultFalse() { + assertFalse(YAML.isHeatRelated()); + } + + @Test + public void testGivenValidJsonForJsonType_WhenCheckValid_ThenResultTrue() { + byte[] input = "{\"validYaml\": \"yes\"}".getBytes(); + Either<Boolean, ActionStatus> result = JSON.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenInvalidJsonContentForJsonType_WhenCheckValid_ThenInvalidJsonResultReturned() { + byte[] input = "invalidJson,with,extraCommas".getBytes(); + Either<Boolean, ActionStatus> result = JSON.isValid(input); + assertEquals(ActionStatus.INVALID_JSON, result.right().value()); + } + + @Test + public void testGivenJsonType_WhenCheckIfHeatRelated_ThenResultFalse() { + assertFalse(JSON.isHeatRelated()); + } + + @Test + public void testGivenValidXmlForXmlType_WhenCheckValid_ThenResultTrue() { + byte[] input = "<root>validXml</root>".getBytes(); + Either<Boolean, ActionStatus> result = XML.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenInvalidXmlContentForXmlType_WhenCheckValid_ThenInvalidXmlResultReturned() { + byte[] input = "<root>inValidXmlWithNoClosingTag".getBytes(); + Either<Boolean, ActionStatus> result = XML.isValid(input); + assertEquals(ActionStatus.INVALID_XML, result.right().value()); + } + + @Test + public void testGivenXmlType_WhenCheckIfHeatRelated_ThenResultFalse() { + assertFalse(XML.isHeatRelated()); + } + + @Test + public void testGivenAnyInputForNotDefinedType_WhenCheckValid_ThenResultTrue() { + byte[] input = "Any input can be defined here <<<<<:::::::////////".getBytes(); + Either<Boolean, ActionStatus> result = NOT_DEFINED.isValid(input); + assertTrue(result.left().value()); + } + + @Test + public void testGivenNotDefinedType_WhenCheckIfHeatRelated_ThenResultFalse() { + assertFalse(NOT_DEFINED.isHeatRelated()); + } +}
\ No newline at end of file |