Search in sources :

Example 31 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayCreatedBooleanArray.

@Test
public void shouldToJsonArrayCreatedBooleanArray() throws Exception {
    JsonArray expected = jsonFactory.createArray();
    expected.set(0, false);
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList(false), jsonFactory, dtoFactory);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) Test(org.junit.Test)

Example 32 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonForCreatedListDtoParams.

@Test
public void shouldToJsonForCreatedListDtoParams() throws Exception {
    List<Dto> list = singletonList(dto);
    JsonArray expected = jsonFactory.createArray();
    JsonValue jsonValue = jsonFactory.parse(dto.toString());
    expected.set(0, jsonValue);
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonFactory, dtoFactory);
    JsonValue actual = jsonRpcParams.toJsonValue();
    assertTrue(expected.jsEquals(actual));
}
Also used : JsonArray(elemental.json.JsonArray) JsonValue(elemental.json.JsonValue) Test(org.junit.Test)

Example 33 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToStringForParsedListStringParams.

@Test
public void shouldToStringForParsedListStringParams() throws Exception {
    String value = "value";
    JsonArray expected = jsonFactory.createArray();
    expected.set(0, value);
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[\"" + value + "\"]", jsonFactory, dtoFactory);
    String actual = jsonRpcParams.toString();
    assertEquals(expected.toJson(), actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonString(elemental.json.JsonString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 34 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToStringCreatedListDoubleParams.

@Test
public void shouldToStringCreatedListDoubleParams() throws Exception {
    double value = 0D;
    List<Double> list = singletonList(value);
    JsonArray jsonArray = jsonFactory.createArray();
    jsonArray.set(0, value);
    String expected = jsonArray.toJson();
    JsonRpcParams jsonRpcParams = new JsonRpcParams(list, jsonFactory, dtoFactory);
    String actual = jsonRpcParams.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(elemental.json.JsonArray) JsonString(elemental.json.JsonString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 35 with JsonArray

use of elemental.json.JsonArray in project che by eclipse.

the class ProjectExplorerStateComponent method getState.

@Override
public JsonObject getState() {
    final List<Path> paths = new ArrayList<>();
    outer: for (Node node : projectExplorer.getTree().getNodeStorage().getAll()) {
        if (projectExplorer.getTree().isExpanded(node) && node instanceof ResourceNode) {
            final List<Node> childrenToStore = projectExplorer.getTree().getNodeStorage().getChildren(node);
            for (Node children : childrenToStore) {
                if (children instanceof ResourceNode) {
                    paths.add(((ResourceNode) children).getData().getLocation());
                    continue outer;
                }
            }
        }
    }
    JsonObject state = Json.createObject();
    JsonArray array = Json.createArray();
    state.put(PATH_PARAM_ID, array);
    int i = 0;
    for (Path path : paths) {
        array.set(i++, path.toString());
    }
    state.put(SHOW_HIDDEN_FILES, projectExplorer.isShowHiddenFiles());
    return state;
}
Also used : Path(org.eclipse.che.ide.resource.Path) JsonArray(elemental.json.JsonArray) Node(org.eclipse.che.ide.api.data.tree.Node) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode) ArrayList(java.util.ArrayList) JsonObject(elemental.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) ResourceNode(org.eclipse.che.ide.resources.tree.ResourceNode)

Aggregations

JsonArray (elemental.json.JsonArray)69 Test (org.junit.Test)62 JsonValue (elemental.json.JsonValue)23 JsonString (elemental.json.JsonString)19 JsonObject (elemental.json.JsonObject)14 Matchers.anyString (org.mockito.Matchers.anyString)10 JsonNumber (elemental.json.JsonNumber)5 PartPresenter (org.eclipse.che.ide.api.parts.PartPresenter)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Node (org.eclipse.che.ide.api.data.tree.Node)2 ResourceNode (org.eclipse.che.ide.resources.tree.ResourceNode)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Promise (org.eclipse.che.api.promises.client.Promise)1 EditorPartPresenter (org.eclipse.che.ide.api.editor.EditorPartPresenter)1 TextEditor (org.eclipse.che.ide.api.editor.texteditor.TextEditor)1 Path (org.eclipse.che.ide.resource.Path)1 MessageLoader (org.eclipse.che.ide.ui.loaders.request.MessageLoader)1 Ignore (org.junit.Ignore)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1