Search in sources :

Example 1 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method testAddUpdateWidget_1.

@Test
public void testAddUpdateWidget_1() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String newCode = "test_new_type_1";
    Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
    try {
        WidgetRequest request = new WidgetRequest();
        request.setCode(newCode);
        request.setGroup(Group.FREE_GROUP_NAME);
        Map<String, String> titles = new HashMap<>();
        titles.put("it", "Titolo ITA");
        titles.put("en", "Title EN");
        request.setTitles(titles);
        request.setCustomUi("<h1>Custom UI</h1>");
        request.setGroup(Group.FREE_GROUP_NAME);
        ResultActions result = this.executeWidgetPost(request, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.code", is(newCode)));
        WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN", widgetType.getTitles().getProperty("en"));
        request.setGroup("invalid");
        titles.put("en", "Title EN modified");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_GROUP_INVALID)));
        request.setGroup("helpdesk");
        request.setCustomUi("");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
        titles.put("en", "Title EN modified");
        request.setCustomUi("New Custom Ui");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.group", is("helpdesk")));
        widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN modified", widgetType.getTitles().getProperty("en"));
        Assert.assertEquals("helpdesk", widgetType.getMainGroup());
        result = this.executeWidgetDelete(newCode, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.code", is(newCode)));
        widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNull(widgetType);
    } catch (Exception e) {
        throw e;
    } finally {
        this.widgetTypeManager.deleteWidgetType(newCode);
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 2 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method testUpdateStockLocked.

@Test
public void testUpdateStockLocked() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String code = "login_form";
    WidgetType widgetType = this.widgetTypeManager.getWidgetType(code);
    WidgetRequest request = new WidgetRequest();
    request.setCode(code);
    request.setGroup(Group.FREE_GROUP_NAME);
    request.setTitles((Map) widgetType.getTitles());
    ResultActions result = this.executeWidgetPut(request, code, accessToken, status().isOk());
    result.andExpect(jsonPath("$.payload.code", is("login_form")));
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 3 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetControllerIntegrationTest method testAddUpdateWidget_2.

@Test
public void testAddUpdateWidget_2() throws Exception {
    UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
    String accessToken = mockOAuthInterceptor(user);
    String newCode = "test_new_type_2";
    Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
    try {
        WidgetRequest request = new WidgetRequest();
        request.setCode(newCode);
        request.setGroup(Group.FREE_GROUP_NAME);
        Map<String, String> titles = new HashMap<>();
        titles.put("it", "Titolo ITA 2");
        titles.put("en", "Title EN 2");
        request.setTitles(titles);
        request.setCustomUi("");
        request.setGroup(Group.FREE_GROUP_NAME);
        ResultActions result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_NOT_BLANK)));
        titles.put("en", "");
        request.setCustomUi("Custom UI");
        result = this.executeWidgetPost(request, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
        titles.put("en", "Title EN 2 bis");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isNotFound());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_WIDGET_NOT_FOUND)));
        result = this.executeWidgetPost(request, accessToken, status().isOk());
        result.andExpect(jsonPath("$.payload.group", is(Group.FREE_GROUP_NAME)));
        WidgetType widgetType = this.widgetTypeManager.getWidgetType(newCode);
        Assert.assertNotNull(widgetType);
        Assert.assertEquals("Title EN 2 bis", widgetType.getTitles().getProperty("en"));
        titles.put("it", "");
        result = this.executeWidgetPut(request, newCode, accessToken, status().isBadRequest());
        result.andExpect(jsonPath("$.errors[0].code", is(WidgetValidator.ERRCODE_MISSING_TITLE)));
    } catch (Exception e) {
        throw e;
    } finally {
        this.widgetTypeManager.deleteWidgetType(newCode);
        Assert.assertNull(this.widgetTypeManager.getWidgetType(newCode));
    }
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) HashMap(java.util.HashMap) ResultActions(org.springframework.test.web.servlet.ResultActions) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) Test(org.junit.Test) AbstractControllerIntegrationTest(org.entando.entando.web.AbstractControllerIntegrationTest)

Example 4 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetServiceTest method getWidgetRequest1.

private WidgetRequest getWidgetRequest1() {
    WidgetRequest widgetRequest = new WidgetRequest();
    widgetRequest.setCode(WIDGET_1_CODE);
    widgetRequest.setTitles(ImmutableMap.of("it", "Mio Titolo", "en", "My Title"));
    widgetRequest.setCustomUi("<div></div>");
    widgetRequest.setGroup("group");
    widgetRequest.setConfigUi(ImmutableMap.of(CUSTOM_ELEMENT_KEY, CUSTOM_ELEMENT_1, RESOURCES_KEY, RESOURCES_1));
    widgetRequest.setBundleId(BUNDLE_1);
    return widgetRequest;
}
Also used : WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest)

Example 5 with WidgetRequest

use of org.entando.entando.web.widget.model.WidgetRequest in project entando-core by entando.

the class WidgetServiceTest method shouldUpdateWidget.

@Test
public void shouldUpdateWidget() throws Exception {
    // Given
    WidgetRequest widgetRequest = getWidgetRequest1();
    when(widgetManager.getWidgetType(eq(widgetRequest.getCode()))).thenReturn(getWidget1());
    when(groupManager.getGroup(widgetRequest.getGroup())).thenReturn(mock(Group.class));
    // When
    WidgetDto widgetDto = widgetService.updateWidget(WIDGET_1_CODE, widgetRequest);
    // Then
    ArgumentCaptor<String> configUiCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> bundleIdCaptor = ArgumentCaptor.forClass(String.class);
    verify(widgetManager).updateWidgetType(anyString(), any(), any(), anyString(), configUiCaptor.capture(), bundleIdCaptor.capture());
    assertThat(configUiCaptor.getValue()).isEqualTo(objectMapper.writeValueAsString(widgetRequest.getConfigUi()));
    assertThat(bundleIdCaptor.getValue()).isEqualTo(widgetRequest.getBundleId());
    assertThat(widgetDto.getConfigUi()).isEqualTo(widgetRequest.getConfigUi());
    assertThat(widgetDto.getBundleId()).isEqualTo(widgetRequest.getBundleId());
}
Also used : Group(com.agiletec.aps.system.services.group.Group) WidgetRequest(org.entando.entando.web.widget.model.WidgetRequest) WidgetDto(org.entando.entando.aps.system.services.widgettype.model.WidgetDto) Test(org.junit.Test)

Aggregations

WidgetRequest (org.entando.entando.web.widget.model.WidgetRequest)11 Test (org.junit.Test)7 UserDetails (com.agiletec.aps.system.services.user.UserDetails)5 HashMap (java.util.HashMap)5 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)5 ResultActions (org.springframework.test.web.servlet.ResultActions)5 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)3 Group (com.agiletec.aps.system.services.group.Group)2 WidgetDto (org.entando.entando.aps.system.services.widgettype.model.WidgetDto)2 PageRequest (org.entando.entando.web.page.model.PageRequest)2 WidgetConfigurationRequest (org.entando.entando.web.page.model.WidgetConfigurationRequest)2