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