[rest] Fix links to group members in REST response (#2399)

* Fix links for to group members in REST response

Signed-off-by: Kai Kreuzer <kai@openhab.org>
pull/2404/head
Kai Kreuzer 2021-06-08 21:41:51 +02:00 committed by GitHub
parent 08632596b3
commit 3cac330c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -186,7 +186,7 @@ public class ItemResource implements RESTResource {
}
private UriBuilder uriBuilder(final UriInfo uriInfo, final HttpHeaders httpHeaders) {
final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder().path(PATH_ITEMS).path("{itemName}");
respectForwarded(uriBuilder, httpHeaders);
return uriBuilder;
}
@ -207,7 +207,6 @@ public class ItemResource implements RESTResource {
final Set<String> namespaces = splitAndFilterNamespaces(namespaceSelector, locale);
final UriBuilder uriBuilder = uriBuilder(uriInfo, httpHeaders);
uriBuilder.path("{itemName}");
Stream<EnrichedItemDTO> itemStream = getItems(type, tags).stream() //
.map(item -> EnrichedItemDTOMapper.map(item, recursive, null, uriBuilder, locale)) //

View File

@ -54,6 +54,7 @@ import org.openhab.core.library.items.DimmerItem;
import org.openhab.core.library.items.StringItem;
import org.openhab.core.library.items.SwitchItem;
import org.openhab.core.test.java.JavaOSGiTest;
import org.openhab.core.transform.TransformationException;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
@ -105,15 +106,17 @@ public class ItemResourceOSGiTest extends JavaOSGiTest {
UriBuilder uriBuilder = mock(UriBuilder.class);
when(uriBuilder.build(any())).thenReturn(URI.create(""));
when(uriBuilder.path(anyString())).thenReturn(uriBuilder);
uriInfo = mock(UriInfo.class);
when(uriInfo.getAbsolutePathBuilder()).thenReturn(uriBuilder);
when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
when(uriInfo.getPath()).thenReturn("");
httpHeaders = mock(HttpHeaders.class);
when(httpHeaders.getHeaderString(anyString())).thenReturn(null);
}
@Test
public void shouldReturnUnicodeItems() throws IOException {
public void shouldReturnUnicodeItems() throws IOException, TransformationException {
item4.setLabel(ITEM_LABEL4);
Response response = itemResource.getItems(uriInfo, httpHeaders, null, null, null, null, false, null);
@ -121,7 +124,7 @@ public class ItemResourceOSGiTest extends JavaOSGiTest {
}
@Test
public void shouldReturnUnicodeItem() throws IOException {
public void shouldReturnUnicodeItem() throws IOException, TransformationException {
item4.setLabel(ITEM_LABEL4);
Response response = itemResource.getItemData(uriInfo, httpHeaders, null, null, ITEM_NAME4);
@ -207,7 +210,7 @@ public class ItemResourceOSGiTest extends JavaOSGiTest {
return JsonPath.read(jsonResponse, "$..name");
}
private List<String> readItemLabelsFromResponse(Response response) throws IOException {
private List<String> readItemLabelsFromResponse(Response response) throws IOException, TransformationException {
String jsonResponse = new String(((InputStream) response.getEntity()).readAllBytes(), StandardCharsets.UTF_8);
return JsonPath.read(jsonResponse, "$..label");
}