From 7224ee74e6deef7dcb0d0cb3d810614981bb1a70 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 10 Jun 2021 14:20:00 +0200 Subject: [PATCH] #156 removed old fake request and response classes --- HISTORY | 4 +- .../aecu/core/service/AecuScriptContext.java | 12 +- .../aecu/core/service/AecuServiceImpl.java | 9 +- .../core/service/GroovyConsoleRequest.java | 488 ------------------ .../core/service/GroovyConsoleResponse.java | 225 -------- .../service/GroovyConsoleRequestTest.java | 159 ------ .../service/GroovyConsoleResponseTest.java | 92 ---- 7 files changed, 9 insertions(+), 980 deletions(-) delete mode 100644 core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java delete mode 100644 core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java delete mode 100644 core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java delete mode 100644 core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java diff --git a/HISTORY b/HISTORY index 48476959..1322b6b5 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,6 @@ -??? 5.0.0 +2021-06-11 4.1.0 - New filter methods: filterByNodeExists() and filterByNodeNotExists() - + - Fixed Sonar issues (#156) 2020-12-21 4.0.0 - Update to Groovy Console 16 and require AEM 6.5 (#135) diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java index cb38f1fd..1af6a41d 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuScriptContext.java @@ -4,14 +4,12 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.ResourceResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.base.Charsets; import com.icfolson.aem.groovy.console.api.context.ScriptContext; -import com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants; /** * Script context to run Groovy Console scripts. @@ -26,24 +24,20 @@ public class AecuScriptContext implements ScriptContext { private ResourceResolver resolver; private ByteArrayOutputStream out = new ByteArrayOutputStream(); - private SlingHttpServletRequest request; - /** * Constructor * * @param script script content * @param resolver resolver - * @param request request */ - public AecuScriptContext(String script, ResourceResolver resolver, SlingHttpServletRequest request) { + public AecuScriptContext(String script, ResourceResolver resolver) { this.script = script; this.resolver = resolver; - this.request = request; } @Override public String getData() { - return request.getParameter(GroovyConsoleConstants.DATA); + return null; } @Override @@ -73,7 +67,7 @@ public String getScript() { @Override public String getUserId() { - return request.getResourceResolver().getUserID(); + return resolver.getUserID(); } } diff --git a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java index 3c922242..03ad06b3 100644 --- a/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java +++ b/core/src/main/java/de/valtech/aecu/core/service/AecuServiceImpl.java @@ -29,7 +29,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.jackrabbit.JcrConstants; -import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.resource.LoginException; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; @@ -188,9 +187,8 @@ public ExecutionResult execute(String path) throws AecuException { * @throws AecuException error running script */ private ExecutionResult executeScript(ResourceResolver resolver, String path) throws AecuException { - SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver); LOG.info("Executing script " + path); - ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver, slingRequest); + ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver); RunScriptResponse response = groovyConsoleService.runScript(scriptContext); boolean success = StringUtils.isBlank(response.getExceptionStackTrace()); if (success) { @@ -219,9 +217,10 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) th private String loadScript(String path, ResourceResolver resolver) throws AecuException { Resource resource = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT); // https://sling.apache.org/documentation/the-sling-engine/resources.html#binary-support - try (InputStream inputStream = resource.adaptTo(InputStream.class)){ + try (InputStream inputStream = resource.adaptTo(InputStream.class)) { if (inputStream == null) { - throw new IOException("Resource at '" + path +"' cannot be adapted to InputStream, it doesn't seem to contain binary data"); + throw new IOException( + "Resource at '" + path + "' cannot be adapted to InputStream, it doesn't seem to contain binary data"); } return IOUtils.toString(inputStream, StandardCharsets.UTF_8); } catch (IOException e) { diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java deleted file mode 100644 index 64b6456d..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleRequest.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright 2018 - 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.Part; - -import org.apache.sling.api.SlingHttpServletRequest; -import org.apache.sling.api.request.RequestDispatcherOptions; -import org.apache.sling.api.request.RequestParameter; -import org.apache.sling.api.request.RequestParameterMap; -import org.apache.sling.api.request.RequestPathInfo; -import org.apache.sling.api.request.RequestProgressTracker; -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; - -/** - * Dummy request that is used to execute the script. - * - * @author Roland Gruber - */ -public class GroovyConsoleRequest implements SlingHttpServletRequest { - - private ResourceResolver resolver; - - /** - * Constructor - * - * @param resolver resource resolver - */ - public GroovyConsoleRequest(ResourceResolver resolver) { - this.resolver = resolver; - } - - @Override - public String getAuthType() { - return null; - } - - @Override - public String getContextPath() { - return null; - } - - @Override - public Cookie[] getCookies() { - return new Cookie[0]; - } - - @Override - public long getDateHeader(String arg0) { - return 0; - } - - @Override - public String getHeader(String arg0) { - return null; - } - - @Override - public Enumeration getHeaderNames() { - return null; - } - - @Override - public Enumeration getHeaders(String arg0) { - return null; - } - - @Override - public int getIntHeader(String arg0) { - return 0; - } - - @Override - public String getMethod() { - return null; - } - - @Override - public String getPathInfo() { - return null; - } - - @Override - public String getPathTranslated() { - return null; - } - - @Override - public String getQueryString() { - return null; - } - - @Override - public String getRemoteUser() { - return null; - } - - @Override - public String getRequestURI() { - return null; - } - - @Override - public StringBuffer getRequestURL() { - return null; - } - - @Override - public String getRequestedSessionId() { - return null; - } - - @Override - public String getServletPath() { - return null; - } - - @Override - public HttpSession getSession() { - return null; - } - - @Override - public HttpSession getSession(boolean arg0) { - return null; - } - - @Override - public Principal getUserPrincipal() { - return null; - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromURL() { - return false; - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - return false; - } - - @Override - public boolean isRequestedSessionIdValid() { - return false; - } - - @Override - public boolean isUserInRole(String arg0) { - return false; - } - - @Override - public Object getAttribute(String arg0) { - return null; - } - - @Override - public Enumeration getAttributeNames() { - return null; - } - - @Override - public String getCharacterEncoding() { - return null; - } - - @Override - public int getContentLength() { - return 0; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletInputStream getInputStream() throws IOException { - return null; - } - - @Override - public String getLocalAddr() { - return null; - } - - @Override - public String getLocalName() { - return null; - } - - @Override - public int getLocalPort() { - return 0; - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public Enumeration getLocales() { - return null; - } - - @Override - public String getParameter(String arg0) { - return null; - } - - @Override - public Map getParameterMap() { - return null; - } - - @Override - public Enumeration getParameterNames() { - return null; - } - - @Override - public String[] getParameterValues(String arg0) { - return new String[0]; - } - - @Override - public String getProtocol() { - return null; - } - - @Override - public BufferedReader getReader() throws IOException { - return null; - } - - @Override - public String getRealPath(String arg0) { - return null; - } - - @Override - public String getRemoteAddr() { - return null; - } - - @Override - public String getRemoteHost() { - return null; - } - - @Override - public int getRemotePort() { - return 0; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0) { - return null; - } - - @Override - public String getScheme() { - return null; - } - - @Override - public String getServerName() { - return null; - } - - @Override - public int getServerPort() { - return 0; - } - - @Override - public boolean isSecure() { - return false; - } - - @Override - public void removeAttribute(String arg0) { - throw new UnsupportedOperationException("removeAttribute not implemented"); - } - - @Override - public void setAttribute(String arg0, Object arg1) { - throw new UnsupportedOperationException("setAttribute not implemented"); - } - - @Override - public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { - throw new UnsupportedOperationException("setCharacterEncoding not implemented"); - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - - @Override - public Cookie getCookie(String arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestDispatcher getRequestDispatcher(Resource arg0, RequestDispatcherOptions arg1) { - return null; - } - - @Override - public RequestParameter getRequestParameter(String arg0) { - return null; - } - - @Override - public List getRequestParameterList() { - return Collections.emptyList(); - } - - @Override - public RequestParameterMap getRequestParameterMap() { - return null; - } - - @Override - public RequestParameter[] getRequestParameters(String arg0) { - return new RequestParameter[0]; - } - - @Override - public RequestPathInfo getRequestPathInfo() { - return null; - } - - @Override - public RequestProgressTracker getRequestProgressTracker() { - return null; - } - - @Override - public Resource getResource() { - return null; - } - - @Override - public ResourceBundle getResourceBundle(Locale arg0) { - return null; - } - - @Override - public ResourceBundle getResourceBundle(String arg0, Locale arg1) { - return null; - } - - @Override - public ResourceResolver getResourceResolver() { - return resolver; - } - - @Override - public String getResponseContentType() { - return null; - } - - @Override - public Enumeration getResponseContentTypes() { - return null; - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - return false; - } - - @Override - public void login(String username, String password) throws ServletException { - // ignore - } - - @Override - public void logout() throws ServletException { - // ignore - } - - @Override - public Collection getParts() throws IOException, ServletException { - return Collections.emptyList(); - } - - @Override - public Part getPart(String name) throws IOException, ServletException { - return null; - } - - @Override - public ServletContext getServletContext() { - return null; - } - - @Override - public AsyncContext startAsync() { - return null; - } - - @Override - public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) { - return null; - } - - @Override - public boolean isAsyncStarted() { - return false; - } - - @Override - public boolean isAsyncSupported() { - return false; - } - - @Override - public AsyncContext getAsyncContext() { - return null; - } - - @Override - public DispatcherType getDispatcherType() { - return null; - } - -} diff --git a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java b/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java deleted file mode 100644 index e0a0209c..00000000 --- a/core/src/main/java/de/valtech/aecu/core/service/GroovyConsoleResponse.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.Collection; -import java.util.Collections; -import java.util.Locale; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.Cookie; - -import org.apache.sling.api.SlingHttpServletResponse; - -/** - * Dummy response to execute the scripts. - * - * @author Roland Gruber - * - */ -public class GroovyConsoleResponse implements SlingHttpServletResponse { - - @Override - public void addCookie(Cookie cookie) { - // not used - } - - @Override - public boolean containsHeader(String name) { - return false; - } - - @Override - public String encodeURL(String url) { - return url; - } - - @Override - public String encodeRedirectURL(String url) { - return url; - } - - @Override - public String encodeUrl(String url) { - return url; - } - - @Override - public String encodeRedirectUrl(String url) { - return url; - } - - @Override - public void sendError(int sc, String msg) throws IOException { - // not used - } - - @Override - public void sendError(int sc) throws IOException { - // not used - } - - @Override - public void sendRedirect(String location) throws IOException { - // not used - } - - @Override - public void setDateHeader(String name, long date) { - // not used - } - - @Override - public void addDateHeader(String name, long date) { - // not used - } - - @Override - public void setHeader(String name, String value) { - // not used - } - - @Override - public void addHeader(String name, String value) { - // not used - } - - @Override - public void setIntHeader(String name, int value) { - // not used - } - - @Override - public void addIntHeader(String name, int value) { - // not used - } - - @Override - public void setStatus(int sc) { - // not used - } - - @Override - public void setStatus(int sc, String sm) { - // not used - } - - @Override - public int getStatus() { - return 200; - } - - @Override - public String getHeader(String name) { - return null; - } - - @Override - public Collection getHeaders(String name) { - return Collections.emptyList(); - } - - @Override - public Collection getHeaderNames() { - return Collections.emptyList(); - } - - @Override - public String getCharacterEncoding() { - return "UTF-8"; - } - - @Override - public String getContentType() { - return null; - } - - @Override - public ServletOutputStream getOutputStream() throws IOException { - return null; - } - - @Override - public PrintWriter getWriter() throws IOException { - return null; - } - - @Override - public void setCharacterEncoding(String charset) { - // not used - } - - @Override - public void setContentLength(int len) { - // not used - } - - @Override - public void setContentType(String type) { - // not used - } - - @Override - public void setBufferSize(int size) { - // not used - } - - @Override - public int getBufferSize() { - return 0; - } - - @Override - public void flushBuffer() throws IOException { - // not used - } - - @Override - public void resetBuffer() { - // not used - } - - @Override - public boolean isCommitted() { - return false; - } - - @Override - public void reset() { - // not used - } - - @Override - public void setLocale(Locale loc) { - // not used - } - - @Override - public Locale getLocale() { - return null; - } - - @Override - public T adaptTo(Class arg0) { - return null; - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java deleted file mode 100644 index 60169fe5..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleRequestTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2018 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; - -import javax.servlet.ServletException; - -import org.apache.sling.api.resource.Resource; -import org.apache.sling.api.resource.ResourceResolver; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -/** - * Tests GroovyConsoleRequest - * - * @author Roland Gruber - * - */ -@RunWith(MockitoJUnitRunner.class) -public class GroovyConsoleRequestTest { - - @Mock - private ResourceResolver resolver; - - private GroovyConsoleRequest request; - - @Before - public void setup() { - request = new GroovyConsoleRequest(resolver); - } - - @Test - public void getResourceResolver() { - assertEquals(resolver, request.getResourceResolver()); - } - - @Test(expected = UnsupportedOperationException.class) - public void removeAttribute() { - request.removeAttribute(""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setAttribute() { - request.setAttribute(null, ""); - } - - @Test(expected = UnsupportedOperationException.class) - public void setCharacterEncoding() throws UnsupportedEncodingException { - request.setCharacterEncoding(""); - } - - @Test - public void emptyMethods() throws IOException, ServletException { - assertNull(request.getAuthType()); - assertNull(request.getContextPath()); - assertEquals(0, request.getCookies().length); - assertEquals(0, request.getDateHeader("")); - assertNull(request.getHeader("")); - assertNull(request.getHeaderNames()); - assertNull(request.getHeaders("")); - assertEquals(0, request.getIntHeader("")); - assertNull(request.getMethod()); - assertNull(request.getPathInfo()); - assertNull(request.getPathTranslated()); - assertNull(request.getQueryString()); - assertNull(request.getRemoteUser()); - assertNull(request.getRequestURI()); - assertNull(request.getRequestURL()); - assertNull(request.getRequestedSessionId()); - assertNull(request.getServletPath()); - assertNull(request.getSession()); - assertNull(request.getSession(true)); - assertFalse(request.isRequestedSessionIdFromCookie()); - assertFalse(request.isRequestedSessionIdFromURL()); - assertFalse(request.isRequestedSessionIdFromUrl()); - assertFalse(request.isRequestedSessionIdValid()); - assertFalse(request.isUserInRole("")); - assertNull(request.getAttribute("")); - assertNull(request.getAttributeNames()); - assertNull(request.getCharacterEncoding()); - assertEquals(0, request.getContentLength()); - assertNull(request.getContentType()); - assertNull(request.getInputStream()); - assertNull(request.getLocalAddr()); - assertNull(request.getLocalName()); - assertEquals(0, request.getLocalPort()); - assertNull(request.getLocale()); - assertNull(request.getLocales()); - assertNull(request.getParameter("")); - assertNull(request.getParameterMap()); - assertNull(request.getParameterNames()); - assertEquals(0, request.getParameterValues("").length); - assertNull(request.getProtocol()); - assertNull(request.getReader()); - assertNull(request.getRealPath("")); - assertNull(request.getRemoteAddr()); - assertNull(request.getRemoteHost()); - assertEquals(0, request.getRemotePort()); - assertNull(request.getRequestDispatcher("")); - assertNull(request.getScheme()); - assertNull(request.getServerName()); - assertEquals(0, request.getServerPort()); - assertFalse(request.isSecure()); - assertNull(request.adaptTo(null)); - assertNull(request.getCookie("")); - assertNull(request.getRequestDispatcher((Resource) null)); - assertNull(request.getRequestDispatcher("", null)); - assertNull(request.getRequestDispatcher((Resource) null, null)); - assertNull(request.getRequestParameter("")); - assertEquals(0, request.getRequestParameterList().size()); - assertNull(request.getRequestParameterMap()); - assertEquals(0, request.getRequestParameters("").length); - assertNull(request.getRequestPathInfo()); - assertNull(request.getRequestProgressTracker()); - assertNull(request.getResource()); - assertNull(request.getResourceBundle(null)); - assertNull(request.getResourceBundle("", null)); - assertNull(request.getResponseContentType()); - assertNull(request.getResponseContentTypes()); - assertFalse(request.authenticate(null)); - request.login(null, null); - request.logout(); - assertEquals(0, request.getParts().size()); - assertNull(request.getPart(null)); - assertNull(request.getServletContext()); - assertNull(request.startAsync()); - assertNull(request.startAsync(null, null)); - assertFalse(request.isAsyncStarted()); - assertFalse(request.isAsyncSupported()); - assertNull(request.getAsyncContext()); - assertNull(request.getDispatcherType()); - } - -} diff --git a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java b/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java deleted file mode 100644 index e1759fad..00000000 --- a/core/src/test/java/de/valtech/aecu/core/service/GroovyConsoleResponseTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2019 Valtech GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and - * associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT - * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package de.valtech.aecu.core.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; - -/** - * Tests GroovyConsoleResponse - * - * @author Roland Gruber - */ -public class GroovyConsoleResponseTest { - - private static final String TEST = "testval"; - - private GroovyConsoleResponse response; - - @Before - public void setup() { - response = new GroovyConsoleResponse(); - } - - @Test - public void setters() throws IOException { - response.addCookie(null); - response.sendError(0); - response.sendError(0, TEST); - response.sendRedirect(TEST); - response.setDateHeader(TEST, 0); - response.addDateHeader(TEST, 0); - response.setHeader(TEST, TEST); - response.addHeader(TEST, TEST); - response.setIntHeader(TEST, 0); - response.addIntHeader(TEST, 0); - response.setStatus(0); - response.setStatus(0, TEST); - response.setCharacterEncoding(TEST); - response.setContentLength(0); - response.setContentType(TEST); - response.setBufferSize(0); - response.flushBuffer(); - response.resetBuffer(); - response.reset(); - response.setLocale(null); - } - - @Test - public void getters() throws IOException { - assertFalse(response.containsHeader(null)); - assertEquals(TEST, response.encodeURL(TEST)); - assertEquals(TEST, response.encodeUrl(TEST)); - assertEquals(TEST, response.encodeRedirectURL(TEST)); - assertEquals(TEST, response.encodeRedirectUrl(TEST)); - assertEquals(200, response.getStatus()); - assertNull(response.getHeader(TEST)); - assertTrue(response.getHeaders(TEST).isEmpty()); - assertTrue(response.getHeaderNames().isEmpty()); - assertEquals("UTF-8", response.getCharacterEncoding()); - assertNull(response.getContentType()); - assertNull(response.getOutputStream()); - assertNull(response.getWriter()); - assertEquals(0, response.getBufferSize()); - assertFalse(response.isCommitted()); - assertNull(response.getLocale()); - assertNull(response.adaptTo(null)); - } - -}