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