1
+ /*******************************************************************************
2
+ * Copyright (c) 2024 IBM Corporation and others.
3
+ * All rights reserved. This program and the accompanying materials
4
+ * are made available under the terms of the Eclipse Public License v2.0
5
+ * which accompanies this distribution, and is available at
6
+ * https://www.eclipse.org/legal/epl-v20.html
7
+ *
8
+ * Contributors:
9
+ * IBM Corporation - initial API and implementation
10
+ *******************************************************************************/
11
+ package io .openliberty .sample .it ;
12
+
13
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
14
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
15
+
16
+ import java .io .StringReader ;
17
+ import java .net .URI ;
18
+ import java .util .concurrent .TimeUnit ;
19
+
20
+ import org .junit .jupiter .api .AfterAll ;
21
+ import org .junit .jupiter .api .BeforeAll ;
22
+ import org .junit .jupiter .api .Test ;
23
+
24
+ import jakarta .json .Json ;
25
+ import jakarta .json .JsonArray ;
26
+ import jakarta .json .JsonObject ;
27
+ import jakarta .json .JsonReader ;
28
+ import jakarta .ws .rs .client .Client ;
29
+ import jakarta .ws .rs .client .ClientBuilder ;
30
+ import jakarta .ws .rs .client .Entity ;
31
+ import jakarta .ws .rs .core .Response ;
32
+
33
+ public class MongoIT {
34
+
35
+ private static Client restClient ;
36
+
37
+
38
+ private static String baseURL ;
39
+
40
+ @ BeforeAll
41
+ public static void setup () throws Exception {
42
+ String port = System .getProperty ("http.port" );
43
+ baseURL = "http://localhost:" + port + "/db/crew/" ;
44
+
45
+ restClient = ClientBuilder .newClient ();
46
+ }
47
+
48
+ @ AfterAll
49
+ public static void teardown () throws Exception {
50
+ restClient .close ();
51
+ }
52
+
53
+ /**
54
+ * Calls the schedule endpoint, and confirms the first two messages over the
55
+ * websocket are available and increment.
56
+ */
57
+ @ Test
58
+ public void CreateRetrieveDeleteTest () throws InterruptedException {
59
+ //{"name":"Test","rank":"Captain","crewID":"12345"}
60
+ restClient .target (baseURL + "it" ).request ().post (Entity .json ("{\" name\" :\" Test\" ,\" rank\" :\" Captain\" ,\" crewID\" :\" 12345\" }" ));
61
+
62
+ Response response = restClient .target (baseURL ).request ().get ();
63
+ JsonReader reader = Json .createReader (new StringReader (response .readEntity (String .class )));
64
+ JsonArray array = reader .readArray ();
65
+ System .out .println (array );
66
+ }
67
+ }
0 commit comments