Fix remaining Sonar code smells
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / fixture / ArtifactInfoBuilder.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.babel.csar.fixture;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import org.onap.sdc.api.notification.IArtifactInfo;
26
27 /**
28  * This class builds an instance of IArtifactInfo for test purposes.
29  */
30 public class ArtifactInfoBuilder {
31
32     /**
33      * Builds an implementation of IArtifactInfo for test purposes.
34      * <p/>
35      *
36      * @param type
37      *            type of artifact
38      * @param name
39      *            name of artifact
40      * @param description
41      *            description of artifact
42      * @param version
43      *            version of artifact
44      * @return IArtifactInfo implementation of IArtifactInfo from given parameters for test purposes
45      */
46     public static IArtifactInfo build(final String type, final String name, final String description,
47             final String version) {
48         IArtifactInfo artifact = new TestArtifactInfoImpl();
49
50         ((TestArtifactInfoImpl) artifact).setArtifactType(type);
51         ((TestArtifactInfoImpl) artifact).setArtifactName(name);
52         ((TestArtifactInfoImpl) artifact).setArtifactDescription(description);
53         ((TestArtifactInfoImpl) artifact).setArtifactVersion(version);
54
55         return artifact;
56     }
57
58     /**
59      * This method is responsible for building a collection of artifacts from a given set of info.
60      * <p/>
61      * The info supplied is a two dimensional array with each element of the first dimension representing a single
62      * artifact and each element of the second dimension represents a property of the artifact.
63      * <p/>
64      * The method will call {@link #build(String, String, String, String)} to build each element in the first dimension
65      * where the elements of the second dimension are the arguments to {@link #build(String, String, String, String)}.
66      * <p/>
67      *
68      * @param artifactInfoBits
69      *            a two dimensional array of data used to build the artifacts
70      * @return List&lt;IArtifactInfo&gt; a list of artifacts built from the given array of info
71      */
72     static List<IArtifactInfo> buildArtifacts(final String[][] artifactInfoBits) {
73         List<IArtifactInfo> artifacts = new ArrayList<>();
74
75         for (String[] artifactInfoBit : artifactInfoBits) {
76             artifacts.add(build(artifactInfoBit[0], artifactInfoBit[1], artifactInfoBit[2], artifactInfoBit[3]));
77         }
78
79         return artifacts;
80     }
81 }