Fixing docker image tag
[ccsdk/cds.git] / components / model-catalog / blueprint-model / test-blueprint-kotlin-parent / pom.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3   ~ Copyright © 2020 Bell Canada
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
8   ~
9   ~     http://www.apache.org/licenses/LICENSE-2.0
10   ~
11   ~ Unless required by applicable law or agreed to in writing, software
12   ~ distributed under the License is distributed on an "AS IS" BASIS,
13   ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   ~ See the License for the specific language governing permissions and
15   ~ limitations under the License.
16   -->
17
18 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
19     <modelVersion>4.0.0</modelVersion>
20
21     <parent>
22         <groupId>org.onap.ccsdk.cds.components.cba</groupId>
23         <artifactId>blueprint-model</artifactId>
24         <version>1.0.0-SNAPSHOT</version>
25     </parent>
26
27     <artifactId>test-blueprint-kotlin-parent</artifactId>
28     <packaging>pom</packaging>
29
30     <name>Components Model Catalog - Blueprints Model - Test Kotlin Parent</name>
31
32     <dependencies>
33         <dependency>
34             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId>
35             <artifactId>execution-service</artifactId>
36         </dependency>
37         <dependency>
38             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
39             <artifactId>resource-resolution</artifactId>
40         </dependency>
41         <dependency>
42             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
43             <artifactId>netconf-executor</artifactId>
44         </dependency>
45         <dependency>
46             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
47             <artifactId>cli-executor</artifactId>
48         </dependency>
49         <dependency>
50             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
51             <artifactId>message-prioritizaion</artifactId>
52         </dependency>
53         <dependency>
54             <groupId>org.jetbrains.kotlin</groupId>
55             <artifactId>kotlin-test-junit</artifactId>
56             <scope>test</scope>
57         </dependency>
58         <dependency>
59             <groupId>org.jetbrains.kotlinx</groupId>
60             <artifactId>kotlinx-coroutines-test</artifactId>
61             <scope>test</scope>
62         </dependency>
63         <dependency>
64             <groupId>junit</groupId>
65             <artifactId>junit</artifactId>
66             <version>4.12</version>
67             <scope>test</scope>
68         </dependency>
69         <dependency>
70             <groupId>io.mockk</groupId>
71             <artifactId>mockk</artifactId>
72             <version>1.10.0</version>
73             <scope>test</scope>
74         </dependency>
75         <dependency>
76             <groupId>com.squareup.okhttp3</groupId>
77             <artifactId>okhttp</artifactId>
78             <version>3.14.0</version>
79         </dependency>
80     </dependencies>
81
82     <build>
83         <sourceDirectory>${project.basedir}/Scripts/kotlin</sourceDirectory>
84         <testSourceDirectory>${project.basedir}/Tests/kotlin</testSourceDirectory>
85         <resources>
86             <resource>
87                 <directory>${project.basedir}/Environments</directory>
88             </resource>
89         </resources>
90         <plugins>
91             <plugin>
92                 <artifactId>maven-antrun-plugin</artifactId>
93                 <executions>
94                     <execution>
95                         <id>validate-kotlin</id>
96                         <phase>validate</phase>
97                         <configuration>
98                             <target name="ktlint">
99                                 <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
100                                     <arg value="Scripts/kotlin/**/*.kt"/>
101                                 </java>
102                             </target>
103                             <skip>${format.skipValidate}</skip>
104                         </configuration>
105                         <goals>
106                             <goal>run</goal>
107                         </goals>
108                     </execution>
109                     <execution>
110                         <!-- Built-in formatter So that you wouldn't have to fix all style violations by hand.-->
111                         <id>format-kotlin</id>
112                         <phase>process-sources</phase>
113                         <configuration>
114                             <target name="ktlint">
115                                 <java taskname="ktlint" dir="${project.basedir}" fork="true" failonerror="true" classname="com.pinterest.ktlint.Main" classpathref="maven.plugin.classpath">
116                                     <arg value="-F"/>
117                                     <arg value="Scripts/kotlin/**/*.kt"/>
118                                 </java>
119                             </target>
120                             <skip>${format.skipExecute}</skip>
121                         </configuration>
122                         <goals>
123                             <goal>run</goal>
124                         </goals>
125                     </execution>
126                 </executions>
127             </plugin>
128             <plugin>
129                 <groupId>org.jacoco</groupId>
130                 <artifactId>jacoco-maven-plugin</artifactId>
131                 <executions>
132                     <execution>
133                         <id>pre-unit-test</id>
134                         <phase>none</phase>
135                     </execution>
136                     <execution>
137                         <id>default-prepare-agent</id>
138                         <phase>none</phase>
139                     </execution>
140                     <execution>
141                         <id>post-unit-test</id>
142                         <phase>none</phase>
143                     </execution>
144                     <execution>
145                         <id>default-report</id>
146                         <phase>none</phase>
147                     </execution>
148                     <execution>
149                         <id>pre-integration-test</id>
150                         <phase>none</phase>
151                     </execution>
152                     <execution>
153                         <id>post-integration-test</id>
154                         <phase>none</phase>
155                     </execution>
156                     <execution>
157                         <id>default-check</id>
158                         <phase>none</phase>
159                     </execution>
160                 </executions>
161             </plugin>
162             <plugin>
163                 <groupId>org.jetbrains.kotlin</groupId>
164                 <artifactId>kotlin-maven-plugin</artifactId>
165                 <executions>
166                     <execution>
167                         <id>compile</id>
168                         <phase>compile</phase>
169                         <goals>
170                             <goal>compile</goal>
171                         </goals>
172                         <configuration>
173                             <sourceDirs>
174                                 <sourceDir>${project.basedir}/Scripts/kotlin</sourceDir>
175                             </sourceDirs>
176                         </configuration>
177                     </execution>
178                     <execution>
179                         <id>test-compile</id>
180                         <phase>test-compile</phase>
181                         <goals>
182                             <goal>test-compile</goal>
183                         </goals>
184                         <configuration>
185                             <sourceDirs>
186                                 <sourceDir>${project.basedir}/Tests/kotlin</sourceDir>
187                             </sourceDirs>
188                         </configuration>
189                     </execution>
190                 </executions>
191             </plugin>
192             <plugin>
193                 <groupId>org.apache.maven.plugins</groupId>
194                 <artifactId>maven-site-plugin</artifactId>
195                 <executions>
196                     <execution>
197                         <id>attach-descriptor</id>
198                         <phase>none</phase>
199                     </execution>
200                 </executions>
201             </plugin>
202             <plugin>
203                 <artifactId>maven-checkstyle-plugin</artifactId>
204                 <executions>
205                     <execution>
206                         <id>check-license</id>
207                         <phase>none</phase>
208                     </execution>
209                     <execution>
210                         <id>check-style</id>
211                         <phase>none</phase>
212                     </execution>
213                 </executions>
214             </plugin>
215             <plugin>
216                 <artifactId>maven-assembly-plugin</artifactId>
217                 <dependencies>
218                     <dependency>
219                         <groupId>org.onap.ccsdk.cds.components.cba</groupId>
220                         <artifactId>cba-assembly-descriptor</artifactId>
221                         <version>${ccsdk.cds.version}</version>
222                         <exclusions>
223                             <exclusion>
224                                 <groupId>*</groupId>
225                                 <artifactId>*</artifactId>
226                             </exclusion>
227                         </exclusions>
228                     </dependency>
229                 </dependencies>
230                 <executions>
231                     <execution>
232                         <id>make-assembly</id>
233                         <phase>package</phase>
234                         <goals>
235                             <goal>single</goal>
236                         </goals>
237                         <configuration>
238                             <descriptorRefs>
239                                 <descriptorRef>cba_zip</descriptorRef>
240                             </descriptorRefs>
241                         </configuration>
242                     </execution>
243                 </executions>
244             </plugin>
245         </plugins>
246     </build>
247
248     <profiles>
249         <profile>
250             <id>deploy-cba</id>
251             <build>
252                 <plugins>
253                     <plugin>
254                         <groupId>org.codehaus.gmaven</groupId>
255                         <artifactId>groovy-maven-plugin</artifactId>
256                         <dependencies>
257                             <dependency>
258                                 <groupId>com.squareup.okhttp3</groupId>
259                                 <artifactId>okhttp</artifactId>
260                                 <version>3.14.0</version>
261                             </dependency>
262                             <dependency>
263                                 <groupId>commons-io</groupId>
264                                 <artifactId>commons-io</artifactId>
265                                 <version>${commons-io-version}</version>
266                             </dependency>
267                         </dependencies>
268                         <executions>
269                             <execution>
270                                 <id>deploy-cba</id>
271                                 <phase>install</phase>
272                                 <goals>
273                                     <goal>execute</goal>
274                                 </goals>
275                                 <configuration>
276                                     <source>
277                                         import okhttp3.Credentials
278                                         import okhttp3.MediaType
279                                         import okhttp3.MultipartBody
280                                         import okhttp3.OkHttpClient
281                                         import okhttp3.Request
282                                         import okhttp3.RequestBody
283                                         import org.apache.commons.io.IOUtils
284
285                                         import java.io.File
286
287                                         target = "${basedir.absolutePath}/target"
288                                         userName = throwIfPropMissing('cds.username')
289                                         password = throwIfPropMissing('cds.password')
290                                         protocol = properties['cds.protocol'] ?: 'http'
291                                         host = properties['cds.host'] ?: 'localhost'
292                                         port = properties['cds.port'] ?: '8081'
293
294                                         def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip"
295                                         def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip"
296                                         def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich'
297                                         def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish'
298
299                                         def throwIfPropMissing(prop) {
300                                         value = properties[prop]
301                                         if (!value || "".equals(value)) {
302                                         throw new RuntimeException("Property missing: $prop")
303                                         }
304                                         return value
305                                         }
306
307                                         def buildRequest(endpoint, fileName) {
308                                         body = new MultipartBody.Builder()
309                                         .setType(MultipartBody.FORM)
310                                         .addFormDataPart("file",
311                                         fileName,
312                                         RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName)))
313                                         .build()
314
315                                         return new Request.Builder()
316                                         .url("$protocol://$host:$port/$endpoint")
317                                         .addHeader('Authorization', Credentials.basic(userName, password))
318                                         .post(body)
319                                         .build()
320                                         }
321
322                                         def logAndThrow(msg) {
323                                         if(response) {
324                                         log.error(response.body().string())
325                                         }
326                                         throw new RuntimeException(msg)
327                                         }
328
329                                         response = null
330                                         try {
331                                         def client = new OkHttpClient()
332
333                                         response = client.newCall(buildRequest(enrichEndpoint, cba)).execute()
334                                         if (!response || !response.isSuccessful()) {
335                                         logAndThrow("Failed to enrich CBA")
336                                         }
337
338                                         IOUtils.copy(
339                                         response.body().byteStream(),
340                                         new FileOutputStream(new File(target, enrichedCba))
341                                         )
342                                         log.info("Created enriched cba: $enrichedCba")
343
344                                         response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute()
345                                         if (!response || !response.isSuccessful()) {
346                                         logAndThrow("Failed to publish CBA")
347                                         }
348
349                                         log.info("CBA Deployed")
350                                         log.info(response.body().string())
351                                         } finally {
352                                         if (response) {
353                                         response.close()
354                                         }
355                                         }
356                                     </source>
357                                 </configuration>
358                             </execution>
359                         </executions>
360                     </plugin>
361                 </plugins>
362             </build>
363         </profile>
364     </profiles>
365 </project>