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());
}
}
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());
}
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);
}
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"));
}
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);
}
Aggregations