use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class TestWidgetTypeAction method testAddNewWidgetType.
// TODO ADD MORE TESTS for add new widget
public void testAddNewWidgetType() throws Throwable {
String widgetTypeCode = "randomWidgetCode_4";
List<String> fragmantCodes = null;
try {
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
assertNull(this._guiFragmentManager.getGuiFragment(widgetTypeCode));
String result = this.executeAddWidgetType("admin", widgetTypeCode, "**GUI**");
assertEquals(Action.SUCCESS, result);
WidgetType addedType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(addedType);
FieldSearchFilter filterByType = new FieldSearchFilter("widgettypecode", widgetTypeCode, false);
FieldSearchFilter[] filters = { filterByType };
fragmantCodes = this._guiFragmentManager.searchGuiFragments(filters);
assertNotNull(fragmantCodes);
assertEquals(1, fragmantCodes.size());
assertEquals(widgetTypeCode, fragmantCodes.get(0));
GuiFragment guiFragment = this._guiFragmentManager.getGuiFragment(fragmantCodes.get(0));
assertNotNull(guiFragment);
assertEquals(widgetTypeCode, guiFragment.getWidgetTypeCode());
assertEquals("**GUI**", guiFragment.getGui());
assertFalse(guiFragment.isLocked());
} catch (Throwable t) {
throw t;
} finally {
if (null != fragmantCodes) {
for (int i = 0; i < fragmantCodes.size(); i++) {
String code = fragmantCodes.get(i);
this._guiFragmentManager.deleteGuiFragment(code);
}
}
this._widgetTypeManager.deleteWidgetType(widgetTypeCode);
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class TestGuiFragmentAction method createMockFragment.
protected GuiFragment createMockFragment(String code, String gui, String widgetTypeCode) {
GuiFragment mFragment = new GuiFragment();
mFragment.setCode(code);
mFragment.setGui(gui);
mFragment.setWidgetTypeCode(widgetTypeCode);
return mFragment;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class GuiFragmentValidatorTest method validateExistingFragment.
@Test
public void validateExistingFragment() throws Exception {
GuiFragment existing = new GuiFragment();
existing.setCode("existing");
when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "<h1>code</h1>");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertTrue(bindingResult.hasErrors());
Assert.assertEquals(1, bindingResult.getErrorCount());
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiGuiFragmentInterface method getGuiFragment.
public JAXBGuiFragment getGuiFragment(Properties properties) throws ApiException, Throwable {
String code = properties.getProperty("code");
JAXBGuiFragment jaxbGuiFragment = null;
try {
GuiFragment guiFragment = this.getGuiFragmentManager().getGuiFragment(code);
if (null == guiFragment) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with id '" + code + "' does not exist", Response.Status.CONFLICT);
}
jaxbGuiFragment = new JAXBGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error creating jaxb object of fragment - code '{}'", code, t);
throw t;
}
return jaxbGuiFragment;
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class ApiGuiFragmentInterface method addGuiFragment.
public void addGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
try {
if (null != this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + jaxbGuiFragment.getCode() + " already exists", Response.Status.CONFLICT);
}
GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
}
this.getGuiFragmentManager().addGuiFragment(guiFragment);
} catch (ApiException ae) {
throw ae;
} catch (Throwable t) {
_logger.error("Error adding new fragment", t);
throw t;
}
}
Aggregations