Skip to content

Commit 7cd8e42

Browse files
authored
Merge pull request #148 from OpenLiberty/qa
Merge qa to master: use default keystore (#131)
2 parents 7841d9a + 5fe595a commit 7cd8e42

File tree

6 files changed

+53
-17
lines changed

6 files changed

+53
-17
lines changed

README.adoc

+9-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ cd /home/project/guide-microprofile-metrics/start
235235
{: codeblock}
236236
endif::[]
237237

238-
include::{common-includes}/devmode-start.adoc[]
238+
include::{common-includes}/devmode-lmp33-start.adoc[]
239239

240240
The MicroProfile Metrics API is included in the MicroProfile dependency specified by your [hotspot file=0]`pom.xml` file.
241241
Look for the dependency with the [hotspot=microprofile file=0]`microprofile` artifact ID.
@@ -251,7 +251,8 @@ in your code to provide metrics from your microservices.
251251
The [hotspot=mpMetrics file=1]`mpMetrics` feature enables MicroProfile Metrics support in Open Liberty. Note that this
252252
feature requires SSL and the configuration has been provided for you.
253253

254-
The [hotspot=quickStartSecurity file=1]`quickStartSecurity` and [hotspot=keyStore file=1]`keyStore` configuration elements provide basic security to secure the server. When you visit the `/metrics` endpoint, use the credentials defined in the server configuration to log in and view the data.
254+
The [hotspot=quickStartSecurity file=1]`quickStartSecurity` configuration element provides basic security to secure the server.
255+
When you visit the `/metrics` endpoint, use the credentials defined in the server configuration to log in and view the data.
255256

256257
// =================================================================================================
257258
// Adding the annotations
@@ -474,13 +475,19 @@ Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.4 sec - in it.
474475
Running it.io.openliberty.guides.metrics.MetricsIT
475476
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.476 sec - in it.io.openliberty.guides.metrics.MetricsIT
476477
Running it.io.openliberty.guides.inventory.InventoryEndpointIT
478+
[WARNING ] Interceptor for {http://client.inventory.guides.openliberty.io/}SystemClient has thrown exception, unwinding now
479+
Could not send Message.
480+
[err] The specified host is unknown.
477481
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.264 sec - in it.io.openliberty.guides.inventory.InventoryEndpointIT
478482
479483
Results :
480484
481485
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
482486
----
483487

488+
The warning and error messages are expected and result from a request to a bad or an unknown hostname.
489+
This request is made in the `testUnknownHost()` test from the `InventoryEndpointIT` integration test.
490+
484491
To determine whether the tests detect a failure, go to the [hotspot file=0]`MetricsIT.java` file and change any of the assertions
485492
in the test methods. Then re-run the tests to see a test failure occur.
486493

finish/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<plugin>
8787
<groupId>io.openliberty.tools</groupId>
8888
<artifactId>liberty-maven-plugin</artifactId>
89-
<version>3.2.3</version>
89+
<version>3.3.3</version>
9090
</plugin>
9191
<!-- Plugin to run functional tests -->
9292
<plugin>

finish/src/main/liberty/config/server.xml

-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
<!-- tag::quickStartSecurity[] -->
1818
<quickStartSecurity userName="admin" userPassword="adminpwd"/>
1919
<!-- end::quickStartSecurity[] -->
20-
<!-- tag::keyStore[] -->
21-
<keyStore id="defaultKeyStore" location="key.jks" type="jks" password="mpKeystore"/>
22-
<!-- end::keyStore[] -->
2320
<httpEndpoint host="*" httpPort="${default.http.port}"
2421
httpsPort="${default.https.port}" id="defaultHttpEndpoint"/>
2522
<webApplication location="guide-microprofile-metrics.war" contextRoot="/"/>

finish/src/test/java/it/io/openliberty/guides/metrics/MetricsIT.java

+42-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// tag::copyright[]
22
/*******************************************************************************
3-
* Copyright (c) 2017, 2020 IBM Corporation and others.
3+
* Copyright (c) 2017, 2021 IBM Corporation and others.
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
66
* which accompanies this distribution, and is available at
@@ -13,17 +13,31 @@
1313
// tag::MetricsTest[]
1414
package it.io.openliberty.guides.metrics;
1515

16-
import static org.junit.jupiter.api.Assertions.*;
17-
import java.io.*;
18-
import java.util.*;
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertTrue;
18+
import static org.junit.jupiter.api.Assertions.fail;
19+
20+
import java.io.BufferedReader;
21+
import java.io.FileInputStream;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.InputStreamReader;
25+
import java.security.KeyStore;
26+
import java.util.ArrayList;
27+
import java.util.HashMap;
28+
import java.util.List;
29+
import java.util.Map;
30+
import java.util.Properties;
31+
1932
import javax.ws.rs.client.Client;
2033
import javax.ws.rs.client.ClientBuilder;
2134
import javax.ws.rs.core.MediaType;
2235
import javax.ws.rs.core.Response;
36+
2337
import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider;
2438
import org.junit.jupiter.api.AfterEach;
25-
import org.junit.jupiter.api.BeforeEach;
2639
import org.junit.jupiter.api.BeforeAll;
40+
import org.junit.jupiter.api.BeforeEach;
2741
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
2842
import org.junit.jupiter.api.Order;
2943
import org.junit.jupiter.api.Test;
@@ -33,10 +47,19 @@
3347
@TestMethodOrder(OrderAnnotation.class)
3448
// end::TestMethodOrder[]
3549
public class MetricsIT {
50+
51+
private static final String KEYSTORE_PATH = System.getProperty("user.dir")
52+
+ "/target/liberty/wlp/usr/servers/"
53+
+ "defaultServer/resources/security/key.p12";
54+
private static final String SYSTEM_ENV_PATH = System.getProperty("user.dir")
55+
+ "/target/liberty/wlp/usr/servers/"
56+
+ "defaultServer/server.env";
57+
3658
private static String httpPort;
3759
private static String httpsPort;
3860
private static String baseHttpUrl;
3961
private static String baseHttpsUrl;
62+
private static KeyStore keystore;
4063

4164
private List<String> metrics;
4265
private Client client;
@@ -49,20 +72,29 @@ public class MetricsIT {
4972
@BeforeAll
5073
// end::BeforeAll[]
5174
// tag::oneTimeSetup[]
52-
public static void oneTimeSetup() {
75+
public static void oneTimeSetup() throws Exception {
5376
httpPort = System.getProperty("http.port");
5477
httpsPort = System.getProperty("https.port");
5578
baseHttpUrl = "http://localhost:" + httpPort + "/";
5679
baseHttpsUrl = "https://localhost:" + httpsPort + "/";
80+
loadKeystore();
5781
}
5882
// end::oneTimeSetup[]
5983

84+
private static void loadKeystore() throws Exception {
85+
Properties sysEnv = new Properties();
86+
sysEnv.load(new FileInputStream(SYSTEM_ENV_PATH));
87+
char[] password = sysEnv.getProperty("keystore_password").toCharArray();
88+
keystore = KeyStore.getInstance("PKCS12");
89+
keystore.load(new FileInputStream(KEYSTORE_PATH), password);
90+
}
91+
6092
// tag::BeforeEach[]
6193
@BeforeEach
6294
// end::BeforeEach[]
6395
// tag::setup[]
6496
public void setup() {
65-
client = ClientBuilder.newClient();
97+
client = ClientBuilder.newBuilder().trustStore(keystore).build();
6698
// tag::JsrJsonpProvider[]
6799
client.register(JsrJsonpProvider.class);
68100
// end::JsrJsonpProvider[]
@@ -130,7 +162,7 @@ public void testInventoryAccessCountMetric() {
130162
// tag::testInventorySizeGaugeMetric[]
131163
public void testInventorySizeGaugeMetric() {
132164
metrics = getMetrics();
133-
Map<String, Integer> inventorySizeGauges = getIntMetrics(metrics,
165+
Map<String, Integer> inventorySizeGauges = getIntMetrics(metrics,
134166
"application_inventorySizeGauge");
135167
for (Integer value : inventorySizeGauges.values()) {
136168
assertTrue(1 <= value);
@@ -176,7 +208,7 @@ private List<String> getMetrics() {
176208
authorizationHeaderValue)
177209
.get();
178210

179-
BufferedReader br = new BufferedReader(new InputStreamReader((InputStream)
211+
BufferedReader br = new BufferedReader(new InputStreamReader((InputStream)
180212
metricsResponse.getEntity()));
181213
List<String> result = new ArrayList<String>();
182214
try {
@@ -201,7 +233,7 @@ private Response getResponse(String url) {
201233
private void assertResponse(String url, Response response) {
202234
assertEquals(200, response.getStatus(), "Incorrect response code from " + url);
203235
}
204-
236+
205237
private Map<String, Integer> getIntMetrics(List<String> metrics, String metricName) {
206238
Map<String, Integer> output = new HashMap<String, Integer>();
207239
for (String metric : metrics) {

start/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<plugin>
8787
<groupId>io.openliberty.tools</groupId>
8888
<artifactId>liberty-maven-plugin</artifactId>
89-
<version>3.2.3</version>
89+
<version>3.3.3</version>
9090
</plugin>
9191
<!-- Plugin to run functional tests -->
9292
<plugin>

start/src/main/liberty/config/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)