From ba7023f60c08fb0888f0a950bb2ddda584036313 Mon Sep 17 00:00:00 2001 From: Ralph Schaer Date: Fri, 10 Jan 2025 20:21:29 +0100 Subject: [PATCH] format --- .../bean/EdFormPostResult.java | 6 +- .../bean/ExtDirectResponseBuilder.java | 2 +- .../controller/RouterController.java | 34 +- .../extdirectspring/util/MethodInfo.java | 16 +- .../extdirectspring/util/ParameterInfo.java | 12 +- .../util/ParametersResolver.java | 8 +- .../annotation/ExtDirectMethodTypeTest.java | 87 +++-- .../bean/ExtDirectFormPostResultTest.java | 5 +- .../bean/ExtDirectResponseBuilderTest.java | 17 +- .../controller/ApiControllerTest.java | 319 +++++++++++++----- .../ApiControllerWithConfigurationTest.java | 297 ++++++++++++---- .../ApiControllerWithDocumentationTest.java | 30 +- .../ApiControllerWithXMLConfig1Test.java | 7 +- .../ApiControllerWithXMLConfig2Test.java | 7 +- .../ApiControllerWithXMLConfig3Test.java | 7 +- .../ApiControllerWithXMLConfig4Test.java | 7 +- .../controller/AppExceptionHandlerTest.java | 13 +- .../controller/ControllerUtil.java | 22 +- .../ExceptionHandlingConfigInXmlTest.java | 8 +- .../controller/ExceptionHandlingTest.java | 4 +- .../RouterControllerFilterTest.java | 2 +- .../RouterControllerFormLoadTest.java | 2 +- ...ntrollerFormPostCrossDomainUploadTest.java | 20 +- .../RouterControllerFormPostJsonTest.java | 26 +- .../RouterControllerFormPostTest.java | 37 +- .../RouterControllerMetadataTest.java | 53 +-- .../RouterControllerOptionalTest.java | 28 +- .../RouterControllerSimpleNamedTest.java | 6 +- .../RouterControllerStoreEdTest.java | 4 +- .../RouterControllerStoreModifyTest.java | 2 +- .../controller/RouterControllerStoreTest.java | 6 +- .../RouterControllerTreeLoadTest.java | 54 +-- .../provider/RemoteProviderOptional.java | 4 +- .../provider/RemoteProviderStoreRead.java | 11 +- .../store/CrudTestMethods.java | 26 +- .../util/MethodInfoCacheTest.java | 4 +- .../util/SupportedParametersTest.java | 10 +- .../view/StoreReadMethodService.java | 2 +- .../extdirectspring_itest/InfoController.java | 3 +- .../SecuredServiceTest.java | 2 +- .../SimpleServiceTest.java | 6 +- 41 files changed, 813 insertions(+), 403 deletions(-) diff --git a/src/main/java/ch/ralscha/extdirectspring/bean/EdFormPostResult.java b/src/main/java/ch/ralscha/extdirectspring/bean/EdFormPostResult.java index 97608b2c..b0be7206 100644 --- a/src/main/java/ch/ralscha/extdirectspring/bean/EdFormPostResult.java +++ b/src/main/java/ch/ralscha/extdirectspring/bean/EdFormPostResult.java @@ -60,8 +60,10 @@ public static EdFormPostResult create(BindingResult bindingResult) { } public static EdFormPostResult create(BindingResult bindingResult, boolean success) { - return ImmutableEdFormPostResult.builder().addErrors(null, null, bindingResult) - .putResult(SUCCESS_PROPERTY, success).build(); + return ImmutableEdFormPostResult.builder() + .addErrors(null, null, bindingResult) + .putResult(SUCCESS_PROPERTY, success) + .build(); } public static EdFormPostResult create(Locale locale, MessageSource messageSource, BindingResult bindingResult) { diff --git a/src/main/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilder.java b/src/main/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilder.java index caae0bbc..c983320b 100644 --- a/src/main/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilder.java +++ b/src/main/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilder.java @@ -223,7 +223,7 @@ public void buildAndWrite() { try { RouterController routerController = RequestContextUtils.findWebApplicationContext(this.request) - .getBean(RouterController.class); + .getBean(RouterController.class); routerController.writeJsonResponse(this.request, this.response, this.extDirectResponse, this.jsonView); diff --git a/src/main/java/ch/ralscha/extdirectspring/controller/RouterController.java b/src/main/java/ch/ralscha/extdirectspring/controller/RouterController.java index fa31c674..a76176e3 100644 --- a/src/main/java/ch/ralscha/extdirectspring/controller/RouterController.java +++ b/src/main/java/ch/ralscha/extdirectspring/controller/RouterController.java @@ -120,8 +120,8 @@ public void poll(@PathVariable("beanName") String beanName, @PathVariable("metho try { - Object[] parameters = this.configurationService.getParametersResolver().prepareParameters(request, - response, locale, methodInfo); + Object[] parameters = this.configurationService.getParametersResolver() + .prepareParameters(request, response, locale, methodInfo); if (this.configurationService.getConfiguration().isSynchronizeOnSession() || methodInfo.isSynchronizeOnSession()) { @@ -230,7 +230,7 @@ else if (methodInfo != null && methodInfo.getHandlerMethod() != null) { Map model = modelAndView.getModel(); if (model.containsKey("extDirectFormPostResult")) { ExtDirectFormPostResult formPostResult = (ExtDirectFormPostResult) model - .get("extDirectFormPostResult"); + .get("extDirectFormPostResult"); directResponse.setResult(formPostResult.getResult()); directResponse.setJsonView(getJsonView(formPostResult, methodInfo.getJsonView())); } @@ -260,8 +260,8 @@ else if (model.containsKey("edFormPostResult")) { consumes = MediaType.APPLICATION_JSON_VALUE) public void router(HttpServletRequest request, HttpServletResponse response, Locale locale) throws IOException { - Object requestData = this.configurationService.getJsonHandler().readValue(request.getInputStream(), - Object.class); + Object requestData = this.configurationService.getJsonHandler() + .readValue(request.getInputStream(), Object.class); List directRequests = null; if (requestData instanceof Map) { @@ -271,8 +271,8 @@ public void router(HttpServletRequest request, HttpServletResponse response, Loc else if (requestData instanceof List) { directRequests = new ArrayList<>(); for (Object oneRequest : (List) requestData) { - directRequests.add( - this.configurationService.getJsonHandler().convertValue(oneRequest, ExtDirectRequest.class)); + directRequests + .add(this.configurationService.getJsonHandler().convertValue(oneRequest, ExtDirectRequest.class)); } } @@ -281,11 +281,11 @@ else if (requestData instanceof List) { handleMethodCallOne(directRequests.get(0), request, response, locale); } else if (this.configurationService.getConfiguration() - .getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.SEQUENTIAL) { + .getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.SEQUENTIAL) { handleMethodCallsSequential(directRequests, request, response, locale); } else if (this.configurationService.getConfiguration() - .getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT) { + .getBatchedMethodsExecutionPolicy() == BatchedMethodsExecutionPolicy.CONCURRENT) { handleMethodCallsConcurrent(directRequests, request, response, locale); } } @@ -298,8 +298,8 @@ private void handleMethodCallsConcurrent(List directRequests, List> futures = new ArrayList<>(directRequests.size()); for (ExtDirectRequest directRequest : directRequests) { Callable callable = createMethodCallCallable(directRequest, request, response, locale); - futures.add( - this.configurationService.getConfiguration().getBatchedMethodsExecutorService().submit(callable)); + futures + .add(this.configurationService.getConfiguration().getBatchedMethodsExecutorService().submit(callable)); } ObjectMapper objectMapper = this.configurationService.getJsonHandler().getMapper(); @@ -315,7 +315,7 @@ private void handleMethodCallsConcurrent(List directRequests, } else { String jsonResult = objectMapper.writerWithView(jsonView) - .writeValueAsString(directResponse.getResult()); + .writeValueAsString(directResponse.getResult()); directResponses.add(new ExtDirectResponseRaw(directResponse, jsonResult)); } } @@ -371,7 +371,7 @@ private void handleMethodCallsSequential(List directRequests, } else { String jsonResult = objectMapper.writerWithView(jsonView) - .writeValueAsString(directResponse.getResult()); + .writeValueAsString(directResponse.getResult()); directResponses.add(new ExtDirectResponseRaw(directResponse, jsonResult)); } } @@ -559,8 +559,8 @@ public void writeJsonResponse(HttpServletResponse response, Object responseObjec jsonGenerator.close(); } else { - JsonGenerator jsonGenerator = objectMapper.getFactory().createGenerator(outputStream, - JsonEncoding.UTF8); + JsonGenerator jsonGenerator = objectMapper.getFactory() + .createGenerator(outputStream, JsonEncoding.UTF8); if (jsonView == null) { objectMapper.writeValue(jsonGenerator, responseObject); } @@ -577,8 +577,8 @@ public void writeJsonResponse(HttpServletResponse response, Object responseObjec private Object processRemotingRequest(HttpServletRequest request, HttpServletResponse response, Locale locale, ExtDirectRequest directRequest, MethodInfo methodInfo) throws Exception { - Object[] parameters = this.configurationService.getParametersResolver().resolveParameters(request, response, - locale, directRequest, methodInfo); + Object[] parameters = this.configurationService.getParametersResolver() + .resolveParameters(request, response, locale, directRequest, methodInfo); if (this.configurationService.getConfiguration().isSynchronizeOnSession() || methodInfo.isSynchronizeOnSession()) { diff --git a/src/main/java/ch/ralscha/extdirectspring/util/MethodInfo.java b/src/main/java/ch/ralscha/extdirectspring/util/MethodInfo.java index d88758a5..5a44e791 100644 --- a/src/main/java/ch/ralscha/extdirectspring/util/MethodInfo.java +++ b/src/main/java/ch/ralscha/extdirectspring/util/MethodInfo.java @@ -220,13 +220,13 @@ private Action extractDocumentationAnnotations(ExtDirectMethodDocumentation docu : docParameters.descriptions(); if (params.length == descriptions.length) { for (int i = 0; i < params.length; i++) { - actionDoc.getParameters().put(params[i], - descriptions[i] == null ? "No description" : descriptions[i]); + actionDoc.getParameters() + .put(params[i], descriptions[i] == null ? "No description" : descriptions[i]); } } else { - LogFactory.getLog(MethodInfo.class).info( - "Documentation: skip generation of parameters, params size is different from descriptions size"); + LogFactory.getLog(MethodInfo.class) + .info("Documentation: skip generation of parameters, params size is different from descriptions size"); } } ExtDirectDocReturn docReturn = documentation.returnMethod(); @@ -236,13 +236,13 @@ private Action extractDocumentationAnnotations(ExtDirectMethodDocumentation docu : docReturn.descriptions(); if (properties.length == descriptions.length) { for (int i = 0; i < properties.length; i++) { - actionDoc.getReturnMethod().put(properties[i], - descriptions[i] == null ? "No description" : descriptions[i]); + actionDoc.getReturnMethod() + .put(properties[i], descriptions[i] == null ? "No description" : descriptions[i]); } } else { - LogFactory.getLog(MethodInfo.class).info( - "Documentation: skip generation of return method properties, properties size is different from descriptions size"); + LogFactory.getLog(MethodInfo.class) + .info("Documentation: skip generation of return method properties, properties size is different from descriptions size"); } } return actionDoc; diff --git a/src/main/java/ch/ralscha/extdirectspring/util/ParameterInfo.java b/src/main/java/ch/ralscha/extdirectspring/util/ParameterInfo.java index 3e120427..805048c2 100644 --- a/src/main/java/ch/ralscha/extdirectspring/util/ParameterInfo.java +++ b/src/main/java/ch/ralscha/extdirectspring/util/ParameterInfo.java @@ -65,7 +65,7 @@ public ParameterInfo(Class clazz, Method method, int paramIndex) { MethodParameter methodParam = new MethodParameter(method, paramIndex); methodParam.initParameterNameDiscovery(discoverer); - + this.name = methodParam.getParameterName(); this.typeDescriptor = new TypeDescriptor(methodParam); @@ -129,10 +129,12 @@ else if (CookieValue.class.isInstance(paramAnn)) { this.hasCookieValueAnnotation = true; break; } - else if (paramAnn.annotationType().getName() - .equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal") - || paramAnn.annotationType().getName() - .equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) { + else if (paramAnn.annotationType() + .getName() + .equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal") + || paramAnn.annotationType() + .getName() + .equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) { this.hasAuthenticationPrincipalAnnotation = (Boolean) AnnotationUtils.getValue(paramAnn, "errorOnInvalidType"); } diff --git a/src/main/java/ch/ralscha/extdirectspring/util/ParametersResolver.java b/src/main/java/ch/ralscha/extdirectspring/util/ParametersResolver.java index 3be7ea9d..0a08a294 100644 --- a/src/main/java/ch/ralscha/extdirectspring/util/ParametersResolver.java +++ b/src/main/java/ch/ralscha/extdirectspring/util/ParametersResolver.java @@ -439,8 +439,8 @@ else if (this.conversionService.canConvert(TypeDescriptor.forObject(value), TypeFactory typeFactory = this.jsonHandler.getMapper().getTypeFactory(); if (methodParameter.getTypeDescriptor().isCollection()) { - JavaType elemType = typeFactory.constructType( - methodParameter.getTypeDescriptor().getElementTypeDescriptor().getType()); + JavaType elemType = typeFactory + .constructType(methodParameter.getTypeDescriptor().getElementTypeDescriptor().getType()); TypeVariable[] vars = rawType.getTypeParameters(); TypeBindings bindings; if (vars == null || vars.length != 1) { @@ -553,8 +553,8 @@ else if (key.equals("group") && value != null && (value instanceof List || value if (descriptor != null && descriptor.getWriteMethod() != null) { try { - descriptor.getWriteMethod().invoke(to, - this.conversionService.convert(value, descriptor.getPropertyType())); + descriptor.getWriteMethod() + .invoke(to, this.conversionService.convert(value, descriptor.getPropertyType())); foundParameters.add(key); } diff --git a/src/test/java/ch/ralscha/extdirectspring/annotation/ExtDirectMethodTypeTest.java b/src/test/java/ch/ralscha/extdirectspring/annotation/ExtDirectMethodTypeTest.java index 64d5548b..11e68cd7 100644 --- a/src/test/java/ch/ralscha/extdirectspring/annotation/ExtDirectMethodTypeTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/annotation/ExtDirectMethodTypeTest.java @@ -39,13 +39,17 @@ public class ExtDirectMethodTypeTest { @Test public void testSimpleIsValid() throws SecurityException { assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method1", RemoteProviderSimple.class, - findMethod(RemoteProviderSimple.class, "method1"))).isTrue(); + findMethod(RemoteProviderSimple.class, "method1"))) + .isTrue(); assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method2", RemoteProviderSimple.class, - findMethod(RemoteProviderSimple.class, "method2"))).isTrue(); + findMethod(RemoteProviderSimple.class, "method2"))) + .isTrue(); assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method3", RemoteProviderSimple.class, - findMethod(RemoteProviderSimple.class, "method3"))).isTrue(); + findMethod(RemoteProviderSimple.class, "method3"))) + .isTrue(); assertThat(ExtDirectMethodType.SIMPLE.isValid("remoteProviderSimple.method3WithError", - RemoteProviderSimple.class, findMethod(RemoteProviderSimple.class, "method3WithError"))).isFalse(); + RemoteProviderSimple.class, findMethod(RemoteProviderSimple.class, "method3WithError"))) + .isFalse(); } @Test @@ -53,7 +57,8 @@ public void testSimpleNamedIsValid() throws SecurityException { for (Method method : RemoteProviderSimpleNamed.class.getMethods()) { if (method.getName().startsWith("method")) { assertThat(ExtDirectMethodType.SIMPLE_NAMED.isValid("remoteProviderSimpleNamed." + method.getName(), - RemoteProviderSimpleNamed.class, method)).isTrue(); + RemoteProviderSimpleNamed.class, method)) + .isTrue(); } } } @@ -63,7 +68,8 @@ public void testFormLoadIsValid() throws SecurityException { for (Method method : RemoteProviderFormLoad.class.getMethods()) { if (method.getName().startsWith("method")) { assertThat(ExtDirectMethodType.FORM_LOAD.isValid("remoteProviderFormLoad." + method.getName(), - RemoteProviderFormLoad.class, method)).isTrue(); + RemoteProviderFormLoad.class, method)) + .isTrue(); } } } @@ -73,7 +79,8 @@ public void testStoreReadIsValid() throws SecurityException { for (Method method : RemoteProviderStoreRead.class.getMethods()) { if (method.getName().startsWith("method")) { assertThat(ExtDirectMethodType.STORE_READ.isValid("remoteProviderStoreRead." + method.getName(), - RemoteProviderStoreRead.class, method)).isTrue(); + RemoteProviderStoreRead.class, method)) + .isTrue(); } } } @@ -84,7 +91,8 @@ public void testStoreModifyIsValid() throws SecurityException { if (method.getName().startsWith("create") || method.getName().startsWith("update") || method.getName().startsWith("destroy")) { assertThat(ExtDirectMethodType.STORE_MODIFY.isValid("remoteProviderStoreModify." + method.getName(), - RemoteProviderStoreModify.class, method)).isTrue(); + RemoteProviderStoreModify.class, method)) + .isTrue(); } } @@ -93,38 +101,53 @@ public void testStoreModifyIsValid() throws SecurityException { @Test public void testFormPostIsValid() throws SecurityException { assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo1", - WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo1"))).isFalse(); + WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo1"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo2", - WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo2"))).isFalse(); + WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo2"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo3", - WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo3"))).isFalse(); + WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo3"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("wrongFormPostController.updateInfo4", - WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo4"))).isFalse(); + WrongFormPostController.class, findMethod(WrongFormPostController.class, "updateInfo4"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("uploadService.upload", UploadService.class, - findMethod(UploadService.class, "upload"))).isTrue(); + findMethod(UploadService.class, "upload"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("uploadService.uploadEd", UploadService.class, - findMethod(UploadService.class, "uploadEd"))).isTrue(); + findMethod(UploadService.class, "uploadEd"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.updateInfo1", FormInfoController2.class, - findMethod(FormInfoController2.class, "updateInfo1"))).isTrue(); + findMethod(FormInfoController2.class, "updateInfo1"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.updateInfo2", FormInfoController2.class, - findMethod(FormInfoController2.class, "updateInfo2"))).isTrue(); + findMethod(FormInfoController2.class, "updateInfo2"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController2.invalidMethod", FormInfoController2.class, - findMethod(FormInfoController2.class, "invalidMethod"))).isFalse(); + findMethod(FormInfoController2.class, "invalidMethod"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfo", FormInfoController.class, - findMethod(FormInfoController.class, "updateInfo"))).isTrue(); + findMethod(FormInfoController.class, "updateInfo"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.upload", FormInfoController.class, - findMethod(FormInfoController.class, "upload"))).isTrue(); + findMethod(FormInfoController.class, "upload"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.invalidMethod1", FormInfoController.class, - findMethod(FormInfoController.class, "invalidMethod1"))).isFalse(); + findMethod(FormInfoController.class, "invalidMethod1"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.invalidMethod2", FormInfoController.class, - findMethod(FormInfoController.class, "invalidMethod2"))).isFalse(); + findMethod(FormInfoController.class, "invalidMethod2"))) + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfoDirect", - FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirect"))).isTrue(); + FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirect"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST.isValid("formInfoController.updateInfoDirectEd", - FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirectEd"))).isTrue(); + FormInfoController.class, findMethod(FormInfoController.class, "updateInfoDirectEd"))) + .isTrue(); } @Test @@ -132,7 +155,8 @@ public void testTreeLoadIsValid() throws SecurityException { for (Method method : RemoteProviderTreeLoad.class.getMethods()) { if (method.getName().startsWith("method")) { assertThat(ExtDirectMethodType.TREE_LOAD.isValid("remoteProviderTreeLoad." + method.getName(), - RemoteProviderTreeLoad.class, method)).isTrue(); + RemoteProviderTreeLoad.class, method)) + .isTrue(); } } } @@ -142,7 +166,8 @@ public void testPollIsValid() throws SecurityException { for (Method method : PollProvider.class.getMethods()) { if (method.getName().startsWith("message") || method.getName().startsWith("handleMessage")) { assertThat(ExtDirectMethodType.POLL.isValid("pollProvider." + method.getName(), PollProvider.class, - method)).isTrue(); + method)) + .isTrue(); } } } @@ -150,26 +175,28 @@ public void testPollIsValid() throws SecurityException { @Test public void testFormPostJsonIsValid() throws SecurityException { assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJson", - FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJson"))).isTrue(); + FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJson"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJsonDirect", - FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirect"))).isTrue(); + FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirect"))) + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid("formInfoController3.updateInfoJsonDirectError", FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirectError"))) - .isTrue(); + .isTrue(); assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid( "formInfoController3.updateInfoJsonDirectNotRegisteredWithBindingResultAsParameter", FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirectNotRegisteredWithBindingResultAsParameter"))) - .isFalse(); + .isFalse(); assertThat(ExtDirectMethodType.FORM_POST_JSON.isValid( "formInfoController3.updateInfoJsonDirectNotRegisteredWithMultipartFileAsParameter", FormInfoController3.class, findMethod(FormInfoController3.class, "updateInfoJsonDirectNotRegisteredWithMultipartFileAsParameter"))) - .isFalse(); + .isFalse(); } diff --git a/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectFormPostResultTest.java b/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectFormPostResultTest.java index 2314c3a4..9828ecfd 100644 --- a/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectFormPostResultTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectFormPostResultTest.java @@ -123,8 +123,9 @@ public void testAddResultProperty() { result.addResultProperty("one", 1); result.addResultProperty("two", "2"); result.addResultProperty("three", Boolean.TRUE); - assertThat(result.getResult()).hasSize(4).contains(MapEntry.entry("success", Boolean.TRUE), - MapEntry.entry("one", 1), MapEntry.entry("two", "2"), MapEntry.entry("three", Boolean.TRUE)); + assertThat(result.getResult()).hasSize(4) + .contains(MapEntry.entry("success", Boolean.TRUE), MapEntry.entry("one", 1), MapEntry.entry("two", "2"), + MapEntry.entry("three", Boolean.TRUE)); } diff --git a/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilderTest.java b/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilderTest.java index c925bbfb..66c3fe1f 100644 --- a/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilderTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/bean/ExtDirectResponseBuilderTest.java @@ -51,8 +51,9 @@ public void testBuilder() { MockHttpServletRequest request = createRequest(); MockHttpServletResponse servletResponse = new MockHttpServletResponse(); - ExtDirectResponseBuilder.create(request, servletResponse).addResultProperty("additionalProperty", 11) - .buildAndWrite(); + ExtDirectResponseBuilder.create(request, servletResponse) + .addResultProperty("additionalProperty", 11) + .buildAndWrite(); ExtDirectResponse response = ControllerUtil.readDirectResponse(servletResponse.getContentAsByteArray()); assertThat(response.getAction()).isEqualTo("action"); @@ -70,8 +71,10 @@ public void testBuilder() { assertThat(data.get("success")).isEqualTo(Boolean.TRUE); servletResponse = new MockHttpServletResponse(); - ExtDirectResponseBuilder.create(request, servletResponse).unsuccessful() - .addResultProperty("additionalProperty", 9).buildAndWrite(); + ExtDirectResponseBuilder.create(request, servletResponse) + .unsuccessful() + .addResultProperty("additionalProperty", 9) + .buildAndWrite(); response = ControllerUtil.readDirectResponse(servletResponse.getContentAsByteArray()); data = (Map) response.getResult(); assertThat(data).hasSize(2); @@ -91,8 +94,10 @@ public void testBuilderUploadResponse() throws IOException { request.setParameter("extTID", "1"); MockHttpServletResponse servletResponse = new MockHttpServletResponse(); - ExtDirectResponseBuilder.create(request, servletResponse).addResultProperty("additionalProperty", Boolean.FALSE) - .addResultProperty("text", "a lot of "text"").buildAndWrite(); + ExtDirectResponseBuilder.create(request, servletResponse) + .addResultProperty("additionalProperty", Boolean.FALSE) + .addResultProperty("text", "a lot of "text"") + .buildAndWrite(); assertThat(servletResponse.getContentType()).isEqualTo("text/html;charset=UTF-8"); String content = servletResponse.getContentAsString(); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerTest.java index 654f677f..d7e48150 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerTest.java @@ -93,8 +93,11 @@ public void setupApiController() throws Exception { @Test public void testNoActionNamespaceDebugDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("remotingApiVar") - .pollingUrlsVar("pollingUrlsVar").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("remotingApiVar") + .pollingUrlsVar("pollingUrlsVar") + .build(); runTest(this.mockMvc, params, allApis(null)); } @@ -107,15 +110,23 @@ public void testNoActionNamespaceDebugCustomConfig() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("testC").remotingApiVar("remotingApiV") - .pollingUrlsVar("pollingUrlsV").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("testC") + .remotingApiVar("remotingApiV") + .pollingUrlsVar("pollingUrlsV") + .configuration(config) + .build(); runTest(this.mockMvc, params, allApis(null)); } @Test public void testWithActionNamespaceDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .build(); runTest(this.mockMvc, params, allApis("actionns")); } @@ -128,22 +139,35 @@ public void testWithActionNamespaceCustomConfig() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .configuration(config) + .build(); runTest(this.mockMvc, params, allApis("actionns")); } @Test public void testEmptyGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("") + .build(); runTest(this.mockMvc, params, emptyGroupApis(null)); } @Test public void testBlankStringGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .build(); runTest(this.mockMvc, params, emptyGroupApis(null)); } @@ -155,8 +179,13 @@ public void testEmptyGroupCustomConfig() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("") + .configuration(config) + .build(); runTest(this.mockMvc, params, emptyGroupApis(null)); } @@ -168,8 +197,13 @@ public void testBlankStringGroupCustomConfig() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .configuration(config) + .build(); runTest(this.mockMvc, params, emptyGroupApis(null)); } @@ -182,16 +216,25 @@ public void testBlankStringGroupCustomConfigBufferLimit() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .configuration(config) + .build(); runTest(this.mockMvc, params, emptyGroupApis(null)); } @Test public void testUnknownGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("xy").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("xy") + .build(); runTest(this.mockMvc, params, noApis(null)); } @@ -202,8 +245,13 @@ public void testUnknownGroupCustomConfig() throws Exception { ReflectionTestUtils.setField(this.configurationService, "configuration", config); this.configurationService.afterPropertiesSet(); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("xy").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("xy") + .configuration(config) + .build(); runTest(this.mockMvc, params, noApis(null)); } @@ -231,8 +279,12 @@ public void testGroup1WithConfig() throws Exception { } private void testGroup1(Configuration config, String fingerprint) throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1") - .configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1") + .configuration(config) + .build(); doTest("/api-debug-doc.js", params, group1Apis("actionns")); doTest("/api-debug.js", params, group1Apis("actionns")); @@ -250,7 +302,7 @@ private void testGroup1(Configuration config, String fingerprint) throws Excepti String expiresHeader = (String) response.getHeaderValue("Expires"); DateTimeFormatter fmt = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z") - .withLocale(Locale.ENGLISH); + .withLocale(Locale.ENGLISH); LocalDateTime expires = LocalDateTime.parse(expiresHeader, fmt); LocalDateTime inSixMonths = LocalDateTime.now(ZoneOffset.UTC).plusSeconds(6 * 30 * 24 * 60 * 60); @@ -264,116 +316,211 @@ private void testGroup1(Configuration config, String fingerprint) throws Excepti @Test public void testGroup2() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group2").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group2") + .build(); runTest(this.mockMvc, params, group2Apis(null)); runTest(this.mockMvc, params, group2Apis(null)); } @Test public void testGroup3() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Extns").actionNs("ns").remotingApiVar("RAPI") - .pollingUrlsVar("PURLS").group("group3").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Extns") + .actionNs("ns") + .remotingApiVar("RAPI") + .pollingUrlsVar("PURLS") + .group("group3") + .build(); runTest(this.mockMvc, params, group3Apis("ns")); runTest(this.mockMvc, params, group3Apis("ns")); } @Test public void testGroup4() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").actionNs("") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); runTest(this.mockMvc, params, group4Apis(null)); - params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); runTest(this.mockMvc, params, group4Apis(null)); } @Test public void testGroup1and2() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1,group2") - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1,group2") + .build(); runTest(this.mockMvc, params, group1and2Apis("actionns")); } @Test public void testGroup1andUnknown() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .group("group1,unknown").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1,unknown") + .build(); runTest(this.mockMvc, params, group1Apis("actionns")); } @Test public void testInterfaceGroup() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").actionNs("") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").group("interface").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("interface") + .build(); runTest(this.mockMvc, params, interfaceApis(null)); - params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("interface").build(); + params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("interface") + .build(); runTest(this.mockMvc, params, interfaceApis(null)); } @Test public void testNoApiNs() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("").actionNs("").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); runTest(this.mockMvc, params, group4Apis(null)); - params = ApiRequestParams.builder().apiNs("").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + params = ApiRequestParams.builder() + .apiNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); runTest(this.mockMvc, params, group4Apis(null)); } @Test public void testFullRouterUrl() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("apiNs").actionNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.TRUE).group("group2").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("apiNs") + .actionNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.TRUE) + .group("group2") + .build(); runTest(this.mockMvc, params, group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.TRUE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.TRUE) + .group("group2") + .build(); runTest(this.mockMvc, params, group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().apiNs("apiNs").actionNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.FALSE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .actionNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.FALSE) + .group("group2") + .build(); runTest(this.mockMvc, params, group2Apis(null, "/router")); - params = ApiRequestParams.builder().apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.FALSE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.FALSE) + .group("group2") + .build(); runTest(this.mockMvc, params, group2Apis(null, "/router")); } @Test public void testFormat() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").group("group2").format("json").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .group("group2") + .format("json") + .build(); runTest(this.mockMvc, params, group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().actionNs("ns").apiNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").group("group2").format("json").fullRouterUrl(Boolean.TRUE).build(); + params = ApiRequestParams.builder() + .actionNs("ns") + .apiNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .group("group2") + .format("json") + .fullRouterUrl(Boolean.TRUE) + .build(); runTest(this.mockMvc, params, group2Apis("ns", "http://localhost/router")); } @Test public void testBaseRouterUrl() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").baseRouterUrl("test").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .baseRouterUrl("test") + .build(); runTest(this.mockMvc, params, group2Apis(null, "test/router")); } @Test public void testBaseRouterUrlWithEndingSlash() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").fullRouterUrl(Boolean.TRUE).baseRouterUrl("service/test/") - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .fullRouterUrl(Boolean.TRUE) + .baseRouterUrl("service/test/") + .build(); runTest(this.mockMvc, params, group2Apis(null, "service/test/router")); } @Test public void testBaseRouterUrlEmptyString() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").baseRouterUrl("").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .baseRouterUrl("") + .build(); runTest(this.mockMvc, params, group2Apis(null, "/router")); } @@ -424,8 +571,10 @@ else if (params.getConfiguration() != null) { contentType = params.getConfiguration().getJsContentType(); } - MvcResult result = mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(contentType)).andReturn(); + MvcResult result = mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(contentType)) + .andReturn(); if ("json".equals(params.getFormat())) { compareJson(result, expectedApi, params); @@ -792,30 +941,30 @@ public static RemotingApi allApis(String namespace) { remotingApi.addPollingProvider(new PollingProvider("pollProvider", "handleMessage4", "message4")); remotingApi.addPollingProvider(new PollingProvider("pollProvider", "handleMessage5", "message5")); remotingApi.addPollingProvider(new PollingProvider("pollProvider", "message6", "message6")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader1", "messageRequestHeader1")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader2", "messageRequestHeader2")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader3", "messageRequestHeader3")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader4", "messageRequestHeader4")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader5", "messageRequestHeader5")); - remotingApi.addPollingProvider( - new PollingProvider("pollProvider", "messageRequestHeader6", "messageRequestHeader6")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue1", "messageCookieValue1")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader1", "messageRequestHeader1")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue2", "messageCookieValue2")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader2", "messageRequestHeader2")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue3", "messageCookieValue3")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader3", "messageRequestHeader3")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue4", "messageCookieValue4")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader4", "messageRequestHeader4")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue5", "messageCookieValue5")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader5", "messageRequestHeader5")); remotingApi - .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue6", "messageCookieValue6")); + .addPollingProvider(new PollingProvider("pollProvider", "messageRequestHeader6", "messageRequestHeader6")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue1", "messageCookieValue1")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue2", "messageCookieValue2")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue3", "messageCookieValue3")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue4", "messageCookieValue4")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue5", "messageCookieValue5")); + remotingApi + .addPollingProvider(new PollingProvider("pollProvider", "messageCookieValue6", "messageCookieValue6")); remotingApi.addAction("remoteProviderOptional", Action.create("method1", 3)); remotingApi.addAction("remoteProviderOptional", Action.create("method2", 1)); @@ -1040,7 +1189,7 @@ static void compare(MvcResult result, RemotingApi remotingApi, ApiRequestParams if (params.getConfiguration() == null || !params.getConfiguration().isStreamResponse()) { assertThat(result.getResponse().getContentLength()) - .isEqualTo(result.getResponse().getContentAsByteArray().length); + .isEqualTo(result.getResponse().getContentAsByteArray().length); } compare(result.getResponse().getContentAsString(), result.getResponse().getContentType(), remotingApi, params); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithConfigurationTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithConfigurationTest.java index 94c533a2..50da2d65 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithConfigurationTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithConfigurationTest.java @@ -123,8 +123,11 @@ private void updateConfiguration(ApiRequestParams params, Configuration preConfi @Test public void testNoActionNamespaceDebugDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("remotingApiVar") - .pollingUrlsVar("pollingUrlsVar").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("remotingApiVar") + .pollingUrlsVar("pollingUrlsVar") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.allApis(null)); @@ -137,8 +140,12 @@ public void testNoActionNamespaceDebugCustomConfig() throws Exception { config.setMaxRetries(2); config.setTimeout(12000); - ApiRequestParams params = ApiRequestParams.builder().apiNs("testC").remotingApiVar("remotingApiV") - .pollingUrlsVar("pollingUrlsV").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("testC") + .remotingApiVar("remotingApiV") + .pollingUrlsVar("pollingUrlsV") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.allApis(null)); @@ -146,8 +153,12 @@ public void testNoActionNamespaceDebugCustomConfig() throws Exception { @Test public void testWithActionNamespaceDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.allApis("actionns")); } @@ -158,24 +169,37 @@ public void testWithActionNamespaceCustomConfig() throws Exception { config.setEnableBuffer(Boolean.FALSE); config.setTimeout(10000); - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.allApis("actionns")); } @Test public void testEmptyGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.emptyGroupApis(null)); } @Test public void testBlankStringGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.emptyGroupApis(null)); } @@ -186,8 +210,13 @@ public void testEmptyGroupCustomConfig() throws Exception { config.setEnableBuffer(Boolean.TRUE); config.setTimeout(33333); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.emptyGroupApis(null)); } @@ -199,8 +228,13 @@ public void testBlankStringGroupCustomConfig() throws Exception { config.setTimeout(33333); config.setBufferLimit(null); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.emptyGroupApis(null)); } @@ -212,16 +246,25 @@ public void testBlankStringGroupCustomConfigBufferLimit() throws Exception { config.setTimeout(222); config.setBufferLimit(5); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group(" ").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group(" ") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.emptyGroupApis(null)); } @Test public void testUnknownGroupDefaultConfig() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("xy").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("xy") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.noApis(null)); } @@ -231,16 +274,25 @@ public void testUnknownGroupCustomConfig() throws Exception { Configuration config = new Configuration(); config.setEnableBuffer(Boolean.TRUE); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("xy").configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("xy") + .configuration(config) + .build(); updateConfiguration(params, config); runTest(this.mockMvc, params, ApiControllerTest.noApis(null)); } @Test public void testGroup1() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1") - .configuration(null).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1") + .configuration(null) + .build(); updateConfiguration(params, null); testGroup1(null, null); @@ -255,8 +307,12 @@ public void testGroup1() throws Exception { public void testGroup1WithConfig() throws Exception { Configuration config = new Configuration(); config.setTimeout(12000); - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1") - .configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1") + .configuration(config) + .build(); updateConfiguration(params, config); testGroup1(config, null); @@ -266,8 +322,12 @@ public void testGroup1WithConfig() throws Exception { } private void testGroup1(Configuration config, String fingerprint) throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1") - .configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1") + .configuration(config) + .build(); doTest("/api-debug-doc.js", params, ApiControllerTest.group1Apis("actionns")); doTest("/api-debug.js", params, ApiControllerTest.group1Apis("actionns")); @@ -286,7 +346,7 @@ private void testGroup1(Configuration config, String fingerprint) throws Excepti String expiresHeader = (String) response.getHeaderValue("Expires"); DateTimeFormatter fmt = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z") - .withLocale(Locale.ENGLISH); + .withLocale(Locale.ENGLISH); LocalDateTime expires = LocalDateTime.parse(expiresHeader, fmt); LocalDateTime inSixMonths = LocalDateTime.now(ZoneOffset.UTC).plusSeconds(6 * 30 * 24 * 60 * 60); @@ -300,8 +360,12 @@ private void testGroup1(Configuration config, String fingerprint) throws Excepti @Test public void testGroup2() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group2").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); @@ -309,8 +373,13 @@ public void testGroup2() throws Exception { @Test public void testGroup3() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Extns").actionNs("ns").remotingApiVar("RAPI") - .pollingUrlsVar("PURLS").group("group3").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Extns") + .actionNs("ns") + .remotingApiVar("RAPI") + .pollingUrlsVar("PURLS") + .group("group3") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group3Apis("ns")); runTest(this.mockMvc, params, ApiControllerTest.group3Apis("ns")); @@ -318,115 +387,201 @@ public void testGroup3() throws Exception { @Test public void testGroup4() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").actionNs("") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group4Apis(null)); - params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); runTest(this.mockMvc, params, ApiControllerTest.group4Apis(null)); } @Test public void testGroup1and2() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1,group2") - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1,group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group1and2Apis("actionns")); } @Test public void testGroup1andUnknown() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns") - .group("group1,unknown").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("group1,unknown") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group1Apis("actionns")); } @Test public void testInterfaceGroup() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").actionNs("") - .remotingApiVar("TEST_REMOTING_API").pollingUrlsVar("TEST_POLLING_URLS").group("interface").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("interface") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.interfaceApis(null)); - params = ApiRequestParams.builder().apiNs("test").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("interface").build(); + params = ApiRequestParams.builder() + .apiNs("test") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("interface") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.interfaceApis(null)); } @Test public void testNoApiNs() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("").actionNs("").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("") + .actionNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group4Apis(null)); - params = ApiRequestParams.builder().apiNs("").remotingApiVar("TEST_REMOTING_API") - .pollingUrlsVar("TEST_POLLING_URLS").group("group4").build(); + params = ApiRequestParams.builder() + .apiNs("") + .remotingApiVar("TEST_REMOTING_API") + .pollingUrlsVar("TEST_POLLING_URLS") + .group("group4") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group4Apis(null)); } @Test public void testFullRouterUrl() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("apiNs").actionNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.TRUE).group("group2").build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("apiNs") + .actionNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.TRUE) + .group("group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.TRUE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.TRUE) + .group("group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().apiNs("apiNs").actionNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.FALSE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .actionNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.FALSE) + .group("group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "/router")); - params = ApiRequestParams.builder().apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").fullRouterUrl(Boolean.FALSE).group("group2").build(); + params = ApiRequestParams.builder() + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .fullRouterUrl(Boolean.FALSE) + .group("group2") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "/router")); } @Test public void testFormat() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("apiNs").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").group("group2").format("json").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("apiNs") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .group("group2") + .format("json") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "http://localhost/router")); - params = ApiRequestParams.builder().actionNs("ns").apiNs("").remotingApiVar("TEST_RMT_API") - .pollingUrlsVar("TEST_POLL_URLS").group("group2").format("json").fullRouterUrl(Boolean.TRUE).build(); + params = ApiRequestParams.builder() + .actionNs("ns") + .apiNs("") + .remotingApiVar("TEST_RMT_API") + .pollingUrlsVar("TEST_POLL_URLS") + .group("group2") + .format("json") + .fullRouterUrl(Boolean.TRUE) + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis("ns", "http://localhost/router")); } @Test public void testBaseRouterUrl() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").baseRouterUrl("test").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .baseRouterUrl("test") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "test/router")); } @Test public void testBaseRouterUrlWithEndingSlash() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").fullRouterUrl(Boolean.TRUE).baseRouterUrl("service/test/") - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .fullRouterUrl(Boolean.TRUE) + .baseRouterUrl("service/test/") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "service/test/router")); } @Test public void testBaseRouterUrlEmptyString() throws Exception { - ApiRequestParams params = ApiRequestParams.builder().actionNs("").apiNs("an").remotingApiVar("rapi") - .pollingUrlsVar("papi").group("group2").baseRouterUrl("").build(); + ApiRequestParams params = ApiRequestParams.builder() + .actionNs("") + .apiNs("an") + .remotingApiVar("rapi") + .pollingUrlsVar("papi") + .group("group2") + .baseRouterUrl("") + .build(); updateConfiguration(params, null); runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null, "/router")); } @@ -460,8 +615,10 @@ else if (params.getConfiguration() != null) { contentType = params.getConfiguration().getJsContentType(); } - MvcResult result = mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith(contentType)).andReturn(); + MvcResult result = mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(contentType)) + .andReturn(); if ("json".equals(params.getFormat())) { ApiControllerTest.compareJson(result, expectedApi, params); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithDocumentationTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithDocumentationTest.java index 5660de50..a1020dde 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithDocumentationTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithDocumentationTest.java @@ -247,15 +247,21 @@ public void testRequestToApiDoesNotContainDocs() throws Exception { } private void doRequestWithoutDocs(String url) throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("doc") - .configuration(this.configurationService.getConfiguration()).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("doc") + .configuration(this.configurationService.getConfiguration()) + .build(); MockHttpServletRequestBuilder request = get(url).accept(MediaType.ALL).characterEncoding("UTF-8"); request.param("apiNs", params.getApiNs()); request.param("actionNs", params.getActionNs()); request.param("group", params.getGroup()); - MvcResult result = this.mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith("application/javascript")).andReturn(); + MvcResult result = this.mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith("application/javascript")) + .andReturn(); ApiControllerTest.compare(result, ApiControllerTest.groupApisWithDoc("actionns"), params); Assert.doesNotContain("/**", result.getResponse().getContentAsString(), @@ -263,16 +269,22 @@ private void doRequestWithoutDocs(String url) throws Exception { } private ActionDoc callApi(String method) throws Exception { - ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("doc") - .configuration(this.configurationService.getConfiguration()).build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("Ext.ns") + .actionNs("actionns") + .group("doc") + .configuration(this.configurationService.getConfiguration()) + .build(); MockHttpServletRequestBuilder request = get("/api-debug-doc.js").accept(MediaType.ALL) - .characterEncoding("UTF-8"); + .characterEncoding("UTF-8"); request.param("apiNs", params.getApiNs()); request.param("actionNs", params.getActionNs()); request.param("group", params.getGroup()); - MvcResult result = this.mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith("application/javascript")).andReturn(); + MvcResult result = this.mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith("application/javascript")) + .andReturn(); ApiControllerTest.compare(result, ApiControllerTest.groupApisWithDoc("actionns"), params); ActionDoc doc = getCommentForMethod(result.getResponse().getContentAsString(), method); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig1Test.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig1Test.java index f8adaf2d..553b266b 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig1Test.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig1Test.java @@ -56,8 +56,11 @@ public void testGroup1() throws Exception { config.setMaxRetries(5); config.setStreamResponse(true); - ApiRequestParams params = ApiRequestParams.builder().group("group1").configuration(config) - .providerType("websocket").build(); + ApiRequestParams params = ApiRequestParams.builder() + .group("group1") + .configuration(config) + .providerType("websocket") + .build(); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group1Apis(null)); } diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig2Test.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig2Test.java index 96507483..aa268208 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig2Test.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig2Test.java @@ -56,8 +56,11 @@ public void testGroup2() throws Exception { config.setMaxRetries(6); config.setStreamResponse(false); - ApiRequestParams params = ApiRequestParams.builder().remotingApiVar("TEST_REMOTING_API").group("group2") - .configuration(config).build(); + ApiRequestParams params = ApiRequestParams.builder() + .remotingApiVar("TEST_REMOTING_API") + .group("group2") + .configuration(config) + .build(); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig3Test.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig3Test.java index 9e6e94d1..0561f068 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig3Test.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig3Test.java @@ -56,8 +56,11 @@ public void testGroup2() throws Exception { config.setMaxRetries(6); config.setStreamResponse(true); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").group("group2").configuration(config) - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .group("group2") + .configuration(config) + .build(); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig4Test.java b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig4Test.java index 9c269134..25340a58 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig4Test.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ApiControllerWithXMLConfig4Test.java @@ -57,8 +57,11 @@ public void testGroup2() throws Exception { config.setStreamResponse(true); config.setBufferLimit(3); - ApiRequestParams params = ApiRequestParams.builder().apiNs("test").group("group2").configuration(config) - .build(); + ApiRequestParams params = ApiRequestParams.builder() + .apiNs("test") + .group("group2") + .configuration(config) + .build(); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); ApiControllerTest.runTest(this.mockMvc, params, ApiControllerTest.group2Apis(null)); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/AppExceptionHandlerTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/AppExceptionHandlerTest.java index 5778a382..b09fca39 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/AppExceptionHandlerTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/AppExceptionHandlerTest.java @@ -59,7 +59,7 @@ public void testExceptionInMapping() throws Exception { new Object[] { 3, "xxx", "string.param" }); MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -80,7 +80,7 @@ public void testBeanOrMethodNotFound() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -100,7 +100,7 @@ public void testExceptionInMappingWithNullValue() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -119,7 +119,7 @@ public void testExceptionNotInMapping() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -136,8 +136,9 @@ public void testExceptionNotInMapping() throws Exception { @Test public void testSendTextPlainRequest() throws Exception { - MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL).contentType(MediaType.TEXT_PLAIN) - .characterEncoding("UTF-8"); + MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL) + .contentType(MediaType.TEXT_PLAIN) + .characterEncoding("UTF-8"); String edsRequest = ControllerUtil.createEdsRequest("remoteProviderSimple", "method1", false, 1, null, null); request.content(edsRequest); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ControllerUtil.java b/src/test/java/ch/ralscha/extdirectspring/controller/ControllerUtil.java index 967e9795..d3627868 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ControllerUtil.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ControllerUtil.java @@ -75,7 +75,8 @@ public static ExtDirectPollResponse performPollRequest(MockMvc mockMvc, String b Map params, HttpHeaders headers, List cookies, boolean withSession) throws Exception { MockHttpServletRequestBuilder request = post("/poll/" + bean + "/" + method + "/" + event).accept(MediaType.ALL) - .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8"); + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding("UTF-8"); if (cookies != null) { request.cookie(cookies.toArray(new Cookie[cookies.size()])); @@ -95,9 +96,11 @@ public static ExtDirectPollResponse performPollRequest(MockMvc mockMvc, String b request.headers(headers); } - MvcResult result = mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith("application/json;charset=UTF-8")) - .andExpect(content().encoding("UTF-8")).andReturn(); + MvcResult result = mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith("application/json;charset=UTF-8")) + .andExpect(content().encoding("UTF-8")) + .andReturn(); return readDirectPollResponse(result.getResponse().getContentAsByteArray()); } @@ -110,7 +113,8 @@ public static MvcResult performRouterRequest(MockMvc mockMvc, String content, Ma HttpHeaders headers, List cookies, boolean withSession) throws Exception { MockHttpServletRequestBuilder request = post("/router").accept(MediaType.ALL) - .contentType(MediaType.APPLICATION_JSON).characterEncoding("UTF-8"); + .contentType(MediaType.APPLICATION_JSON) + .characterEncoding("UTF-8"); if (cookies != null) { request.cookie(cookies.toArray(new Cookie[cookies.size()])); @@ -135,9 +139,11 @@ public static MvcResult performRouterRequest(MockMvc mockMvc, String content, Ma request.headers(headers); } - return mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith("application/json;charset=UTF-8")) - .andExpect(content().encoding("UTF-8")).andReturn(); + return mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith("application/json;charset=UTF-8")) + .andExpect(content().encoding("UTF-8")) + .andReturn(); } diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingConfigInXmlTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingConfigInXmlTest.java index 7420ae81..1b976c81 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingConfigInXmlTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingConfigInXmlTest.java @@ -55,7 +55,7 @@ public void testExceptionInMapping() throws Exception { new Object[] { 3, "xxx", "string.param" }); MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -76,7 +76,7 @@ public void testBeanOrMethodNotFound() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -96,7 +96,7 @@ public void testExceptionInMappingWithNullValue() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -115,7 +115,7 @@ public void testExceptionNotInMapping() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingTest.java index 359dba3d..4d76b192 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/ExceptionHandlingTest.java @@ -156,7 +156,7 @@ private ExtDirectResponse runTest(Configuration configuration) throws Exception new Object[] { 3, "xxx", "string.param" }); MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); @@ -179,7 +179,7 @@ private ExtDirectResponse runTest11(Configuration configuration) throws Exceptio String edRequest = ControllerUtil.createEdsRequest("remoteProviderSimple", "method11", 3, null); MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, edRequest); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFilterTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFilterTest.java index f8d60cb1..a7f58430 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFilterTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFilterTest.java @@ -78,7 +78,7 @@ public void testFilters() throws Exception { for (String json : jsonList) { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, json); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(1); ExtDirectResponse resp = responses.get(0); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormLoadTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormLoadTest.java index 6ff650ac..9617b22f 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormLoadTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormLoadTest.java @@ -247,7 +247,7 @@ public void testMultipleRequests() throws Exception { MvcResult result = ControllerUtil.performRouterRequest(this.mockMvc, sb.toString()); List responses = ControllerUtil - .readDirectResponses(result.getResponse().getContentAsByteArray()); + .readDirectResponses(result.getResponse().getContentAsByteArray()); assertThat(responses).hasSize(6); ExtDirectResponse resp = responses.get(0); diff --git a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormPostCrossDomainUploadTest.java b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormPostCrossDomainUploadTest.java index 8f57bb98..671d4c08 100644 --- a/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormPostCrossDomainUploadTest.java +++ b/src/test/java/ch/ralscha/extdirectspring/controller/RouterControllerFormPostCrossDomainUploadTest.java @@ -66,9 +66,11 @@ public void testUpload() throws Exception { request.file("fileUpload", "the content of the file".getBytes()); - MvcResult resultMvc = this.mockMvc.perform(request).andExpect(status().isOk()) - .andExpect(content().contentTypeCompatibleWith("text/html;charset=utf-8")) - .andExpect(content().encoding("UTF-8")).andReturn(); + MvcResult resultMvc = this.mockMvc.perform(request) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith("text/html;charset=utf-8")) + .andExpect(content().encoding("UTF-8")) + .andReturn(); String response = resultMvc.getResponse().getContentAsString(); String prefix = "