package jnpf.elnController;
|
|
import jnpf.elnEntity.runtime.ElnRecordVos;
|
import jnpf.elnService.ElnRecordQueryService;
|
import jnpf.util.context.SpringContext;
|
import org.junit.BeforeClass;
|
import org.junit.Test;
|
import org.springframework.context.support.StaticApplicationContext;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import java.lang.reflect.Method;
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertSame;
|
|
public class ElnRecordQueryControllerTest {
|
|
@BeforeClass
|
public static void setUpSpringContext() {
|
SpringContext.setApplicationContext(new StaticApplicationContext());
|
}
|
|
@Test
|
public void exposesSideEffectFreeLookupByTestWorkItem() throws Exception {
|
AtomicReference<String> captured = new AtomicReference<>();
|
ElnRecordVos.Created expected = new ElnRecordVos.Created();
|
ElnRecordQueryService service = testWorkItemId -> {
|
captured.set(testWorkItemId);
|
return expected;
|
};
|
ElnRecordQueryController controller = new ElnRecordQueryController(service);
|
|
assertSame(expected, controller.getByTestWorkItem("item-1").getData());
|
assertEquals("item-1", captured.get());
|
|
RequestMapping mapping = ElnRecordQueryController.class.getAnnotation(RequestMapping.class);
|
Method method = ElnRecordQueryController.class.getMethod("getByTestWorkItem", String.class);
|
assertEquals("/records", mapping.value()[0]);
|
assertEquals("/byTestWorkItem/{testWorkItemId}", method.getAnnotation(GetMapping.class).value()[0]);
|
assertEquals("testWorkItemId", method.getParameters()[0].getAnnotation(PathVariable.class).value());
|
}
|
}
|