Skip to content

Commit

Permalink
Replace Krazo default view suffix constant with spec constant
Browse files Browse the repository at this point in the history
fixes: #369
  • Loading branch information
erdlet committed May 10, 2023
1 parent 6e858aa commit 9004e08
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/eclipse/krazo/KrazoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.eclipse.krazo;

import jakarta.mvc.engine.ViewEngine;
import org.eclipse.krazo.cdi.RedirectScopeManager;
import org.eclipse.krazo.jaxrs.JaxRsContext;
import org.eclipse.krazo.security.CsrfTokenStrategy;
Expand Down Expand Up @@ -69,7 +70,7 @@ public CsrfTokenStrategy getCsrfTokenStrategy() {
}

public String getDefaultViewFileExtension() {
Object value = config.getProperty(Properties.DEFAULT_VIEW_FILE_EXTENSION);
Object value = config.getProperty(ViewEngine.VIEW_EXTENSION);
if (value instanceof String) {
return (String) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ static String appendExtensionIfRequired(String viewName, String defaultExtension
}

String resultView = viewName;
if (!viewName.contains(".")) {
if (defaultExtension.contains(".")) {
resultView += defaultExtension;
}
else if (!viewName.contains(".")) {
resultView += "." + defaultExtension;
}
return resultView;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.eclipse.krazo.test.defaultview;

import jakarta.mvc.engine.ViewEngine;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

import java.util.Map;

@ApplicationPath("mvc")
public class DefaultViewApplication extends Application {

@Override
public Map<String, Object> getProperties() {
return Map.of(ViewEngine.VIEW_EXTENSION, ".jsp");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.eclipse.krazo.test.defaultview;

import jakarta.enterprise.context.RequestScoped;
import jakarta.mvc.Controller;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Controller
@RequestScoped
@Path("default-view")
public class DefaultViewController {

@GET
public String index() {
return "index";
}
}
10 changes: 10 additions & 0 deletions testsuite/src/main/resources/defaultview/views/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<title>Default-View Extension Test</title>
</head>
<body>
<h1 id="headline">Default-View Extension Test</h1>
</body>
</html>
75 changes: 75 additions & 0 deletions testsuite/src/test/java/org/eclipse/krazo/test/DefaultViewIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2014-2015 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2019 Eclipse Krazo committers and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.eclipse.krazo.test;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.eclipse.krazo.test.util.WebArchiveBuilder;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.net.URL;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;

/**
* Tests default view extension.
*
* @author Tobias Erdle
*/
@RunWith(Arquillian.class)
public class DefaultViewIT {
private static final String WEB_INF_SRC = "src/main/resources/defaultview/";
@ArquillianResource
private URL baseURL;
private WebClient webClient;

@Before
public void setUp() {
webClient = new WebClient();
webClient.getOptions()
.setThrowExceptionOnFailingStatusCode(false);
webClient.getOptions()
.setRedirectEnabled(true);
}

@Deployment(testable = false, name = "default-view")
public static WebArchive createDeployment() {
return new WebArchiveBuilder()
.addPackage("org.eclipse.krazo.test.defaultview")
.addView(Paths.get(WEB_INF_SRC).resolve("views/index.jsp").toFile(), "index.jsp")
.addBeansXml()
.build();
}

@Test
public void test() throws Exception {
final HtmlPage page = webClient.getPage(baseURL + "mvc/default-view");

System.out.println(page.asXml());

assertEquals("Default-View Extension Test", page.getElementById("headline").getTextContent());
}
}

0 comments on commit 9004e08

Please sign in to comment.