diff options
Diffstat (limited to 'integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/ToscaTypesDefinitionUtils.java')
-rw-r--r-- | integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/ToscaTypesDefinitionUtils.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/ToscaTypesDefinitionUtils.java b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/ToscaTypesDefinitionUtils.java new file mode 100644 index 0000000000..9e5c6964e2 --- /dev/null +++ b/integration-tests/src/test/java/org/onap/sdc/backend/ci/tests/utils/ToscaTypesDefinitionUtils.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.onap.sdc.backend.ci.tests.utils; + +import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaAnnotationsTypesDefinition; +import org.onap.sdc.backend.ci.tests.tosca.datatypes.ToscaParameterConstants; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.User; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; + +import static org.junit.Assert.assertNotNull; +import static org.onap.sdc.backend.ci.tests.utils.ToscaParserUtils.getDataFromZipFileByBytes; +import static org.testng.AssertJUnit.fail; + +public class ToscaTypesDefinitionUtils { + + private ToscaTypesDefinitionUtils() { + } + + private static final String ANNOTATIONS_TYPE_PATH = ToscaParameterConstants.TOSCA_DEFINITION_PATH + "/annotations.yml"; + private static Logger log = LoggerFactory.getLogger(ToscaTypesDefinitionUtils.class); + + public static ToscaAnnotationsTypesDefinition getToscaAnnotationsFromCsar(Component csarOwner, User user) throws Exception { + byte[] decodeBase64 = CsarParserUtils.downloadComponentCsar(csarOwner, user); + String dataFromZipFileByBytes = getDataFromZipFileByBytes(ANNOTATIONS_TYPE_PATH, decodeBase64); + assertNotNull(dataFromZipFileByBytes); + return parseToscaAnnotationsYml(dataFromZipFileByBytes); + } + + private static ToscaAnnotationsTypesDefinition parseToscaAnnotationsYml(String payload){ + Constructor constructor = initToscaAnnotationDefObject(); + return (ToscaAnnotationsTypesDefinition) parseToscaYamlPayload(payload, constructor); + } + + private static Object parseToscaYamlPayload(String payload, Constructor constructor) { + Yaml yaml = new Yaml(constructor); + try { + return yaml.load(payload); + } catch (Exception e) { + log.debug("Failed to parse tosca yaml file", e); + e.printStackTrace(); + fail("Failed to parse tosca yaml file"); + } + return null; + } + + private static Constructor initToscaAnnotationDefObject() { + Constructor toscaStructure = new Constructor(ToscaAnnotationsTypesDefinition.class); + toscaStructure.addTypeDescription(ToscaAnnotationsTypesDefinition.getTypeDescription()); + return toscaStructure; + } +} |