use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class TestApiWidgetTypeInterface method getJaxbWidgetType.
private JAXBWidgetType getJaxbWidgetType(WidgetType widgetType) throws Throwable {
assertNotNull(widgetType);
GuiFragment singleGuiFragment = null;
List<GuiFragment> fragments = new ArrayList<>();
if (!widgetType.isLogic()) {
singleGuiFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetType.getCode());
} else {
List<String> fragmentCodes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetType.getCode());
if (null != fragmentCodes) {
for (int i = 0; i < fragmentCodes.size(); i++) {
String fragmentCode = fragmentCodes.get(i);
GuiFragment fragment = this._guiFragmentManager.getGuiFragment(fragmentCode);
if (null != fragment) {
fragments.add(fragment);
}
}
}
}
return new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeUpdateJaxbNoLogicWidgetType.
private void testInvokeUpdateJaxbNoLogicWidgetType(String widgetTypeCode, ApsProperties titles, boolean removeParametersFromCall, String customSingleGui, boolean expectedSuccess) throws Throwable {
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(widgetType);
WidgetType widgetTypeToEdit = widgetType.clone();
GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
ApsProperties originalTitles = widgetType.getTitles();
try {
JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(widgetTypeToEdit);
if (StringUtils.isNotBlank(customSingleGui)) {
jaxbWidgetType.setGui(customSingleGui);
}
if (null != titles) {
jaxbWidgetType.setTitles(titles);
}
if (removeParametersFromCall) {
jaxbWidgetType.setTypeParameters(null);
}
this._apiWidgetTypeInterface.updateWidgetType(jaxbWidgetType);
if (!expectedSuccess) {
fail();
}
WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(extractedWidgetType);
assertEquals(widgetType.getMainGroup(), extractedWidgetType.getMainGroup());
assertEquals(titles, extractedWidgetType.getTitles());
assertEquals(widgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
assertEquals(widgetType.isLocked(), extractedWidgetType.isLocked());
if (StringUtils.isNotBlank(customSingleGui) && null == previousFragment) {
assertNotNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
}
} catch (ApiException ae) {
if (expectedSuccess) {
fail();
}
} catch (Throwable t) {
throw t;
} finally {
if (null == previousFragment) {
List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode);
if (null != codes) {
for (int i = 0; i < codes.size(); i++) {
String code = codes.get(i);
this._guiFragmentManager.deleteGuiFragment(code);
}
}
} else if (null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
this._guiFragmentManager.addGuiFragment(previousFragment);
} else {
this._guiFragmentManager.updateGuiFragment(previousFragment);
}
this._widgetTypeManager.updateWidgetType(widgetType.getCode(), originalTitles, widgetType.getConfig(), widgetType.getMainGroup(), widgetType.getConfigUi(), widgetType.getBundleId());
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class TestApiWidgetTypeInterface method testInvokeDeleteJaxbNoLogicWidgetType.
private void testInvokeDeleteJaxbNoLogicWidgetType(String widgetTypeCode, boolean expectedSuccess) throws Throwable {
Properties properties = new Properties();
properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
properties.put("code", widgetTypeCode);
WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
assertNotNull(widgetType);
WidgetType widgetTypeToDelete = widgetType.clone();
GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
try {
this._apiWidgetTypeInterface.deleteWidgetType(properties);
if (!expectedSuccess) {
fail();
}
assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
assertNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
} catch (ApiException ae) {
if (expectedSuccess) {
throw ae;
}
} catch (Throwable t) {
if (expectedSuccess) {
throw t;
}
} finally {
if (null != previousFragment && null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
this._guiFragmentManager.addGuiFragment(previousFragment);
}
if (null == this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
this._widgetTypeManager.addWidgetType(widgetTypeToDelete);
}
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class GuiFragmentSettingsControllerIntegrationTest method testGetPluginsMapping.
@Test
public void testGetPluginsMapping() throws Exception {
String code = "info";
GuiFragment fragment = new GuiFragment();
fragment.setCode(code);
fragment.setDefaultGui("hello world");
this.guiFragmentManager.addGuiFragment(fragment);
try {
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
String accessToken = mockOAuthInterceptor(user);
ResultActions result = this.executeGet("/fragments/info/plugins", accessToken, status().isOk());
result.andExpect(jsonPath("$.payload.size()", is(0)));
ResultActions resultFragment = this.executeGet("/fragments/info", accessToken, status().isOk());
resultFragment.andExpect(jsonPath("$.payload.code", is(code)));
resultFragment.andExpect(jsonPath("$.payload.locked", is(false)));
} finally {
this.guiFragmentManager.deleteGuiFragment(code);
}
}
use of org.entando.entando.aps.system.services.guifragment.GuiFragment in project entando-core by entando.
the class GuiFragmentValidatorTest method validateExistingAndInvalidFragment.
@Test
public void validateExistingAndInvalidFragment() throws Exception {
GuiFragment existing = new GuiFragment();
existing.setCode("existing");
when(this.guiFragmentManager.getGuiFragment("existing")).thenReturn(existing);
GuiFragmentRequestBody request = new GuiFragmentRequestBody("existing", "");
MapBindingResult bindingResult = new MapBindingResult(new HashMap<Object, Object>(), "fragment");
validator.validate(request, bindingResult);
Assert.assertTrue(bindingResult.hasErrors());
Assert.assertEquals(2, bindingResult.getErrorCount());
}
Aggregations