Upgrade to okhttp version 4.9.3
[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 <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">
18     <modelVersion>4.0.0</modelVersion>
19
20     <parent>
21         <groupId>org.onap.ccsdk.cds.components.cba</groupId>
22         <artifactId>blueprint-model</artifactId>
23         <version>1.3.0-SNAPSHOT</version>
24     </parent>
25
26     <artifactId>test-blueprint-kotlin-parent</artifactId>
27     <packaging>pom</packaging>
28
29     <name>Components Model Catalog - Blueprints Model - Test Kotlin Parent</name>
30
31     <dependencies>
32         <dependency>
33             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId>
34             <artifactId>execution-service</artifactId>
35         </dependency>
36         <dependency>
37             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
38             <artifactId>resource-resolution</artifactId>
39         </dependency>
40         <dependency>
41             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
42             <artifactId>netconf-executor</artifactId>
43         </dependency>
44         <dependency>
45             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
46             <artifactId>restconf-executor</artifactId>
47         </dependency>
48         <dependency>
49             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
50             <artifactId>cli-executor</artifactId>
51         </dependency>
52         <dependency>
53             <groupId>org.onap.ccsdk.cds.blueprintsprocessor.functions</groupId>
54             <artifactId>message-prioritization</artifactId>
55         </dependency>
56         <dependency>
57             <groupId>org.jetbrains.kotlin</groupId>
58             <artifactId>kotlin-test-junit</artifactId>
59             <scope>test</scope>
60         </dependency>
61         <dependency>
62             <groupId>org.jetbrains.kotlinx</groupId>
63             <artifactId>kotlinx-coroutines-test</artifactId>
64             <scope>test</scope>
65         </dependency>
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>4.9.3</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                 <groupId>org.jacoco</groupId>
96                 <artifactId>jacoco-maven-plugin</artifactId>
97                 <executions>
98                     <execution>
99                         <id>pre-unit-test</id>
100                         <phase>none</phase>
101                     </execution>
102                     <execution>
103                         <id>default-prepare-agent</id>
104                         <phase>none</phase>
105                     </execution>
106                     <execution>
107                         <id>post-unit-test</id>
108                         <phase>none</phase>
109                     </execution>
110                     <execution>
111                         <id>default-report</id>
112                         <phase>none</phase>
113                     </execution>
114                     <execution>
115                         <id>pre-integration-test</id>
116                         <phase>none</phase>
117                     </execution>
118                     <execution>
119                         <id>post-integration-test</id>
120                         <phase>none</phase>
121                     </execution>
122                     <execution>
123                         <id>default-check</id>
124                         <phase>none</phase>
125                     </execution>
126                 </executions>
127             </plugin>
128             <plugin>
129                 <groupId>org.jetbrains.kotlin</groupId>
130                 <artifactId>kotlin-maven-plugin</artifactId>
131                 <executions>
132                     <execution>
133                         <id>compile</id>
134                         <phase>compile</phase>
135                         <goals>
136                             <goal>compile</goal>
137                         </goals>
138                         <configuration>
139                             <sourceDirs>
140                                 <sourceDir>${project.basedir}/Scripts/kotlin</sourceDir>
141                             </sourceDirs>
142                         </configuration>
143                     </execution>
144                     <execution>
145                         <id>test-compile</id>
146                         <phase>test-compile</phase>
147                         <goals>
148                             <goal>test-compile</goal>
149                         </goals>
150                         <configuration>
151                             <sourceDirs>
152                                 <sourceDir>${project.basedir}/Tests/kotlin</sourceDir>
153                             </sourceDirs>
154                         </configuration>
155                     </execution>
156                 </executions>
157             </plugin>
158             <plugin>
159                 <groupId>org.apache.maven.plugins</groupId>
160                 <artifactId>maven-site-plugin</artifactId>
161                 <executions>
162                     <execution>
163                         <id>attach-descriptor</id>
164                         <phase>none</phase>
165                     </execution>
166                 </executions>
167             </plugin>
168             <plugin>
169                 <artifactId>maven-checkstyle-plugin</artifactId>
170                 <executions>
171                     <execution>
172                         <id>check-license</id>
173                         <phase>none</phase>
174                     </execution>
175                     <execution>
176                         <id>check-style</id>
177                         <phase>none</phase>
178                     </execution>
179                 </executions>
180             </plugin>
181             <plugin>
182                 <artifactId>maven-assembly-plugin</artifactId>
183                 <dependencies>
184                     <dependency>
185                         <groupId>org.onap.ccsdk.cds.components.cba</groupId>
186                         <artifactId>cba-assembly-descriptor</artifactId>
187                         <version>${ccsdk.cds.version}</version>
188                         <exclusions>
189                             <exclusion>
190                                 <groupId>*</groupId>
191                                 <artifactId>*</artifactId>
192                             </exclusion>
193                         </exclusions>
194                     </dependency>
195                 </dependencies>
196                 <executions>
197                     <execution>
198                         <id>make-assembly</id>
199                         <phase>package</phase>
200                         <goals>
201                             <goal>single</goal>
202                         </goals>
203                         <configuration>
204                             <descriptorRefs>
205                                 <descriptorRef>cba_zip</descriptorRef>
206                             </descriptorRefs>
207                         </configuration>
208                     </execution>
209                 </executions>
210             </plugin>
211             <plugin>
212                 <groupId>org.apache.maven.plugins</groupId>
213                 <artifactId>maven-failsafe-plugin</artifactId>
214                 <executions>
215                     <execution>
216                         <id>default</id>
217                         <phase>none</phase>
218                     </execution>
219                     <execution>
220                         <id>integration-tests</id>
221                         <phase>none</phase>
222                     </execution>
223                 </executions>
224             </plugin>
225             <plugin>
226                 <artifactId>maven-surefire-plugin</artifactId>
227                 <executions>
228                     <execution>
229                         <id>default-test</id>
230                         <phase>test</phase>
231                         <goals>
232                             <goal>test</goal>
233                         </goals>
234                     </execution>
235                 </executions>
236             </plugin>
237         </plugins>
238     </build>
239
240     <profiles>
241         <profile>
242             <id>deploy-cba</id>
243             <build>
244                 <plugins>
245                     <plugin>
246                         <groupId>org.codehaus.gmaven</groupId>
247                         <artifactId>groovy-maven-plugin</artifactId>
248                         <dependencies>
249                             <dependency>
250                                 <groupId>com.squareup.okhttp3</groupId>
251                                 <artifactId>okhttp</artifactId>
252                                 <version>3.14.0</version>
253                             </dependency>
254                             <dependency>
255                                 <groupId>commons-io</groupId>
256                                 <artifactId>commons-io</artifactId>
257                                 <version>${commons-io-version}</version>
258                             </dependency>
259                         </dependencies>
260                         <executions>
261                             <execution>
262                                 <id>deploy-cba</id>
263                                 <phase>install</phase>
264                                 <goals>
265                                     <goal>execute</goal>
266                                 </goals>
267                                 <configuration>
268                                     <source>
269                                         import okhttp3.Credentials
270                                         import okhttp3.MediaType
271                                         import okhttp3.MultipartBody
272                                         import okhttp3.OkHttpClient
273                                         import okhttp3.Request
274                                         import okhttp3.RequestBody
275                                         import org.apache.commons.io.IOUtils
276
277                                         import java.io.File
278
279                                         target = "${basedir.absolutePath}/target"
280                                         userName = throwIfPropMissing('cds.username')
281                                         password = throwIfPropMissing('cds.password')
282                                         protocol = properties['cds.protocol'] ?: 'http'
283                                         host = properties['cds.host'] ?: 'localhost'
284                                         port = properties['cds.port'] ?: '8081'
285
286                                         def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip"
287                                         def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip"
288                                         def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich'
289                                         def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish'
290
291                                         def throwIfPropMissing(prop) {
292                                         value = properties[prop]
293                                         if (!value || "".equals(value)) {
294                                         throw new RuntimeException("Property missing: $prop")
295                                         }
296                                         return value
297                                         }
298
299                                         def buildRequest(endpoint, fileName) {
300                                         body = new MultipartBody.Builder()
301                                         .setType(MultipartBody.FORM)
302                                         .addFormDataPart("file",
303                                         fileName,
304                                         RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName)))
305                                         .build()
306
307                                         return new Request.Builder()
308                                         .url("$protocol://$host:$port/$endpoint")
309                                         .addHeader('Authorization', Credentials.basic(userName, password))
310                                         .post(body)
311                                         .build()
312                                         }
313
314                                         def logAndThrow(msg) {
315                                         if(response) {
316                                         log.error(response.body().string())
317                                         }
318                                         throw new RuntimeException(msg)
319                                         }
320
321                                         response = null
322                                         try {
323                                         def client = new OkHttpClient()
324
325                                         response = client.newCall(buildRequest(enrichEndpoint, cba)).execute()
326                                         if (!response || !response.isSuccessful()) {
327                                         logAndThrow("Failed to enrich CBA")
328                                         }
329
330                                         IOUtils.copy(
331                                         response.body().byteStream(),
332                                         new FileOutputStream(new File(target, enrichedCba))
333                                         )
334                                         log.info("Created enriched cba: $enrichedCba")
335
336                                         response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute()
337                                         if (!response || !response.isSuccessful()) {
338                                         logAndThrow("Failed to publish CBA")
339                                         }
340
341                                         log.info("CBA Deployed")
342                                         log.info(response.body().string())
343                                         } finally {
344                                         if (response) {
345                                         response.close()
346                                         }
347                                         }
348                                     </source>
349                                 </configuration>
350                             </execution>
351                         </executions>
352                     </plugin>
353                 </plugins>
354             </build>
355         </profile>
356     </profiles>
357 </project>