package no.nrk.panorama.serum;
import static org.fest.assertions.Assertions.assertThat;
import java.lang.annotation.Annotation;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.cxf.jaxrs.model.ParameterType;
import org.apache.cxf.jaxrs.utils.InjectionUtils;
import org.apache.cxf.message.MessageImpl;
import org.junit.Test;
public class CXFInjectionUtilsJUnitTest {
public static class Adapter extends XmlAdapter<String, Id> {
@Override
public String marshal(final Id id) throws Exception {
return id.getId();
}
@Override
public Id unmarshal(final String idStr) throws Exception {
Id id = new DelegatingId();
id.setId(idStr);
return id;
}
}
@XmlJavaTypeAdapter(Adapter.class)
public interface Id {
public String getId();
public void setId(String id);
}
public static class DelegatingId implements Id {
private String id;
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
}
@Test
public void handleParameter_givenValidInput_shouldReturnIdWithCorrectValue() throws Exception {
String value = "1.1";
Object id = InjectionUtils.handleParameter(value, true, Id.class, new Annotation[] {}, ParameterType.PATH,
new MessageImpl());
assertThat(id).isInstanceOf(Id.class);
assertThat(((Id)id).getId()).isEqualTo(value);
}
}