Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package com.mirth.connect.client.core.api.providers;

import javax.inject.Singleton;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;
import javax.ws.rs.ext.Provider;
Expand Down Expand Up @@ -49,7 +49,7 @@ public T fromString(String value) {
T result = (T) calendar;
return result;
} catch (DateTimeParseException e) {
throw new ProcessingException(e);
throw new BadRequestException("Invalid date '" + value + "'. Expected format yyyy-MM-dd'T'HH:mm:ss.SSSZ, for example 1985-10-26T09:00:00.000-0700.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Open Integration Engine Contributors

package com.mirth.connect.client.core.api.providers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;

import java.util.Calendar;

import javax.ws.rs.BadRequestException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ParamConverter;

import org.junit.BeforeClass;
import org.junit.Test;

public class CalendarParamConverterProviderTest {

private static ParamConverter<Calendar> converter;

@BeforeClass
public static void setup() {
converter = new CalendarParamConverterProvider().getConverter(Calendar.class, null, null);
}

@Test
public void testNullReturnsNull() {
assertNull(converter.fromString(null));
}

@Test
public void testValidDateRoundTrips() {
String value = "1985-10-26T09:00:00.000-0700";
Calendar calendar = converter.fromString(value);
assertNotNull(calendar);
assertEquals(value, converter.toString(calendar));
}

@Test
public void testInvalidDateThrowsBadRequest() {
try {
converter.fromString("1985");
fail("Expected BadRequestException for a malformed date");
} catch (BadRequestException e) {
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
}
}
}
Loading