Search in sources :

Example 1 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ModifyScheduledJobHandler method updateConfig.

private void updateConfig(final EditableScheduledJob target, final ScriptValue params) {
    if (params.getKeys().contains("config")) {
        final ScriptValue value = params.getMember("config");
        if (value == null) {
            throw new IllegalArgumentException("config cannot be null");
        }
        target.config = propertyTreeMarshallerService.get().marshal(params.getMember("config").getMap());
    }
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue)

Example 2 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class PortalRequestSerializerTest method serializeNoHeadersNoParams.

@Test
public void serializeNoHeadersNoParams() throws Exception {
    final PortalRequest sourceRequest = new PortalRequest();
    final String jsonRequest = readResource("PortalRequestSerializer_request2.json");
    final Object obj = execute("var result = " + jsonRequest + "; result;");
    final ScriptValue value = this.factory.newValue(obj);
    PortalRequestSerializer reqSerializer = new PortalRequestSerializer(sourceRequest, value);
    final PortalRequest portalRequest = reqSerializer.serialize();
    assertNotNull(portalRequest);
    assertEquals(HttpMethod.POST, portalRequest.getMethod());
    assertEquals("https", portalRequest.getScheme());
    assertEquals("myhost", portalRequest.getHost());
    assertEquals(1234, portalRequest.getPort());
    assertEquals("/some/path", portalRequest.getPath());
    assertEquals("https://myhost:1234/some/path/url", portalRequest.getUrl());
    assertEquals("127.0.0.42", portalRequest.getRemoteAddress());
    assertEquals(RenderMode.EDIT, portalRequest.getMode());
    assertEquals(true, portalRequest.isValidTicket());
    assertEquals(Branch.from("draft"), portalRequest.getBranch());
    assertEquals("application/json", portalRequest.getContentType());
    assertEquals(0, portalRequest.getHeaders().size());
    assertEquals(0, portalRequest.getCookies().size());
    assertEquals(0, portalRequest.getParams().size());
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 3 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class PortalRequestSerializerTest method serializeNonObject.

@Test
public void serializeNonObject() throws Exception {
    final PortalRequest sourceRequest = new PortalRequest();
    final Object obj = execute("var result = 'response'; result;");
    final ScriptValue value = this.factory.newValue(obj);
    PortalRequestSerializer reqSerializer = new PortalRequestSerializer(sourceRequest, value);
    final PortalRequest portalRequest = reqSerializer.serialize();
    assertNotNull(portalRequest);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 4 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class PortalRequestSerializerTest method serialize_no_params_duplication.

@Test
public void serialize_no_params_duplication() throws Exception {
    final PortalRequest sourceRequest = new PortalRequest();
    sourceRequest.getParams().put("a", "oldA");
    sourceRequest.getParams().put("b", "oldB");
    sourceRequest.getParams().put("b", "oldB");
    sourceRequest.getParams().put("d", "oldD");
    sourceRequest.getParams().put("e", "oldE");
    sourceRequest.getParams().put("f", "oldF");
    final String jsonRequest = readResource("PortalRequestSerializer_request4.json");
    final Object obj = execute("var result = " + jsonRequest + "; result;");
    final ScriptValue value = this.factory.newValue(obj);
    PortalRequestSerializer reqSerializer = new PortalRequestSerializer(sourceRequest, value);
    final PortalRequest portalRequest = reqSerializer.serialize();
    assertThat(portalRequest.getParams().get("a")).containsExactly("newA");
    assertThat(portalRequest.getParams().get("b")).containsExactly("newB", "1");
    assertThat(portalRequest.getParams().get("c")).containsExactly("newC");
    assertThat(portalRequest.getParams().get("d")).containsExactly("oldD");
    assertFalse(portalRequest.getParams().containsKey("e"));
    assertFalse(portalRequest.getParams().containsKey("f"));
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 5 with ScriptValue

use of com.enonic.xp.script.ScriptValue in project xp by enonic.

the class ScriptValueFactoryImplTest method newValue_scalar.

@Test
public void newValue_scalar() {
    final ScriptValue value = this.factory.newValue("2");
    assertNotNull(value);
    assertEquals(false, value.isArray());
    assertEquals(false, value.isFunction());
    assertEquals(false, value.isObject());
    assertEquals(true, value.isValue());
    assertEquals("2", value.getValue());
    assertEquals(2, value.getValue(Integer.class));
    assertTrue(value.getList().isEmpty());
    assertNonArray(value);
    assertNonObject(value);
    assertNonFunction(value);
}
Also used : ScriptValue(com.enonic.xp.script.ScriptValue) Test(org.junit.jupiter.api.Test)

Aggregations

ScriptValue (com.enonic.xp.script.ScriptValue)40 Test (org.junit.jupiter.api.Test)20 PortalRequest (com.enonic.xp.portal.PortalRequest)7 PortalResponseSerializer (com.enonic.xp.portal.impl.controller.PortalResponseSerializer)5 PortalRequestMapper (com.enonic.xp.portal.impl.mapper.PortalRequestMapper)5 JSObject (jdk.nashorn.api.scripting.JSObject)4 PortalResponseMapper (com.enonic.xp.portal.impl.mapper.PortalResponseMapper)3 ScriptExports (com.enonic.xp.script.ScriptExports)3 PropertyTree (com.enonic.xp.data.PropertyTree)2 ResourceProblemException (com.enonic.xp.resource.ResourceProblemException)2 WebException (com.enonic.xp.web.WebException)2 ByteSource (com.google.common.io.ByteSource)2 Map (java.util.Map)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)1 Content (com.enonic.xp.content.Content)1 ContentId (com.enonic.xp.content.ContentId)1 ContentQuery (com.enonic.xp.content.ContentQuery)1 Contents (com.enonic.xp.content.Contents)1 FindContentIdsByQueryResult (com.enonic.xp.content.FindContentIdsByQueryResult)1 GetContentByIdsParams (com.enonic.xp.content.GetContentByIdsParams)1