Skip to content

Commit

Permalink
#44 Mgt of keys and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Jun 24, 2012
1 parent 7f87e5f commit 2148391
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 140 deletions.
@@ -1,7 +1,7 @@
package net.myconfig.service.exception;


public class KeyAlreadyDefinedException extends ApplicationRelatedException {
public class KeyAlreadyDefinedException extends KeyInputException {

public KeyAlreadyDefinedException(int id, String name) {
super (id, name);
Expand Down
@@ -1,7 +1,7 @@
package net.myconfig.service.exception;


public class VersionAlreadyDefinedException extends ApplicationRelatedException {
public class VersionAlreadyDefinedException extends VersionInputException {

public VersionAlreadyDefinedException(int id, String name) {
super (id, name);
Expand Down
@@ -0,0 +1,9 @@
package net.myconfig.service.exception;

public abstract class VersionInputException extends ApplicationRelatedException {

public VersionInputException(int id, Object... params) {
super(id, params);
}

}
@@ -1,7 +1,7 @@
package net.myconfig.service.exception;


public class VersionNotDefinedException extends CoreException {
public class VersionNotDefinedException extends VersionInputException {

public VersionNotDefinedException(int application, String name) {
super (application, name);
Expand Down
Expand Up @@ -2,7 +2,9 @@

import java.util.Locale;

import net.myconfig.service.exception.ApplicationRelatedException;
import net.myconfig.service.exception.KeyInputException;
import net.myconfig.service.exception.VersionInputException;
import net.myconfig.web.rest.UIInterface;
import net.myconfig.web.support.ErrorHandler;

Expand All @@ -14,33 +16,61 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

public abstract class AbstractGUIApplicationPage extends AbstractGUIPage implements KeyActions {
public abstract class AbstractGUIApplicationPage extends AbstractGUIPage implements KeyActions, VersionActions {

public AbstractGUIApplicationPage(UIInterface ui, ErrorHandler errorHandler) {
super(ui, errorHandler);
}

public abstract String page (int application, Model model);

protected abstract String pagePath (int application);

@ExceptionHandler(KeyInputException.class)
public ModelAndView onKeyException (Locale locale, KeyInputException ex) {
ExtendedModelMap model = prepareModelForError(locale, ex, "key_error");
// OK
return onMgtException(locale, ex, "key_error");
}

@ExceptionHandler(VersionInputException.class)
public ModelAndView onVersionException (Locale locale, VersionInputException ex) {
return onMgtException(locale, ex, "version_error");
}

protected ModelAndView onMgtException(Locale locale, ApplicationRelatedException ex, String errorKey) {
ExtendedModelMap model = prepareModelForError(locale, ex, errorKey);
return new ModelAndView(page(ex.getId(), model), model);
}

@Override
@RequestMapping(value = "/{application:\\d+}/key/create", method = RequestMethod.POST)
public String keyCreate(Model model, @PathVariable int application, String name, String description) {
ui.keyCreate (application, name, description);
return page (application, model);
return backToPage (application);
}

@Override
@RequestMapping(value = "/{application:\\d+}/key/delete", method = RequestMethod.POST)
public String keyDelete(Model model, @PathVariable int application, String name) {
ui.keyDelete(application, name);
return page (application, model);
return backToPage (application);
}

@Override
@RequestMapping(value = "/{application:\\d+}/version/create", method = RequestMethod.POST)
public String versionCreate(Model model, @PathVariable int application, String name) {
ui.versionCreate (application, name);
return backToPage (application);
}

@Override
@RequestMapping(value = "/{application:\\d+}/version/delete", method = RequestMethod.POST)
public String versionDelete(Model model, @PathVariable int application, String name) {
ui.versionDelete(application, name);
return backToPage (application);
}

protected String backToPage(int application) {
return redirect(pagePath(application));
}

}
Expand Up @@ -25,5 +25,10 @@ public String page(@PathVariable int application, Model model) {
model.addAttribute("application", ui.applicationConfiguration(application));
return "application";
}

@Override
protected String pagePath(int application) {
return "application/" + application;
}

}

This file was deleted.

@@ -0,0 +1,11 @@
package net.myconfig.web.gui;

import org.springframework.ui.Model;

public interface VersionActions {

String versionCreate (Model model, int application, String name);

String versionDelete (Model model, int application, String name);

}
Expand Up @@ -7,8 +7,8 @@ <h1><@lh key="configuration.versions" /></h1>
<@crud_table items = application.versionSummaryList errorKey = "version_error">
<@crud_column property="name" key="model.version.name" />
<@crud_column property="keyNumber" key="configuration.version.keyNumber" class="crud-number" />
<@crud_create id="version" action="gui/version/create/${application.id}" label="configuration.version.new" />
<@crud_delete action="gui/version/delete/${application.id}" field="name" promptKey="version.delete" />
<@crud_create id="version" action="gui/application/${application.id}/version/create" label="configuration.version.new" />
<@crud_delete action="gui/application/${application.id}/version/delete" field="name" promptKey="version.delete" />
</@crud_table>
</section>
<section id="app-environments">
Expand Down
Expand Up @@ -43,5 +43,70 @@ public void application_configuration_not_there() throws Exception {
ErrorMessage error = (ErrorMessage) mav.getModel().get("error");
assertEquals ("[S-004] Cannot find application 0", error.getMessage());
}

@Test
public void version_create () throws Exception {
ApplicationSummary app = ui.applicationCreate(helper.generateName("versionCreate_"));
ModelAndView mav = helper.run ("POST", "/gui/application/" + app.getId() + "/version/create", "name", "1.0");
assertNotNull (mav);
assertEquals ("redirect:/gui/application/" + app.getId(), mav.getViewName());
}

@Test
public void version_create_already_exists () throws Exception {
ApplicationSummary app = ui.applicationCreate(helper.generateName("versionCreate_"));
helper.run ("POST", "/gui/version/create/" + app.getId(), "name", "1.0");
ModelAndView mav = helper.run ("POST", "/gui/version/create/" + app.getId(), "name", "1.0");
assertNotNull (mav);
assertEquals ("configuration", mav.getViewName());
ApplicationConfiguration configuration = (ApplicationConfiguration) mav.getModel().get("application");
assertNotNull(configuration);
assertEquals (app.getId(), configuration.getId());
assertEquals(app.getName(), configuration.getName());
helper.assertErrorMessage (mav, "version_error", "[S-003] The version \"1.0\" is already defined.");
}

@Test
public void version_create_noapp () throws Exception {
ModelAndView mav = helper.run ("POST", "/gui/version/create/-1", "name", "1.0");
assertNotNull (mav);
assertEquals ("error", mav.getViewName());
ErrorMessage error = (ErrorMessage) mav.getModel().get("error");
assertEquals ("[S-004] Cannot find application -1", error.getMessage());
}

@Test
public void version_delete() throws Exception {
// Test data
ApplicationSummary app = ui.applicationCreate(helper.generateName("version_delete_"));
ui.versionCreate(app.getId(), "1.0");
ui.versionCreate(app.getId(), "1.1");
ui.versionCreate(app.getId(), "1.2");
// Deletes one version
ModelAndView mav = helper.run("POST", "/gui/version/delete/" + app.getId(), "name", "1.1");
assertNotNull (mav);
assertEquals ("redirect:/gui/application/configure?id=" + app.getId(), mav.getViewName());
}

@Test
public void version_delete_none() throws Exception {
// Test data
ApplicationSummary app = ui.applicationCreate(helper.generateName("version_delete_none_"));
ui.versionCreate(app.getId(), "1.0");
ui.versionCreate(app.getId(), "1.1");
// Deletes one version
ModelAndView mav = helper.run("POST", "/gui/version/delete/" + app.getId(), "name", "1.2");
assertNotNull (mav);
assertEquals ("redirect:/gui/application/configure?id=" + app.getId(), mav.getViewName());
}

@Test
public void version_delete_noapp() throws Exception {
ModelAndView mav = helper.run("POST", "/gui/version/delete/-1", "name", "1.1");
assertNotNull (mav);
assertEquals ("error", mav.getViewName());
ErrorMessage error = (ErrorMessage) mav.getModel().get("error");
assertEquals ("[S-004] Cannot find application -1", error.getMessage());
}

}

This file was deleted.

0 comments on commit 2148391

Please sign in to comment.