Skip to content
This repository was archived by the owner on Dec 20, 2021. It is now read-only.

Commit 7b7ffd5

Browse files
alezorSebastian Lohmeier
authored andcommitted
0.1 Release commit (#19)
* Adding integration tests * MQTT Test (without AMQP side - configured via Jenkins) * implemented internal AMQP consumer with Hono-Cli classes Signed-off-by: Alexander Zorin <[email protected]>
1 parent 54e5f3b commit 7b7ffd5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1445
-903
lines changed

Jenkinsfile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ pipeline {
1616
git 'https://github.com/eclipse/kuksa.integration.git'
1717
sh """cd testing && \
1818
export JAVA_HOME=/opt/tools/java/openjdk/latest && \
19-
/opt/tools/apache-maven/latest/bin/mvn --batch-mode test -Dhono_device_registry=${hono_device_registry} \
20-
-Dhono_dispatch_router=${hono_dispatch_router} \
19+
/opt/tools/apache-maven/latest/bin/mvn --batch-mode clean test \
20+
-Dhono_device_registry=${hono_device_registry} \
21+
-Dhono_dispatch_router=${hono_dispatch_router} \
2122
-Dhono_adapter_http_vertx=${hono_adapter_http_vertx} \
2223
-Dhono_adapter_mqtt_vertx=${hono_adapter_mqtt_vertx} \
2324
-Dhawkbit_address=${hawkbit_address} \
@@ -26,15 +27,19 @@ pipeline {
2627
-Dappstore_address=${appstore_address} \
2728
-Dappstore_username=${appstore_username} \
2829
-Dappstore_password=${appstore_password} \
30+
-Dhono_client_host=${hono_client_host} \
31+
-Dhono_client_port=${hono_client_port} \
32+
-Dhono_client_password=${hono_client_password} \
33+
-Dhono_client_username=${hono_client_username} \
2934
"""
35+
}
3036
}
3137
}
32-
}
3338
post {
3439
failure {
3540
mail to: '[email protected]',
3641
subject: "Failed Jenkins Pipeline: ${currentBuild.fullDisplayName}",
37-
body: "Something is wrong with ${env.BUILD_URL}"
42+
body: "Something is wrong with ${env.BUILD_URL}"
3843
}
3944
}
4045
}

testing/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/

testing/pom.xml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
<dependencies>
2929
<dependency>
30-
<groupId>org.springframework.boot</groupId>
31-
<artifactId>spring-boot-starter</artifactId>
30+
<groupId>org.springframework.cloud</groupId>
31+
<artifactId>spring-cloud-starter-openfeign</artifactId>
3232
<exclusions>
3333
<exclusion>
3434
<groupId>org.springframework.boot</groupId>
@@ -39,6 +39,19 @@
3939

4040
</dependency>
4141

42+
<dependency>
43+
<groupId>org.springframework</groupId>
44+
<artifactId>spring-core</artifactId>
45+
<version>5.1.5.RELEASE</version>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.springframework</groupId>
50+
<artifactId>spring-web</artifactId>
51+
<scope>test</scope>
52+
<version>5.1.5.RELEASE</version>
53+
</dependency>
54+
4255
<dependency>
4356
<groupId>org.springframework.boot</groupId>
4457
<artifactId>spring-boot-starter-web</artifactId>
@@ -60,13 +73,6 @@
6073

6174
</dependency>
6275

63-
<dependency>
64-
<groupId>org.springframework</groupId>
65-
<artifactId>spring-web</artifactId>
66-
<scope>test</scope>
67-
68-
<version>5.1.2.RELEASE</version>
69-
</dependency>
7076

7177
<!-- PROTON LIBRARY -->
7278
<dependency>
@@ -99,20 +105,20 @@
99105
<dependency>
100106
<groupId>org.eclipse.hono</groupId>
101107
<artifactId>hono-client</artifactId>
102-
<version>0.9</version>
108+
<version>1.0-M2</version>
103109
</dependency>
104110

105111
<dependency>
106112
<groupId>org.eclipse.hono</groupId>
107113
<artifactId>hono-demo-certs</artifactId>
108-
<version>0.9</version>
114+
<version>1.0-M2</version>
109115
<scope>provided</scope>
110116
</dependency>
111117

112118
<dependency>
113119
<groupId>org.eclipse.hono</groupId>
114120
<artifactId>hono-legal</artifactId>
115-
<version>0.9</version>
121+
<version>1.0-M2</version>
116122
<scope>provided</scope>
117123
</dependency>
118124

@@ -136,6 +142,19 @@
136142
<version>2.11.1</version>
137143
</dependency>
138144

145+
146+
<!-- STATIC LOGGER BINDER -->
147+
<dependency>
148+
<groupId>org.slf4j</groupId>
149+
<artifactId>slf4j-api</artifactId>
150+
<version>1.7.5</version>
151+
</dependency>
152+
<dependency>
153+
<groupId>org.slf4j</groupId>
154+
<artifactId>slf4j-log4j12</artifactId>
155+
<version>1.7.5</version>
156+
</dependency>
157+
139158
<!-- READ YAML FILE -->
140159
<dependency>
141160
<groupId>com.fasterxml.jackson.dataformat</groupId>
@@ -147,6 +166,12 @@
147166
<artifactId>jackson-databind</artifactId>
148167
<version>2.9.7</version>
149168
</dependency>
169+
<dependency>
170+
<groupId>org.springframework</groupId>
171+
<artifactId>spring-web</artifactId>
172+
<version>5.1.8.RELEASE</version>
173+
<scope>compile</scope>
174+
</dependency>
150175

151176
</dependencies>
152177

testing/src/main/java/org/eclipse/kuksa/testing/Application.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*********************************************************************
2-
* Copyright (c) 2019 Assystem GmbH [and others].
2+
* Copyright (c) 2019 Expleo GmbH [and others].
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
10-
* Contributors: Assystem GmbH
10+
* Contributors: Expleo GmbH
1111
**********************************************************************/
1212

1313
package org.eclipse.kuksa.testing;
@@ -17,7 +17,6 @@
1717

1818
@SpringBootApplication
1919
public class Application {
20-
2120
public static void main(String[] args) {
2221
SpringApplication.run(Application.class, args);
2322
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/**
2+
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*/
9+
package org.eclipse.kuksa.testing;
10+
11+
import java.io.ByteArrayOutputStream;
12+
import java.io.IOException;
13+
import java.io.InputStream;
14+
import java.io.OutputStream;
15+
import java.lang.reflect.Type;
16+
import java.nio.charset.Charset;
17+
import java.util.List;
18+
import java.util.Map.Entry;
19+
20+
import org.springframework.core.io.InputStreamResource;
21+
import org.springframework.http.HttpHeaders;
22+
import org.springframework.http.HttpOutputMessage;
23+
import org.springframework.http.MediaType;
24+
import org.springframework.http.converter.HttpMessageConverter;
25+
import org.springframework.util.LinkedMultiValueMap;
26+
import org.springframework.util.MultiValueMap;
27+
import org.springframework.web.client.RestTemplate;
28+
import org.springframework.web.multipart.MultipartFile;
29+
30+
import feign.RequestTemplate;
31+
import feign.codec.EncodeException;
32+
import feign.codec.Encoder;
33+
34+
/**
35+
* A feign encoder implementation which handles {@link MultipartFile} body.
36+
*/
37+
public class FeignMultipartEncoder implements Encoder {
38+
39+
private final List<HttpMessageConverter<?>> converters = new RestTemplate().getMessageConverters();
40+
private final HttpHeaders multipartHeaders = new HttpHeaders();
41+
private final HttpHeaders jsonHeaders = new HttpHeaders();
42+
43+
private static final Charset UTF_8 = Charset.forName("UTF-8");
44+
45+
public FeignMultipartEncoder() {
46+
multipartHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
47+
jsonHeaders.setContentType(MediaType.APPLICATION_JSON);
48+
}
49+
50+
@Override
51+
public void encode(final Object object, final Type bodyType, final RequestTemplate template) {
52+
encodeMultipartFormRequest(object, template);
53+
}
54+
55+
private void encodeMultipartFormRequest(final Object value, final RequestTemplate template) {
56+
if (value == null) {
57+
throw new EncodeException("Cannot encode request with null value.");
58+
}
59+
if (!isMultipartFile(value)) {
60+
throw new EncodeException("Only multipart can be handled by this encoder");
61+
}
62+
encodeRequest(encodeMultipartFile((MultipartFile) value), multipartHeaders, template);
63+
}
64+
65+
@SuppressWarnings("unchecked")
66+
private void encodeRequest(final Object value, final HttpHeaders requestHeaders, final RequestTemplate template) {
67+
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
68+
final HttpOutputMessage dummyRequest = new HttpOutputMessageImpl(outputStream, requestHeaders);
69+
try {
70+
final Class<?> requestType = value.getClass();
71+
final MediaType requestContentType = requestHeaders.getContentType();
72+
for (final HttpMessageConverter<?> messageConverter : converters) {
73+
if (messageConverter.canWrite(requestType, requestContentType)) {
74+
((HttpMessageConverter<Object>) messageConverter).write(value, requestContentType, dummyRequest);
75+
break;
76+
}
77+
}
78+
} catch (final IOException ex) {
79+
throw new EncodeException("Cannot encode request.", ex);
80+
}
81+
final HttpHeaders headers = dummyRequest.getHeaders();
82+
if (headers != null) {
83+
for (final Entry<String, List<String>> entry : headers.entrySet()) {
84+
template.header(entry.getKey(), entry.getValue());
85+
}
86+
}
87+
/*
88+
* we should use a template output stream... this will cause issues if
89+
* files are too big, since the whole request will be in memory.
90+
*/
91+
template.body(outputStream.toByteArray(), UTF_8);
92+
}
93+
94+
private MultiValueMap<String, Object> encodeMultipartFile(final MultipartFile file) {
95+
try {
96+
final MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
97+
multiValueMap.add("file", new MultipartFileResource(file.getName(), file.getSize(), file.getInputStream()));
98+
return multiValueMap;
99+
} catch (final IOException ex) {
100+
throw new EncodeException("Cannot encode request.", ex);
101+
}
102+
}
103+
104+
private static boolean isMultipartFile(final Object object) {
105+
return object instanceof MultipartFile;
106+
}
107+
108+
private static final class HttpOutputMessageImpl implements HttpOutputMessage {
109+
110+
private final OutputStream body;
111+
private final HttpHeaders headers;
112+
113+
private HttpOutputMessageImpl(final OutputStream body, final HttpHeaders headers) {
114+
this.body = body;
115+
this.headers = headers;
116+
}
117+
118+
@Override
119+
public OutputStream getBody() {
120+
return body;
121+
}
122+
123+
@Override
124+
public HttpHeaders getHeaders() {
125+
return headers;
126+
}
127+
128+
}
129+
130+
/**
131+
* Dummy resource class. Wraps file content and its original name.
132+
*/
133+
static class MultipartFileResource extends InputStreamResource {
134+
135+
private final String filename;
136+
private final long size;
137+
138+
public MultipartFileResource(final String filename, final long size, final InputStream inputStream) {
139+
super(inputStream);
140+
this.size = size;
141+
this.filename = filename;
142+
}
143+
144+
@Override
145+
public String getFilename() {
146+
return this.filename;
147+
}
148+
149+
@Override
150+
public long contentLength() {
151+
return size;
152+
}
153+
154+
}
155+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2018 Netas Telekomunikasyon A.S.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Adem Kose, Fatih Ayvaz and Ilker Kuzu (Netas Telekomunikasyon A.S.) - Initial functionality
12+
******************************************************************************/
13+
package org.eclipse.kuksa.testing;
14+
15+
import org.eclipse.kuksa.testing.config.HawkBitConfiguration;
16+
import org.springframework.cloud.openfeign.FeignClient;
17+
import org.springframework.web.bind.annotation.PathVariable;
18+
import org.springframework.web.bind.annotation.RequestMapping;
19+
import org.springframework.web.bind.annotation.RequestMethod;
20+
import org.springframework.web.multipart.MultipartFile;
21+
22+
import feign.Param;
23+
import feign.Response;
24+
25+
26+
@FeignClient(name = "feign-client", url = "http://hawkbit-appstacle.westeurope.cloudapp.azure.com:8080", configuration = HawkBitConfiguration.class)
27+
public interface HawkbitMultiPartFileFeignClient {
28+
29+
@RequestMapping(value = "rest/v1/softwaremodules/{softwareModuleId}/artifacts", method = RequestMethod.POST)
30+
Response uploadFile(@PathVariable("softwareModuleId") String softwareModuleId, @Param("file") MultipartFile file);
31+
32+
}

testing/src/main/java/org/eclipse/kuksa/testing/config/AppStoreConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/*********************************************************************
2-
* Copyright (c) 2019 Assystem GmbH [and others].
2+
* Copyright (c) 2019 Expleo GmbH [and others].
33
*
44
* This program and the accompanying materials are made
55
* available under the terms of the Eclipse Public License 2.0
66
* which is available at https://www.eclipse.org/legal/epl-2.0/
77
*
88
* SPDX-License-Identifier: EPL-2.0
99
*
10-
* Contributors: Assystem GmbH
10+
* Contributors: Expleo GmbH
1111
**********************************************************************/
1212

1313
package org.eclipse.kuksa.testing.config;

0 commit comments

Comments
 (0)