2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.core.converter.impl.pnfd.parser;
22 import static org.hamcrest.Matchers.equalTo;
23 import static org.hamcrest.Matchers.notNullValue;
24 import static org.junit.Assert.assertThat;
25 import static org.junit.Assert.fail;
26 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.QUERY;
27 import static org.openecomp.core.converter.pnfd.model.PnfTransformationToken.TO_NAME;
29 import java.io.IOException;
30 import java.io.InputStream;
32 import org.junit.Test;
33 import org.openecomp.core.converter.pnfd.model.ConversionDefinition;
34 import org.openecomp.core.converter.pnfd.model.ConversionStrategyType;
35 import org.openecomp.core.util.TestResourcesUtil;
36 import org.openecomp.core.util.YamlTestUtil;
38 public class ConversionDefinitionYamlParserTest {
41 public void shouldBuildDefinition() {
42 final Map<String, Object> definitionYaml;
43 final String definitionYamlFilePath = "transformation/conversionDefinition/conversionDefinitionWithReplaceStrategy.yaml";
44 try (final InputStream resourceInputStream = TestResourcesUtil.getFileResourceAsStream(definitionYamlFilePath)) {
45 definitionYaml = (Map<String, Object>) YamlTestUtil.read(resourceInputStream);
46 } catch (final IOException e) {
47 fail(String.format("Could not load %s", definitionYamlFilePath));
50 final ConversionDefinition conversionDefinition = ConversionDefinitionYamlParser.parse(definitionYaml);
51 assertConversionDefinition(definitionYaml, conversionDefinition);
54 private void assertConversionDefinition(final Map<String, Object> definitionYaml,
55 final ConversionDefinition conversionDefinition) {
56 assertThat("The conversion definition should have been built"
57 , conversionDefinition, notNullValue());
58 assertThat("Should have initialized the conversion definition query"
59 , conversionDefinition.getConversionQuery(), notNullValue());
60 assertThat("The conversion definition should have been built"
61 , conversionDefinition.getConversionQuery().getQuery(), equalTo(definitionYaml.get(QUERY.getName())));
62 assertThat("Should have initialized the conversion definition to attribute name"
63 , conversionDefinition.getToAttributeName(), equalTo(definitionYaml.get(TO_NAME.getName())));
64 assertThat("Should have initialized the conversion definition strategy"
65 , conversionDefinition.getPnfdConversionStrategy(), notNullValue());
66 assertThat("Should have the expected strategy"
67 , conversionDefinition.getPnfdConversionStrategy().getStrategyType(), equalTo(ConversionStrategyType.REPLACE));