package jnpf.limsController; import jnpf.lims.api.ElnSourceApi; import jnpf.lims.api.TestWorkItemSnapshotApi; import org.junit.Test; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import java.lang.reflect.Method; import static org.junit.Assert.assertFalse; public class LimsElnSourceApiPathNamingTest { @Test public void allLimsElnSourceApiPathsUseJavaCamelCaseSegments() { for (Class type : new Class[]{LimsElnSourceController.class, LimsElnSourceActorController.class, LimsTestWorkItemSnapshotController.class}) { RequestMapping mapping = type.getAnnotation(RequestMapping.class); assertPaths(type.getName(), mapping == null ? null : mapping.value()); assertMethodMappings(type); } for (Class type : new Class[]{ElnSourceApi.class, TestWorkItemSnapshotApi.class}) { FeignClient feign = type.getAnnotation(FeignClient.class); assertPaths(type.getName(), new String[]{feign.path()}); assertMethodMappings(type); } } private static void assertMethodMappings(Class type) { for (Method method : type.getDeclaredMethods()) { String owner = type.getName() + "#" + method.getName(); GetMapping get = method.getAnnotation(GetMapping.class); PostMapping post = method.getAnnotation(PostMapping.class); PutMapping put = method.getAnnotation(PutMapping.class); assertPaths(owner, get == null ? null : get.value()); assertPaths(owner, post == null ? null : post.value()); assertPaths(owner, put == null ? null : put.value()); } } private static void assertPaths(String owner, String[] paths) { if (paths == null) { return; } for (String path : paths) { assertFalse(owner + " contains a kebab-case API path: " + path, path.contains("-")); } } }