summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java
blob: 11292d8a9256fc578bdf0419b4278b8648adc48a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * Copyright 2020 Nokia
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.
 */

package org.onap.functional;

import com.google.gson.Gson;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.functional.cli.OnapCliValidationResponseWrapper;
import org.onap.functional.cli.OnapCliWrapper;

import java.util.Arrays;

import static org.assertj.core.api.Assertions.assertThat;

public final class CsarValidationUtility {

    private static final int NOR_ERROR_CODE = 0;
    private static final String UNKNOWN_LINE_NUMBER = "-1";
    private static final String UNKNOWN_FILE = "";

    private CsarValidationUtility(){}

    public static final String CERTIFICATION_RULE = "r130206";
    public static final String PM_DICTIONARY_YAML_RULE = "r816745";
    public static final String MANIFEST_FILE_RULE = "r01123";
    public static final String OPERATION_STATUS_FAILED = "FAILED";
    public static final String OPERATION_STATUS_PASS = "PASS";

    public static OnapCliValidationResponseWrapper getCliCommandValidationResult(OnapCliWrapper cli) {
        final OnapCommandResult onapCommandResult = cli.getCommandResult();
        return new Gson().fromJson(onapCommandResult.getOutput().toString(), OnapCliValidationResponseWrapper.class);
    }

    public static OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper createExpectedError(
        String rule, String errorCode, String errorMessage
    ) {
        return new OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper(
            rule.toUpperCase(), errorCode,
            errorMessage,
            UNKNOWN_FILE, UNKNOWN_LINE_NUMBER
        );
    }

    public static OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper createExpectedError(
        String rule, String errorCode, String errorMessage, String file
    ) {
        return new OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper(
            rule.toUpperCase(), errorCode,
            errorMessage,
            file, UNKNOWN_LINE_NUMBER
        );
    }

    public static boolean ruleHaveOneOfCodes(String ruleCode, String... codes ) {
        return Arrays.asList(codes).contains(ruleCode);
    }

    public static void verifyThatOperationFinishedWithoutAnyError(OnapCliWrapper cli) {
        assertThat(cli.getExitCode()).isEqualTo(NOR_ERROR_CODE);
    }



}