RestClientModelTest.java
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.jersey.restclient;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by David Kral.
*/
public class RestClientModelTest extends JerseyTest {
@Override
protected ResourceConfig configure() {
enable(TestProperties.LOG_TRAFFIC);
return new ResourceConfig(ApplicationResourceImpl.class);
}
@Test
public void testGetIt() throws URISyntaxException {
ApplicationResource app = RestClientBuilder.newBuilder()
.baseUri(new URI("http://localhost:9998"))
.build(ApplicationResource.class);
List<String> collection = app.getValue();
assertEquals(2, collection.size());
assertEquals("This is default value!", collection.get(0));
assertEquals("Test", collection.get(1));
Map<String, String> map = app.getTestMap();
assertEquals(2, map.size());
assertEquals("firstValue", map.get("firstKey"));
assertEquals("secondValue", map.get("secondKey"));
assertEquals("Hi", app.sayHi());
}
@Test
public void testFormParam() throws URISyntaxException {
String response = RestClientBuilder.newBuilder()
.baseUri(new URI("http://localhost:9998"))
.build(ApplicationResource.class).formParam(null);
assertEquals("", response);
}
}